Skip to content

Commit

Permalink
Set up pre-commit git hook using husky
Browse files Browse the repository at this point in the history
Install the hooks in the prepare script through a node call rather than just `husky install`
as the package won't be installed on Heroku, which would make the `prepare` script fail.

https://typicode.github.io/husky/#/?id=with-a-custom-script
  • Loading branch information
romaricpascal committed Nov 23, 2022
1 parent 9dc3b6a commit d9bd3e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no-install lint-staged
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"lint:js": "npm run lint:js:cli -- \"**/*.{cjs,js,mjs}\"",
"lint:js:cli": "eslint --cache --cache-location .cache/eslint --cache-strategy content --color --ignore-path .gitignore --max-warnings 0",
"lint:scss": "npm run lint:scss:cli -- \"{app,src}/**/*.scss\"",
"lint:scss:cli": "stylelint --cache --cache-location .cache/stylelint --cache-strategy content --color --ignore-path .gitignore --max-warnings 0"
"lint:scss:cli": "stylelint --cache --cache-location .cache/stylelint --cache-strategy content --color --ignore-path .gitignore --max-warnings 0",
"prepare": "node -e \"try { require('husky').install() } catch (e) {if (e.code !== 'MODULE_NOT_FOUND') throw e}\""
},
"dependencies": {
"@babel/core": "^7.20.2",
Expand Down Expand Up @@ -87,6 +88,7 @@
"eslint-plugin-n": "^15.5.1",
"eslint-plugin-promise": "^6.1.1",
"html-validate": "7.10.0",
"husky": "^8.0.2",
"jest": "^29.3.1",
"jest-axe": "^7.0.0",
"jest-dev-server": "^6.1.1",
Expand Down

0 comments on commit d9bd3e9

Please sign in to comment.