Code review is essential for engineering projects, but the Linter checker is better at finding and addressing potential syntax errors, improper use of syntax, and keeping code style consistent. The following workflow addresses automatic detection and repair at deployment time for ESLint

install

yarn add eslint yorkie lint-staged -D

configure

eslint

// .eslintrc.js
module.exports = {
  root: true.parser: 'babel-eslint'.parserOptions: {
    sourceType: 'module'
  },
  env: {
    browser: true
  },
  globals: {
    android: false
  },
  // ...
}

Copy the code

yorkie

/.git/hooks/pre-commit /.git/hooks/pre-commit

// package.json
{
	"gitHooks": {
    	"pre-commit": "lint-staged"}}Copy the code

lint-staged

If [$file in SRC /**/*.js]; $file in SRC /**/*.js]; do eslint –fix && git add; fi

// .lintstagedrc
{
  "src/**/*.{js,vue}": ["eslint --fix"."git add"]."src/*.{js,vue}": ["eslint --fix"."git add"]}Copy the code

Usage

Git commit -m $MSG triggers the pre-commit hook and performs lint-staged configuration (.lintStageDRC), which is automatically fixed and then added into staging, esLint –fix && git add

workflow