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

A mix of both solutions from:
https://typicode.github.io/husky/#/?id=with-a-custom-script
  • Loading branch information
romaricpascal committed Nov 23, 2022
1 parent 9dc3b6a commit e36a704
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 \"'DYNO' in process.env || 'CI' in process.env || require('husky').install()\""
},
"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 e36a704

Please sign in to comment.