0.0.1-alpha.2 โ€ข Published 5 years ago

prettier-files v0.0.1-alpha.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

prettier-check

Build Status

cli for quick checking and formatting prettier ๐Ÿƒ๐Ÿผ ๐Ÿƒ๐Ÿผ ๐Ÿƒ๐Ÿผ

require

Please install prettier >= version 1.15.3

"peerDependencies": {
   "prettier": ">=1.15.3"
},

install

npm install --save-dev prettier prettier-files

Usage

(1) adds prettierFiles attribute in package.json

package.json adds prettierFiles attribute

...
 "prettierFiles":[
    "src/**/*.js*",
    "src/**/*.ts*",
    "src/**/*.less",
    "config/**/*.js*",
    "scripts/**/*.js"
  ],
...

(2) api

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

check

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']

wrtie

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']

(3) Matching rules

based on glob. Refer to matching rules.๏ผš

Glob Primer

pre-commit hook

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"
    }

License

MIT license

MIT