How to configure Prettier to work with Apex Salesforce code in VSCode
Yes that is possible
Prerequisite:- VSCode is fully configured to work with Salesforce
- Select the existing Salesforce Project. At the root level run the below command in the Terminal
npm init //this will create package.json file to track npm dependencies
Run the below code to install the prettier apex npm plugin, as a local dependency to the project.
- Note:- Same could have been done globally.
npm install --save-dev --save-exact prettier prettier-plugin-apex
- Install the prettier extension, it will create a .prettierrc file under the root of SF project
- Open apex file (.cls), Cmd+Shift+P > Format document.