Skip to content

Commit

Permalink
build: configure lint-staged and pre-commit hook
Browse files Browse the repository at this point in the history
Adds a Husky pre-commit hook that runs lint-staged, which has been configured to run 'lint' and
'format' on the file types specified in .lintstagedrc. This helps the developer by only running the
lint and format scripts on files they have changed and staged, and keeps unlinted and unformatted
commits out of the code base.

Resolves: #26
  • Loading branch information
M-Scott-Lassiter committed Apr 26, 2022
1 parent c96bb37 commit 00b362a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
exit 1
3 changes: 2 additions & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"*.(js|ts)": "eslint --fix"
"*.{js,ts}": ["npm run lint"],
"**/*.{js,jsx,ts,tsx,json,html,css,scss,md}": ["npm run format"]
}
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.1.4",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.0",
"husky": "^7.0.4",
"jest": "^27.5.1",
"lint-staged": "^12.4.1",
"markdown-toc": "^1.2.0",
Expand All @@ -68,7 +68,7 @@
},
"husky": {
"hooks": {
"pre-commit": "npm run test && exit 1"
"pre-commit": "npx lint-staged"
}
}
}

0 comments on commit 00b362a

Please sign in to comment.