Apex Space Remover
A VS Code extension that replicates the Salesforce "Apex Space Removal" script (Spacecheck.js) as an editor feature.
Every time you save an Apex file — a .cls class or a .trigger trigger, the extension automatically:
- Converts leading indentation spaces → tabs (using the configured tab size), and
- Removes trailing spaces at the end of each line.
Test classes are never touched — any .cls file whose content contains the @isTest annotation is skipped automatically, exactly like the Salesforce script.
Package it once as a .vsix and share it — teammates install it locally in a couple of clicks.
Features
| What |
Where / How |
| Clean on save |
Enabled by default. Save any .cls/.trigger file that has changes → spaces cleaned instantly (test classes skipped). |
| Notification with the 3 numbers |
On every clean you get a notification: Spaces replaced: X, Tabs inserted: Y, Apex chars saved: Z — the exact numbers the Salesforce script reports. |
| Execution Summary Table |
On every clean, the terminal-style table File \| Status \| SpacesReplaced \| TabsInserted \| ApexCharSaving is printed in the Apex Space Remover output panel (opens automatically), like console.table in the script. |
| One-click clean (status bar) |
When an Apex file is open, a ✨ Clean Spaces button appears in the bottom status bar. Click it to clean and save the file — this works even if the file has no unsaved changes. |
| Clean current file on demand |
Command Palette → Apex Space Remover: Clean Current File |
| Diagnose a single file |
Command Palette → Apex Space Remover: Check Current File (diagnose) — shows exactly what it sees (space counts, test-class status, whether a save would change it) |
| Dry-run over the whole workspace |
Command Palette → Apex Space Remover: Verify All Apex Files (dry run) |
| Batch-fix the whole workspace |
Command Palette → Apex Space Remover: Fix All Apex Files in Workspace |
| Safety net |
After every save the file is re-read from disk; if spaces remain, it is rewritten automatically (protects against anything interfering with the save) |
All of the above applies to both .cls classes and .trigger triggers.
Settings
Open Settings → Extensions → Apex Space Remover (or add to settings.json):
| Setting |
Default |
Description |
apexSpaceCleaner.enabledOnSave |
true |
Clean .cls/.trigger files automatically when saved. |
apexSpaceCleaner.tabSize |
4 |
Number of spaces treated as one tab level. |
apexSpaceCleaner.skipTestClasses |
true |
Never modify files containing @isTest. |
apexSpaceCleaner.convertLeadingSpacesToTabs |
true |
Convert leading spaces to tabs. |
apexSpaceCleaner.removeTrailingSpaces |
true |
Remove end-of-line spaces. |
apexSpaceCleaner.showSaveNotification |
true |
Show a notification when a save actually cleans a file. |
apexSpaceCleaner.logEverySave |
true |
Log every .cls save (cleaned / no-change / skipped) to the output channel. |
apexSpaceCleaner.feedbackWhenNoChange |
true |
Even when a file is already clean, still show the table + notification (No changes needed, 0/0/0) on the Clean Spaces button, Clean Current File command, and save. Set false to only show feedback when a file is actually cleaned. |
Example:
{
"apexSpaceCleaner.enabledOnSave": true,
"apexSpaceCleaner.tabSize": 4,
"apexSpaceCleaner.skipTestClasses": true
}
Install from the shared .vsix
- Receive the
apex-space-remover-1.0.0.vsix file (shared by whoever built it).
- Open VS Code.
- Open the Extensions view (
Ctrl+Shift+X / Cmd+Shift+X).
- Click the "..." menu at the top right → Install from VSIX....
- Pick the
.vsix file → the extension is installed.
- Open/save any
.cls file → spaces are cleaned automatically (test classes skipped).
Important VS Code behaviour: like format-on-save, the automatic cleaning only runs when a file is actually saved with changes. If you open a .cls/.trigger file and press Cmd/Ctrl+S without editing anything, VS Code does not perform a real save, so nothing happens. To clean a file without editing it, use the ✨ Clean Spaces status-bar button or Apex Space Remover: Clean Current File.
The extension activates on startup / when an Apex workspace opens. Open the Apex Space Remover output channel (View → Output → Apex Space Remover) to see the log + Execution Summary Tables, or run Apex Space Remover: Check Current File (diagnose) to inspect the active file.
Building the .vsix yourself
From this project folder:
npm install
npm run compile
npm run package # or: npx @vscode/vsce package
This produces apex-space-remover-1.0.0.vsix in the project root — that file is what you share.
Note on the publisher: before the extension can be published to the public VS Code Marketplace it needs a unique, registered publisher id in package.json. For local .vsix installation the publisher value does not matter — teammates can install the file without it being published.
Running locally during development (F5)
- Open this folder in VS Code (
code apex-space-cleaner-extension).
- Press
F5 → an Extension Development Host window opens.
- Open any Salesforce project with
.cls files and test the save behaviour.
Changelog
See the CHANGELOG.md file shipped inside this project folder.
License
MIT