From the Marketplace PlugIns, just install Node and the Prettier PlugIn.
In your terminal or shell, type:
npm install --save-dev --save-exact prettier
npm install --global prettier
- In the Settings/Preferences dialog Ctrl+Alt+S
- Choose the Node.js interpreter to use.
- From the Prettier package list, select the
prettierinstallation to use.
- IntelliJ IDEA will locate the
prettierpackage itself and the field is filled in automatically.
- To run Prettier automatically against specific files every time such file is changed and saved, select the Run on save for files checkbox.
- Provide a pattern that defines the set of files to be reformatted every timeon save.
Prettier will now also format your files on save.
In you package.json you can specify prettier:
In the project where Prettier is enabled, open package.json and click Yes in the pane at the top of the tab. Sometimes it is shown in the context menu, right click and bottom of the options in the list.
Example of a .prettierrc.json:
"files": ["*.html", "legacy/**/*.js", "*.tsx"],
I select the lines of Code and just press CMD+ALT+SHIFT+P
The Code will be reformatted instantly.
Link to Prettier: https://prettier.io/docs/en/configuration.html