cli for quick checking and formatting prettier ππΌ ππΌ ππΌ
Please install prettier
>= version 1.15.3
"peerDependencies": {
"prettier": ">=1.15.3"
},
npm install --save-dev prettier prettier-files
package.json
adds prettierFiles attribute
...
"prettierFiles":[
"src/**/*.js*",
"src/**/*.ts*",
"src/**/*.less",
"config/**/*.js*",
"scripts/**/*.js"
],
...
Usage: prettier-files [options] [command]
Options:
-v, --version output the version number
-h, --help output usage information
Commands:
check|-c prettier check
write|-w prettier write
prettier will be get prettierFiles attribute in package.json
by default
prettier-files check
you can use an array of strings through the third parameter for easy use in combination with pre-commit Hook
prettierFiles check ['path1', 'path2']
prettier will be get prettierFiles attribute in package.json
by default
prettier-files write
you can use an array of strings through the third parameter for easy use with pre-commit Hook
prettierFiles write ['path1', 'path2']
based on glob
. Refer to matching rules.οΌ
Usually prettier is used with pre-commit Hook, The following examples use with husky and lint-stage
(1) install huskyγlint-staged
npm install husky lint-staged --save --dev
(2) configure package.json
"lint-staged": "lint-staged"
...
"lint-staged": {
"**/*.{js,ts,tsx,json,jsx,less}": [
"prettier-files check",
"git add"
],
"**/*.{js,jsx}": "npm run lint-staged:js"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint-staged"
}
MIT license
MIT