DEV Community

Mark
Mark

Posted on • Updated on

Install Husky + Commitlint + Lint-staged

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
Enter fullscreen mode Exit fullscreen mode

Install Lint-staged

npm i -D lint-staged
Enter fullscreen mode Exit fullscreen mode

Change package.json

"lint-staged": {
    "*.{ts,tsx,js,jsx}": [
      "eslint --fix",
      "prettier --write"
    ]
  },
Enter fullscreen mode Exit fullscreen mode

pre-commit

#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
Enter fullscreen mode Exit fullscreen mode

Install Commitlint

npm i -D @commitlint/cli @commitlint/config-conventional
Enter fullscreen mode Exit fullscreen mode

Create commitlint.config.js

module.exports = {
  extends: ['@commitlint/config-conventional']
};
Enter fullscreen mode Exit fullscreen mode

commit-msg

npx --no -- commitlint --edit ${1}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)