This is a modified version of the Prettier Apex plugin to better suit our current coding conventions.
See the original documentation here.
These are the changes from the original project. Each one is configurable with an option in .prettierrc
.
Option: apexBeginClassWithEmptyLine
(boolean)
public class Potato {
private int size;
...
}
public class Potato {
private int size;
...
}
Option: apexUseContinuationIndent
(boolean)
doSomething(paramA,
paramB,
paramC);
doSomething(paramA,
paramB,
paramC);
Option: apexSkipNewlineBeforeCondition
(boolean)
if(
conditionA
&& conditionB
&& conditionC) {
...
}
if(conditionA
&& conditionB
&& conditionC) {
...
}
Option: apexSkipNewlineBeforeClosingParenthesis
(boolean)
private void doSomething(
Potato p1,
Potato p2,
Potato p3
) {
...
}
private void doSomething(
Potato p1,
Potato p2,
Potato p3) {
...
}
Note that the "Before" style is still permitted for statements without a body, e.g. return / assignment statements.
- Newline after
/*
in block comments - Support continuation lines inside a long expression
- if-statements
- assignment statements
- Line breaks between methods
- Line breaks BEFORE operators
-
From the
prettier-plugin-apex
repo:npm link
-
From the repo to be formatted:
npm link prettier-plugin-apex
-
Enable "Format on Save".
You can also format manually using: Ctrl + Shift + P => Format Document
After making a change to the Prettier plugin, it must be reloaded using:
Ctrl + Shift + P => Reload Window
Note that it can take some time for Prettier to initialise.
To run linting and unit tests:
npm test
To run just the unit tests:
npx jest
- Dev Notes
- Developing Prettier Plugins
- Prettier Commands
- AstPath Class (
path
parameter supplied to print functions)