husky

Used to submit messages to Lint, run tests, lint code, etc. Husky supports all Git hooks.

yarn add husky --dev
yarn add pinst --dev # ONLY if your package is not private
yarn husky install
husky add .husky/pre-commit "npm test" // v6
Copy the code

Husky official documentation address typicode. Making. IO # / husky / /? Id…

lint-staged

Prior to code submission, code rule checking ensures that all code entering git repositories complies with code rules. However, lint can be slow to run on an entire project, and Lint-staged versions can be fast because they only detect files in staging.

yarn add lint-staged --dev
husky add .husky/pre-commit "yarn lint-staged"
Copy the code

package.json

"husky": { // v4
    "hooks": {
      "pre-commit": "lint-staged"}},"lint-staged": {
    "*.{js,ts,vue}": "eslint --fix"."*.{scss,css}": "prettier --write"
 }
Copy the code

Git commit specification

<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
Copy the code

type

Only the following seven identifiers are allowed to describe the commit category.

  • Feat: New Feature
  • Fix: Fixes bugs
  • -Jenny: There are some docs.
  • Style: format (changes that do not affect code execution)
  • Refactor: refactoring (i.e. code changes that are not new features or bug fixes)
  • Test: Adds a test
  • Chore: Changes to the build process or helper

scope

Scope is used to specify the scope of the commit impact, such as the data layer, control layer, view layer, and so on, depending on the project.

subject

Subject is a short description of the commit purpose, no more than 50 characters long.

body

The Body section is a detailed description of the commit, broken into multiple lines.

footer

The Footer section is only used in two cases:

  • Incompatible variation
  • Shut downissue
  • revertIf the current COMMIT is used to undo a previous COMMIT, it must start with Revert:, followed by the headers that were revoked.

checkcommitCompliance with the rules

The installation

yarn add @commitlint/cli @commitlint/config-conventional --dev
Copy the code

configuration

commitlint.config.js

module.exports = {
  extends: ["@commitlint/config-conventional"].rules: {
    "type-enum": [
      2."always"["upd"."feat"."fix"."refactor"."docs"."chore"."style"."revert"]],"type-case": [0]."type-empty": [0]."scope-empty": [0]."scope-case": [0]."subject-full-stop": [0."never"]."subject-case": [0."never"]."header-max-length": [0."always".72],}};Copy the code
# .husky/commit-msg (v7)
#.
npx --no-install commitlint --edit $1
# or
yarn commitlint --edit $1
Copy the code

Automatically generated that meets the rulecommitinformation

The installation

yarn add commitizen cz-conventional-changelog --dev
Copy the code

configuration

package.json

"config": {
   "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"}}Copy the code

reference

Juejin. Cn/post / 688607…

www.jianshu.com/p/201bd81e7…