1

Hey does anyone here know how to make VSCode auto fix missing semicolons instead of just show where it is missing?

I Started setting up Prettier and it will format apex code but not replace double quotes with single quotes nor insert missing semicolons.

Can someone point me in the right direction?

I tried:

Prettier, Uncrustify and none of them worked for me.

if (o.Owner.Username == "[email protected]"){
System.debug("why am I not bracced by singel quotes yet?")
}

this should be formatted to:

if (o.Owner.Username == '[email protected]'){
    System.debug('why am I not bracced by singel quotes yet?');
}

Id be greatful for any hint :)

2 Answers 2

2

Code formatters only runs successfully when there are no syntax errors.

Double quotes and missing semi colons is allowed in JavaScript, hence prettier or any code formatter can be configured to appropriately format those with rules. Not that even in JavaScript if you have a missing brace, the formatter won't work.

In Apex, double quotes or missing semi colons is not allowed, this may not be possible by prettier or any formatter yet.

After formatting, also look at the error on output of prettier or crusify plugin to see exact error.

0

As @Raul mentioned, this is not possible with prettier. what you might want to do auto deploy, which can set this in the workspace settings... To push files each time you save them, use workspace setting. This will help you with errors and run prettier afterwards.

 salesforcedx-vscode-core.push-or-deploy-on-save.enabled:true

Or use sfdx force:source:push to compile everything at the end

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .