Skip to content

Commit 17eaad0

Browse files
rogerluanhallettj
andauthored
docs: update Husky documentation to match husky v7.0.0 (hallettj#62)
Co-authored-by: Jesse Hallett <[email protected]>
1 parent 8e98ce7 commit 17eaad0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,26 @@ notation) so that you can see them.
116116
Follow these steps to automatically format all Javascript files on commit in
117117
a project that uses npm.
118118

119-
Install git-format-staged, husky, and a formatter (I use prettier-standard):
119+
Install git-format-staged, husky, and a formatter (I use `prettier-standard`):
120120

121121
$ npm install --save-dev git-format-staged husky prettier-standard
122122

123-
Add a `"precommit"` script in `package.json`:
123+
Add a `prepare` script to install husky when running `npm install`:
124124

125-
"scripts": {
126-
"precommit": "git-format-staged -f prettier-standard '*.js'"
127-
}
125+
$ npm set-script prepare "husky install"
126+
$ npm run prepare
127+
128+
Add the pre-commit hook:
129+
130+
$ npx husky add .husky/pre-commit "git-format-staged --formatter 'prettier-standard --stdin-filepath \"{}\"' '*.js'"
131+
$ git add .husky/pre-commit
128132

129133
Once again note that the `'*.js'` pattern is quoted! If the formatter command
130134
included arguments it would also need to be quoted.
131135

132136
That's it! Whenever a file is changed as a result of formatting on commit you
133137
will see a message in the output from `git commit`.
134138

135-
136139
## Comparisons to similar utilities
137140

138141
There are other tools that will format or lint staged files. What distinguishes

0 commit comments

Comments
 (0)