How to install Prettier
npm install prettier --save-dev
How to configure Prettier
touch .prettierrc.json
Add some default configuration:
{
"trailingComma": "es5",
"tabWidth": 4,
"printWidth": 120,
"semi": true,
"singleQuote": false,
"useTabs": false,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"bracketSpacing": false,
"bracketSameLine": true,
"arrowParens": "avoid",
"requirePragma": false,
"insertPragma": false,
"proseWrap": "preserve",
"endOfLine": "lf"
}
Note: jsxBracketSameLine is deprectaed since version 2.4.1. You must use bracketSameLine instead
How to ignore folders in Prettier
touch .prettierignore
Add some folders to be ignored. Tipically it will be pretty similar to your .gitignore file
# Ignore artifacts:
node_modules
dist
build
coverage
.nyc_output
How to start detecting issues with Prettier
prettier . -c
Pro tip: instead of running by hand, you can integrate it with you favorite IDE
Photo by Greg Rosenke on Unsplash