Skip to content

Commit

Permalink
Introduce husky pre-commit hook with lint-staged
Browse files Browse the repository at this point in the history
  • Loading branch information
dongzoolee committed Sep 8, 2023
1 parent 37de121 commit 744a2c0
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 26 deletions.
36 changes: 36 additions & 0 deletions .husky/_/husky.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env sh
if [ -z "$husky_skip_init" ]; then
debug () {
if [ "$HUSKY_DEBUG" = "1" ]; then
echo "husky (debug) - $1"
fi
}

readonly hook_name="$(basename -- "$0")"
debug "starting $hook_name..."

if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi

if [ -f ~/.huskyrc ]; then
debug "sourcing ~/.huskyrc"
. ~/.huskyrc
fi

readonly husky_skip_init=1
export husky_skip_init
sh -e "$0" "$@"
exitCode="$?"

if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
fi

if [ $exitCode = 127 ]; then
echo "husky - command not found in PATH=$PATH"
fi

exit $exitCode
fi
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
3 changes: 3 additions & 0 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
"*.{js,jsx,ts,tsx}": ["yarn pretty:fix", "yarn eslint:fix"],
};
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"pretty:check": "prettier -c .",
"pretty:fix": "prettier -w .",
"eslint:check": "eslint './**/*.{js,jsx,ts,tsx}'",
"eslint:fix": "eslint --fix './**/*.{js,jsx,ts,tsx}'"
"eslint:fix": "eslint --fix './**/*.{js,jsx,ts,tsx}'",
"prepare": "husky install"
},
"dependencies": {
"babel-plugin-styled-components": "^1.12.0",
Expand All @@ -34,10 +35,17 @@
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react": "^7.33.2",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"prettier": "^3.0.3",
"redux-devtools-extension": "^2.13.9"
},
"engines": {
"node": ">=16 <17"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
Loading

0 comments on commit 744a2c0

Please sign in to comment.