- code formatter
- few options, easy to set up
Installation
Install
prettier
locally or use editor extension.npm install --save-dev prettier
If
eslint
is used before formatting with Prettier, install plugin to turn off conflicting rules.npm install --save-dev eslint-config-prettier
Create a
.prettierrc.json
file locally.
Configuration
- use a configuration file
.prettierrc.json
- if
eslint
is used before formatting with Prettier, add"prettier"
in"extends"
in.eslintrc.json
, also"prettier/@typescript-eslint"
if typescript is installed
Example
prettierrc.json
{
"printWidth": 100,
"tabWidth": 4,
"endOfLine": "lf",
"useTabs": false,
"trailingComma": "none",
"semi": true,
"singleQuote": false,
"bracketSpacing": true,
"arrowParens": "avoid",
"proseWrap": "never",
"overrides": [
{
"files": ["*.json", "*.md"],
"options": {
"tabWidth": 2
}
}
]
}
prettierignore
# Markdown files
*.md