Prettier
An opinionated code formatter enforces a consistent code style across your entire codebase
Target
提交代碼時…
自動格式化代碼
使用 ESLint 檢查代碼,並自動修復錯誤
在修復不了的時候,回報錯誤(此次 commit 不會提交)
Basic Configuration
.prettierrc
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "always",
"proseWrap": "preserve"
}
Install
package.json
Integrating with ESLint Linters
If you use ESLint, install eslint-config-prettier to make ESLint and Prettier play nice with each other. It turns off all ESLint rules that are unnecessary or might conflict with Prettier.
.eslintrc
Git Pre-commit Hooks
Run Prettier as a pre-commit hook to makes sure all your commits are formatted.
package.json
Additional
CI setup
Run prettier --check . in CI to make sure that your project stays formatted.
Reference
Last updated
Was this helpful?