Skip to content

Prettier

See the official documentation.

Terminal window
npm i prettier

These are basic prettier settings (.prettierrc.json).

.prettierrc.json
{
"$schema": "https://json.schemastore.org/prettierrc.json",
"arrowParens": "avoid",
"printWidth": 80,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
}

Create an ignore file (.prettierignore):

build
dist
coverage
analysis

and here is a script to run prettier on a javascript project:

Terminal window
# File: package.json
"format": "prettier \"./**/*.{html,css,js,jsx,ts,tsx,md,mdx,json}\" --write --cache --log-level=warn",

More CLI docs

Integration with a linter