Please, read our General Formatting Guidelines for a complete overview of our formatting recommendations and best practices.
Prettier usage is built-in inside Liferay DXP thanks to the liferay-npm-scripts
package that encapsulates all the necessary logic, dependencies and configuration for it to work.
Only JSP, JavaScript and SCSS files are formatted using Prettier
Note that because we apply some small Liferay-specific overrides to Prettier's behavior when formatting in liferay-portal, please see the editor integrations information for details on how to set up your editor or IDE to apply these overrides automatically.
Every module inside Liferay DXP with JavaScript or SCSS files should contain a package.json
file with at least the following npm scripts:
{
"scripts": {
"checkFormat": "liferay-npm-scripts check",
"format": "liferay-npm-scripts fix"
}
}
Among other things, the format
script will run Prettier with the default configuration and save the changes to your files. It can be invoked either directly as yarn format
or through the Gradle Wrapper as gradlew npmRunFormat
.
The checkFormat
script will run Prettier (and some other checks described in "Linting") without saving your files and exit with an error if there are changes. This task is meant to run on CI to prevent files from being committed without the proper formatting.
- Linting: information on checking and fixing the non-presentational aspects of our source code.