npm i --save-dev babel-eslint
npm i --save-dev eslint-loader
npm info "eslint-config-airbnb@latest" peerDependencies
{ eslint: '^5.16.0 || ^6.1.0',
'eslint-plugin-import': '^2.18.2',
'eslint-plugin-jsx-a11y': '^6.2.3',
'eslint-plugin-react': '^7.14.3',
'eslint-plugin-react-hooks': '^1.7.0' } npm i --save-dev eslint@5.16.0
npm i --save-dev eslint-plugin-import@2.18.2
npm i --save-dev eslint-plugin-jsx-a11y@6.2.3
npm i --save-dev eslint-plugin-react@7.14.3
npm i --save-dev eslint-plugin-react-hooks@1.7.0
在根目录创建.eslintrc文件

.eslintrc文件内容如下
{
"parser": "babel-eslint",
"extends": [
"airbnb"
],
"rules": {
// 缩进改为4空格,默认2空格
"indent": [0, 2],
// 对象尾随逗号取消
"comma-dangle": [2, "never"]
},
"plugins": [
"react"
],
"env": {
"browser": true,
"node": true,
"jasmine": true
}
}

1). 添加包

  • npm install eslint --save-dev
  • npm install eslint-loader --save-dev
  • npm install eslint-plugin-html --save-dev 
    • 该插件用与检查写在script标签中的代码
  • npm install babel-eslint --save-dev
    • babel-eslint解析器是一种使用频率很高的解析器,现在很多项目都使用了es6,为了兼容性考虑基本都使用babel插件对代码进行编译。而用babel编译 后的代码使用babel-eslint这款解析器可以避免不必要的麻烦
  • npm install eslint-plugin-react --save-dev
  • npm install eslint-config-airbnb --save-dev
  • npm install eslint-plugin-import --save-dev
  • npm install eslint-plugin-jsx-a11y --save-dev

2)eslint 配置项

  • root :

    • 限定配置文件的使用范围
  • parse:
    • 指定eslint的解析器
  • parserOptions:
    • 设置解析器选项
  • extends:
    • 指定eslint规范
    • extends可以使用eslint官方推荐的,也可以使用第三方的,如:aribnb, google, standard。
      使用第三方的airbnb
  •  
    plugins:
    • 引用第三方的插件
  • env:
    • 指定代码运行的宿主环境
  • rules:
    • 启用额外的规则或覆盖默认的规则
    • /**
      * "off" 或 0 - 关闭规则
      * "warn" 或 1 - 开启规则,使用警告级别的错误:warn (不会导致程序退出),
      * "error" 或 2 - 开启规则,使用错误级别的错误:error (当被触发的时候,程序会退出)
      */

        

  • globals:
    • 声明在代码中的自定义全局变量

4)eslint官方提供了3种预安装包

  • eslint-config-google:
    • Google标准
    • npm install eslint eslint-config-google -D
  • eslint-config-airbnb
    • Airbnb标准,它依赖eslint, eslint-plugin-import, eslint-plugin-react, and eslint-plugin-jsx-a11y等插件,并且对各个插件的版本有所要求
    • 你可以执行以下命令查看所依赖的各个版本:
      • npm info "eslint-config-airbnb@latest" peerDependencies
    • 你会看到以下输出信息,包含每个了每个plugins的版本要求
      •   

        { eslint: '^5.16.0 || ^6.1.0',
        'eslint-plugin-import': '^2.18.2',
        'eslint-plugin-jsx-a11y': '^6.2.3',
        'eslint-plugin-react': '^7.14.3',
        'eslint-plugin-react-hooks': '^1.7.0' }
    • 知道了每个plugins的版本要求后,代入以下命令执行安装即可使用
      • npm install eslint-config-airbnb eslint@^#.#.# eslint-plugin-jsx-a11y@^#.#.# eslint-plugin-import@^#.#.# eslint-plugin-react@^#.#.# -D
  • eslint-config-standard
    • Standard标准,它是一些前端工程师自定的标准
    • npm install eslint-config-standard eslint-plugin-standard eslint-plugin-promise -D

3). 在工程根目录下创建.eslintrc文件

{
"parser": "babel-eslint",
"extends": "airbnb",
"rules": {
"generator-star-spacing": [0],
"consistent-return": [0],
"react/forbid-prop-types": [0],
"react/jsx-filename-extension": [1, { "extensions": [".js"] }],
"global-require": [0],
"import/prefer-default-export": [0],
"react/jsx-no-bind": [0],
"react/prop-types": [0],
"react/prefer-stateless-function": [0],
"no-else-return": [0],
"no-restricted-syntax": [0],
"import/no-extraneous-dependencies": [0],
"no-use-before-define": [0],
"jsx-a11y/no-static-element-interactions": [0],
"no-nested-ternary": [0],
"arrow-body-style": [0],
"import/extensions": [0],
"no-bitwise": [0],
"no-cond-assign": [0],
"linebreak-style": [0],
"import/no-unresolved": [0],
"require-yield": [1],
"prefer-template":[0],
"no-undef":[0],
"no-param-reassign":[0],
"no-useless-escape":[0],
"no-plusplus":[0],
"no-mixed-operators":[0],
"object-shorthand":[0],
"no-console": [0],
"no-loop-func":[0],
"class-methods-use-this":[0],
"radix":[0],
"no-trailing-spaces":[0],
"comma-dangle": [0],
"no-underscore-dangle": [0],
"react/require-default-props": [0],
"no-unused-expressions": [0],
"react/sort-comp":[0],
"max-lines": [2,500],
"max-len": [2,125],
"react/jsx-boolean-value": [0],
"react/react-in-jsx-scope": [0],
"operator-assignment": [0],
"no-fallthrough": [0],
"react/no-array-index-key": [0],
"eqeqeq": [0],
"react/no-multi-comp": [0],
"react/no-unused-prop-types": [0],
"prefer-const": [0]
},
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
}
}

webpack 添加eslint代码审查的更多相关文章

  1. 如何在VUE项目中添加ESLint

    如何在VUE项目中添加ESLint 1. 首先在项目的根目录下 新建 .eslintrc.js文件,其配置规则可以如下:(自己小整理了一份),所有的代码如下: // https://eslint.or ...

  2. vue-cli构建的项目手动添加eslint配置

    一.package.json里配置添加 1.scripts里添加快捷eslint检查命令 "lint": "eslint --ext .js,.vue src" ...

  3. vue + iview 怎样在vue项目下添加ESLint

    参考:https://segmentfault.com/a/1190000012019019?utm_source=tag-newest 使用iview框架的MenuGroup标签,vscode报红, ...

  4. 在React项目中添加ESLint

    1. 安装eslint npm install eslint --save-dev // 或者 yarn add eslint --dev 2. 初始化配置文件 npx eslint --init / ...

  5. 在vue项目中如何添加eslint

    随着vue的越做越好,更多的开发者选择使用vue,本篇记录如何在vue项目中添加eslint. 首先第一种就是在vue项目创建初始时就选择了创建,随着初始化一起代入到了项目当中,那么要是一开始觉得es ...

  6. webpack+vue+Eslint+husky+lint-staged 统一项目编码规范

    一. Eslint: 为什么我们要在项目中使用ESLint ESLint可以校验我们写的代码,给代码定义一个规范,项目里的代码必须按照这个规范写. 加入ESLint有非常多的好处,比如说可以帮助我们避 ...

  7. react+webpack+babel+eslint+redux+react-router+sass 环境快速搭建

    本文中的例子支持webpack-dev-server自动刷新及react热替换,使用了redux管理state,用react-router切换路由,用babel实现ES6语法书写,同时支持async/ ...

  8. 给vue项目添加ESLint

    eslint配置方式有两种: 注释配置:使用js注释来直接嵌入ESLint配置信息到一个文件里 配置文件:使用一个js,JSON或者YAML文件来给整个目录和它的子目录指定配置信息.这些配置可以写在一 ...

  9. atom添加eslint插件

    在atom编辑器里添加插件,操作步骤如下:以atom-ide-vue插件为例 //切换到插件目录cd /Users/name/.atom/packages //将需要下载插件的源代码拉下来git cl ...

随机推荐

  1. 【原理】Reids字典

    I.字典的实现 Redis的字典使用哈希表作为底层实现. 1.1 哈希表 Redis字典所使用的哈希表结构定义如下: typedef struct dictht { // 哈希表数组 dictEntr ...

  2. 同时安装CUDA8.0和CUDA9.0

    http://geyao1995.com/CUDA8_CUDA9/ tensorflow1.5版本竟然不支持CUDA8.0了 卸载是不可能卸载的 1.原料准备 CUDA9.0下载:https://de ...

  3. PHP rewinddir() 函数

    打开一个目录,列出其中的文件,充值目录句柄,重新列出其中的文件,然后关闭: <?php$dir = "/images/"; // Open a directory, and ...

  4. 洛谷P2786 英语1(eng1)- 英语作文

    题目背景 蒟蒻HansBug在英语考场上,挠了无数次的头,可脑子里还是一片空白. 题目描述 眼下出现在HansBug蒟蒻面前的是一篇英语作文,然而智商捉急的HansBug已经草草写完了,此时 他发现离 ...

  5. 优雅的SpringMVC和Restful

    一.前言 1.前段时间一直在写微信小程序的请求,终于把客户端的请求弄好了,可是服务端呢,该怎么写,纠结了半天,用servlet暂时写好了一个:http://www.cnblogs.com/JJDJJ/ ...

  6. [CSP-S模拟测试45]题解

    开局一行$srand$,得分全靠随机化. A.kill 发现两个并不显然的性质: 1.选中的人和怪物一定是按顺序的.第一个人打所有被选中怪物的第一只,第二个人打第二只,$etc$. 2.最优方案打的怪 ...

  7. oracle 批处理 bulk collect 带来的性能优势

    create table -- drop table tmp_20190706_220000-- truncate table tmp_20190706_220000 create table tmp ...

  8. Django2.0中得url路由path得用法

    Django2.0中,url得匹配规则更新了,在django1.0中,url是用正则表达式书写得,相对来说比较繁琐一些,在django2.0中进行了升级优化,改为了path from django.u ...

  9. Objective-C UIWebview JS 交互

    一.在OC中调用网页中的 js 方法. Objective-C 代码 [self.webView stringByEvaluatingJavaScriptFromString:@"alert ...

  10. jQuery Mobile 自定义导航条图标

    1.jQuery Mobile 自定义导航条图标