-
Notifications
You must be signed in to change notification settings - Fork 9
Setup Uncrustify Code Formatting for Apex and Javascript in Visual Studio Code
-
Install Chocolatey Package Manager or NPM
-
Install Uncrustify by running windows powershell as an admin and entering the following command if using chocolatey package manager :
choco install uncrustify
or if you use npm run this commandnpm i uncrustify
-
Install the Uncrustify Visual Studio Code plugin
-
In Visual Studio Code press Ctrl+Shift+P to bring up the command palette and enter the following command: Preferences: Open Settings (JSON). This should open a settings.json file
-
Inside the settings.json file add the following lines:
"uncrustify.langOverrides": { "apex": "JAVA", "apex-anon": "JAVA" }, "[apex]": { "editor.defaultFormatter": "LaurentTreguier.uncrustify" }, "[javascript]": { "editor.defaultFormatter": "LaurentTreguier.uncrustify" }
-
Press Ctrl+S to save the settings file
-
Press Ctrl+Shift+P to bring up the control palette and enter the following command: Uncrustify: Create Default Config. After running that command you should see an uncrustify.cfg file in your project (or you can use the config file I like here: Matt's Uncrustify Config)
-
Open the uncrustify.cfg file and update all your settings in it (This is just a nice UI with a ton of different options, so nothing complicated here). Make sure to hit the save button in the top right corner when you are done!
-
Once you finished open a file you would like to have code formatting done to and press Alt+Shift+F
-
Enjoy your auto-formatted code!