Skip to content

Instantly share code, notes, and snippets.

@ShepetaAndrey
Created April 27, 2022 19:05
Show Gist options
  • Save ShepetaAndrey/bd0a58aa6a8560a9d85cd50d1da50363 to your computer and use it in GitHub Desktop.
Save ShepetaAndrey/bd0a58aa6a8560a9d85cd50d1da50363 to your computer and use it in GitHub Desktop.
Husky, lint-staged, commitlint, Vue JS

Husky + commitlint + lint-staged

husky

husky docs

This command will add husky "prepare": "husky install" npm lifecycle hook script that will be executed automatically during npm install command run.

npx husky-init

extend git hooks:

  • code lint/format
npx husky add .husky/pre-commit "npx lint-staged --allow-empty $1"
  • commit message validation
npx husky add .husky/commit-msg "npx commitlint --edit $1"

commitlint

commitlint docs

Requires commit messages to respect prescribed conventional rules.

Files that extends git hooks with custom logic will be stored in .husky folder.

npm install -D @commitlint/config-conventional @commitlint/cli

Add commitlint.config.js

module.exports = {
  extends: ["@commitlint/config-conventional"],
};

lint-staged

lint-staged docs

npm install -D lint-staged
  • eslint
npm install -D eslint
/* package.json */
{
  "lint-staged": {
    "*.{vue,js}": "eslint --fix"
  }
}
  • eslint + prettier
npm install -D eslint prettier
/* package.json */
{
  "lint-staged": {
    "*.{vue,js}": [
      "eslint --fix",
      "prettier --write"
    ]
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment