<!--
- @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"
},
异常示列
.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
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。