Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git提交代码eslint校验配置 #19

Open
chenshenhai opened this issue Jun 4, 2017 · 0 comments
Open

git提交代码eslint校验配置 #19

chenshenhai opened this issue Jun 4, 2017 · 0 comments

Comments

@chenshenhai
Copy link
Owner

chenshenhai commented Jun 4, 2017

1. 安装相关模块

# 安装钩子
npm install --save-dev husky

# 安装eslint
npm install --save-dev eslint babel-eslint

2. 配置脚本

在项目的package.json中添加提交校验脚本

  • precommit 是作为git commit 前校验
  • prepush 是作为git push 前校验
  • eslint_fix 自定义脚本,是用来执行自动eslint修复用的自定义脚本
{
  "scripts": {
    "precommit": "./node_modules/.bin/eslint --ext .jsx,.js ./",
    "prepush": "./node_modules/.bin/eslint --ext .jsx,.js ./",
    "eslint_fix": "./node_modules/.bin/eslint --fix  --ext .jsx,.js ./"
  },
}

3. 其他

配置eslint规则

  • 新建规则文件.eslintrc或者.eslintrc.js这两种文件都可以支持
  • 具体规则配置可以查阅规则文档 http://eslint.cn/docs/rules/

配置eslint忽略文件

在项目根目录下新建 .eslintignore 文件,具体忽略写法与.gitignore的写法一致

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant