GitHooks uses package.json configuration:

{" name ":" eslint ", "version" : "0.1.0 from", "private" : true, "scripts" : {" serve ":" vue - cli - service serve ", "build" : "Vue-cli-service build", "lint": "vue-cli-service lint", "dependencies": {"core-js": "^3.6.4", "vue": "^ 2.6.11", "vue - the router" : "^ 3.1.5"}, "devDependencies" : {" @ vue/cli - plugin - Babel ":" ^ 4.2.0 ", "@ vue/cli - plugin - eslint" : "^ 4.2.0 @", "vue/cli - plugin - the router" : "^ 4.2.0", "@ vue/cli - service" : "^ 4.2.0", "@ vue/eslint - config - standard" : "^ 5.1.0", "Babel - eslint" : "^ 10.0.3", "eslint" : "^ 6.7.2", "eslint - plugin - import" : "^ 2.20.1", "eslint - plugin - node" : "^ 11.0.0 eslint - plugin -", "promise", "^ 2", "eslint - plugin - standard" : "^ 4.0.0", "eslint - plugin - vue" : "^ 6.1.2 lint -", "staged" : "^ 9.5.0", "vue - the template - the compiler" : "^ 2.6.11"}, "gitHooks" : {" pre - commit ": "lint-staged" }, "lint-staged": { "*.{js,jsx,vue}": [ "vue-cli-service lint", "git add" ] } }Copy the code

Core configuration:

"gitHooks": {
    "pre-commit": "lint-staged"
  },
  "lint-staged": {
    "*.{js,jsx,vue}": [
      "vue-cli-service lint",
      "git add"
    ]
  }
Copy the code

Git add: @vue/standard; git commit:

The pre-commit hook is triggered during git commit execution, executing the NPM Run Precommit script (i.e. Lint-staged commands); Lint-staged configurations can be configured to use Linters to apply filtering rules to file paths in staging, and the matching files perform the configured tasks. The task is to call the ESLint directive in your project to check the files and automatically fix them if they report errors --fix, Finally, add the correct code to the staging area git add. If an error persists, the process terminates and the COMMIT operation cannot be performed.Copy the code