git-format-staged
Advanced tools
Comparing version 2.1.3 to 3.0.0
{ | ||
"name": "git-format-staged", | ||
"version": "2.1.3", | ||
"version": "3.0.0", | ||
"description": "Git command to transform staged files according to a command that accepts file content on stdin and produces output on stdout.", | ||
@@ -31,5 +31,2 @@ "scripts": { | ||
], | ||
"release": { | ||
"branches": "master" | ||
}, | ||
"devDependencies": { | ||
@@ -46,3 +43,3 @@ "@commitlint/cli": "^8.3.5", | ||
"prettier-standard": "^9.1.1", | ||
"semantic-release": "^17.2.3", | ||
"semantic-release": "^19.0.2", | ||
"strip-indent": "^3.0.0", | ||
@@ -49,0 +46,0 @@ "tmp": "0.2.0", |
@@ -6,6 +6,6 @@ # git-format-staged | ||
Consider a project where you want all code formatted consistently. So you use | ||
a formatting command. (For example I use [prettier-standard][] in my | ||
Javascript projects.) You want to make sure that everyone working on the | ||
project runs the formatter, so you use a tool like [husky][] to install a git | ||
pre-commit hook. The naive way to write that hook would be to: | ||
a formatting command. (For example I use [prettier][] in my Javascript and | ||
Typescript projects.) You want to make sure that everyone working on the project | ||
runs the formatter, so you use a tool like [husky][] to install a git pre-commit | ||
hook. The naive way to write that hook would be to: | ||
@@ -34,6 +34,5 @@ - get a list of staged files | ||
[prettier-standard]: https://www.npmjs.com/package/prettier-standard | ||
[prettier]: https://prettier.io/ | ||
[husky]: https://www.npmjs.com/package/husky | ||
## How to install | ||
@@ -56,3 +55,2 @@ | ||
## How to use | ||
@@ -79,2 +77,9 @@ | ||
Note that the syntax of the `fnmatch` glob match is a is a bit different from | ||
normal shell globbing. So if you need to match multiple patterns, you should | ||
pass multiple arguments with different patterns, and they will be grouped. | ||
So instead of e.g. `'src/**/*.{js,jsx,ts}'`, you would use: | ||
$ git-format-staged --formatter 'prettier --stdin-filepath "{}"' 'src/*.js' 'src/*.jsx' 'src/*.ts' | ||
Files can be excluded by prefixing a pattern with `!`. For example: | ||
@@ -123,19 +128,22 @@ | ||
Install git-format-staged, husky, and a formatter (I use prettier-standard): | ||
Install git-format-staged, husky, and a formatter (I use `prettier`): | ||
$ npm install --save-dev git-format-staged husky prettier-standard | ||
$ npm install --save-dev git-format-staged husky prettier | ||
Add a `"precommit"` script in `package.json`: | ||
Add a `prepare` script to install husky when running `npm install`: | ||
"scripts": { | ||
"precommit": "git-format-staged -f prettier-standard '*.js'" | ||
} | ||
$ npm set-script prepare "husky install" | ||
$ npm run prepare | ||
Once again note that the `'*.js'` pattern is quoted! If the formatter command | ||
included arguments it would also need to be quoted. | ||
Add the pre-commit hook: | ||
$ npx husky add .husky/pre-commit "git-format-staged --formatter 'prettier --stdin-filepath \"{}\"' '*.js' '*.ts'" | ||
$ git add .husky/pre-commit | ||
Once again note that the formatter command and the `'*.js'` and `'*.ts'` | ||
patterns are quoted! | ||
That's it! Whenever a file is changed as a result of formatting on commit you | ||
will see a message in the output from `git commit`. | ||
## Comparisons to similar utilities | ||
@@ -142,0 +150,0 @@ |
Sorry, the diff of this file is not supported yet
22800
203