This article is base on
https://dev.to/markliu2013/setup-eslint-and-prettier-in-react-3h99
We want to enforcing coding conventions before commit to git repository.
Run eslint and prettier before commit code
Install Husky
npm i -D husky
npx husky init
Install Lint-staged
npm i -D lint-staged
Change package.json
"lint-staged": {
"*.{ts,tsx,js,jsx}": [
"eslint --fix",
"prettier --write"
]
},
pre-commit
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
Install Commitlint
npm i -D @commitlint/cli @commitlint/config-conventional
Create commitlint.config.js
module.exports = {
extends: ['@commitlint/config-conventional']
};
commit-msg
npx --no -- commitlint --edit ${1}
Top comments (0)