2

<!--

  • @Author: starkwang
  • @Contact me: https://shudong.wang/about
  • @Date: 2019-10-10 15:48:45
  • @LastEditors: starkwang
  • @LastEditTime: 2019-10-10 19:39:17
  • @Description: 在项目里面配置git commit hook,git commit 时 强制效验代码

-->

本文首发:https://shudong.wang/10579.html

安装包

yarn add husky@next
yarn add -D lint-staged@next

在package.json 配置

  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "src/**/*.js": "eslint"
  },

异常示列

2019-10-10-19-37-04

.eslint.js 文件参考
module.exports = {
  env: {
    browser: true,
    node: true,
    es6: true
  },
  plugins: ['react'],
  parser: 'babel-eslint',
  parserOptions: {
    ecmaVersion: 7,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
      modules: true
    }
  },
  extends: 'react-app',
  rules: {
    'import/prefer-default-export': 0,
    'arrow-body-style': 0,
    'no-use-before-define': 'off',
    'import/no-extraneous-dependencies': [
      1,
      {
        devDependencies: true
      }
    ],
    'import/extensions': 0,
    'prefer-const': 0,
    'object-shorthand': 1,
    'import/first': 0,
    'no-unused-expressions': [
      1,
      {
        allowShortCircuit: true
      }
    ],
    'no-empty': [
      1,
      {
        allowEmptyCatch: true
      }
    ],
    'default-case': 0,
    'no-case-declarations': 0,
    'no-script-url': 0,
    'semi': 0,
    'no-unused-vars': 1,
    'global-require': 0,
    'react/jsx-uses-react': 2,
    'react/jsx-uses-vars': 2,
    'import/no-unresolved': 0,
    'no-unneeded-ternary': 1,
    'no-nested-ternary': 1,
    'no-return-assign': 0,
    'yoda': 'off',
    'dot-notation': 1,
    'no-param-reassign': 1,
    'no-continue': 0,
    'func-names': 1
  }
}

西树先森
7.1k 声望926 粉丝

从事开发多年,前端、后端(go、Python、php)、服务架构都有涉猎,经历过大公司、创业公司,擅长前端及公司技术选型。