├── examples └── usage-with-lint-staged │ ├── .eslintignore │ ├── .gitignore │ ├── index.js │ ├── package.json │ └── .eslintrc.js ├── .gitignore ├── .editorconfig ├── eslint-config-react └── index.js ├── package.json ├── README-zh_CN.md ├── README.md ├── CHANGELOG.md ├── docs ├── eslint-standard.md └── RULE.md ├── index.js └── LICENSE /examples/usage-with-lint-staged/.eslintignore: -------------------------------------------------------------------------------- 1 | fis-conf.js 2 | -------------------------------------------------------------------------------- /examples/usage-with-lint-staged/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | .DS_Store 3 | node_modules/ -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .DS_Store 3 | node_modules 4 | *.log 5 | *-lock.json 6 | coverage/ -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | charset = utf-8 6 | trim_trailing_whitespace = true 7 | 8 | [index.js] 9 | indent_style = space 10 | indent_size = 2 -------------------------------------------------------------------------------- /examples/usage-with-lint-staged/index.js: -------------------------------------------------------------------------------- 1 | var a = 1, 2 | b = 2; 3 | 4 | var c = a + b; 5 | var d = a + b; 6 | 7 | console.log(c); 8 | console.log(d); 9 | 10 | alert(111); 11 | 12 | alert(222); -------------------------------------------------------------------------------- /examples/usage-with-lint-staged/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-lint-staged", 3 | "version": "0.0.1", 4 | "scripts": { 5 | "precommit": "lint-staged" 6 | }, 7 | "lint-staged": { 8 | "src/*.{js,jsx}": [ 9 | "eslint --fix", 10 | "git add" 11 | ] 12 | }, 13 | "devDependencies": { 14 | "eslint": "^4.8.0", 15 | "eslint-config-ivweb": "^0.1.0", 16 | "husky": "^0.14.3", 17 | "lint-staged": "^4.2.3" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/usage-with-lint-staged/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "plugins": [ 3 | "react" 4 | ], 5 | "env": { 6 | "es6": true, 7 | "browser": true, 8 | "node": true 9 | }, 10 | "parserOptions": { 11 | "ecmaVersion": 6, 12 | "sourceType": "module", 13 | "ecmaFeatures": { 14 | "jsx": true 15 | } 16 | }, 17 | "extends": ["eslint:recommended", "plugin:react/recommended", "ivweb"], 18 | "globals": { 19 | "__inline": true, 20 | "IS_SERVER": true, 21 | "__uri": true 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /eslint-config-react/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "parser": "babel-eslint", 3 | "plugins": [ 4 | "react" 5 | ], 6 | "rules": { 7 | "react/jsx-uses-react": 2, 8 | "react/no-did-update-set-state": 2, 9 | "react/no-redundant-should-component-update": 2, 10 | "react/no-will-update-set-state": 2, 11 | "react/require-render-return": 2, 12 | "react/jsx-closing-tag-location": 2, 13 | "react/jsx-closing-bracket-location": [2, { selfClosing: 'tag-aligned' }], 14 | "react/jsx-key": 2, 15 | "react/jsx-no-bind": 2, 16 | "react/jsx-pascal-case": 2, 17 | "react/jsx-uses-vars": 2, 18 | } 19 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-config-ivweb", 3 | "version": "0.1.5", 4 | "description": "腾讯IVWEB团队eslint配置检测规范", 5 | "license": "Apache-2.0", 6 | "repository": "iv-web/eslint-config-ivweb", 7 | "author": "IVWEB", 8 | "engines": { 9 | "node": ">=0.10.0" 10 | }, 11 | "scripts": { 12 | "test": "node test/test.js", 13 | "commitmsg": "validate-commit-msg", 14 | "commit": "git-cz ", 15 | "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0" 16 | }, 17 | "files": [ 18 | "index.js", 19 | "eslint-config-react" 20 | ], 21 | "keywords": [ 22 | "ivweb", 23 | "code", 24 | "quality", 25 | "style", 26 | "lint", 27 | "eslint", 28 | "validate", 29 | "code style" 30 | ], 31 | "dependencies": { 32 | "eslint-plugin-react": "^7.7.0" 33 | }, 34 | "devDependencies": { 35 | "babel-eslint": "^8.2.3", 36 | "commitizen": "^2.3.0", 37 | "conventional-changelog-cli": "^1.2.0", 38 | "eslint": "^4.1.1", 39 | "husky": "^0.13.1", 40 | "validate-commit-msg": "^2.11.1" 41 | }, 42 | "peerDependencies": { 43 | "eslint": ">=4.1.1" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /README-zh_CN.md: -------------------------------------------------------------------------------- 1 | eslint-config-ivweb 2 | =========================== 3 | 4 | [![npm package](https://img.shields.io/npm/v/eslint-config-ivweb.svg?style=flat-square)](https://www.npmjs.org/package/eslint-config-ivweb) 5 | [![NPM downloads](http://img.shields.io/npm/dt/eslint-config-ivweb.svg?style=flat-square)](https://npmjs.org/package/eslint-config-ivweb) 6 | 7 | 腾讯IVWEB团队ESLint共享配置规则 8 | 9 | ## 安装 10 | 11 | ``` 12 | $ npm install --save-dev eslint eslint-plugin-react eslint-config-ivweb 13 | ``` 14 | 15 | ## 文档 16 | * [介绍](docs/eslint-standard.md) 17 | * [规则解释](docs/RULE.md) 18 | 19 | ## 使用 20 | 一旦`eslint-config-ivweb`安装成功,你可以通过[ESLint配置文件]((http://eslint.org/docs/user-guide/configuring)) 中的字段extends中使用它 21 | 22 | ```js 23 | { 24 | "extends": "ivweb", 25 | "rules": { 26 | // Additional, per-project rules... 27 | } 28 | } 29 | ``` 30 | 31 | ### 配合`eslint:recommended`使用`ivweb` 32 | 有部分[eslint:recommended](http://eslint.org/docs/rules/)提到的规则在ivweb中没有提到,因此最好配合eslint:recommend一起使用。 33 | 34 | 只需要同时继承eslint:recommend 和 ivweb 即可,确保 ivweb 放置在最后。部分eslint:recommend定义的规则有点严格,ivweb里面有做定制化的修改。 35 | 36 | ```js 37 | { 38 | "extends": ["eslint:recommended", "plugin:react/recommended", "ivweb"], 39 | "rules": { 40 | // Additional, per-project rules... 41 | } 42 | } 43 | ``` 44 | 45 | ## 如何贡献 46 | 47 | 1. 从目前已经存在的issue或者提出一个新的issue去讨论新的特性或者存在的bug. 48 | 2. 在Github上Fork [仓库](https://github.com/feflow/eslint-config-ivweb)_,然后在master或者其它分支上开始进行您的修改. 49 | 3. 编写测试用力表明某个bug被修复掉了或者新的特性可以正常工作. 50 | 4. 提交PR直到它被merge或者发布出去了. :) 记得把您添加进 [AUTHORS_](AUTHORS). 51 | 52 | ## 版本日志 53 | 54 | [版本日志](CHANGELOG.md) 55 | 56 | ## 许可证 57 | 58 | Apache-2 © IVWEB 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # eslint-config-ivweb 2 | 3 | [![npm package](https://img.shields.io/npm/v/eslint-config-ivweb.svg?style=flat-square)](https://www.npmjs.org/package/eslint-config-ivweb) 4 | [![NPM downloads](http://img.shields.io/npm/dt/eslint-config-ivweb.svg?style=flat-square)](https://npmjs.org/package/eslint-config-ivweb) 5 | 6 | ESLint shareable config for the IVWEB JavaScript style guide. 7 | 8 | [中文 README](README-zh_CN.md) 9 | 10 | ## Installation 11 | 12 | ``` 13 | $ npm install --save-dev eslint eslint-plugin-react eslint-config-ivweb 14 | ``` 15 | 16 | ## Documents 17 | * Introduction: [eslint-standard.md](docs/eslint-standard.md) 18 | * Rules explanation: [RULES.md](docs/RULE.md) 19 | 20 | ## Usage 21 | 22 | Once the `eslint-config-ivweb` package is installed, you can use it by specifying `ivweb` in the [`extends`](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) section of your [ESLint configuration](http://eslint.org/docs/user-guide/configuring). 23 | 24 | ```js 25 | { 26 | "extends": "ivweb", 27 | "rules": { 28 | // Additional, per-project rules... 29 | } 30 | } 31 | ``` 32 | 33 | ### Using the `ivweb` config with `eslint:recommended` 34 | 35 | There are several rules in the [`eslint:recommended` ruleset](http://eslint.org/docs/rules/) that IVWEB style is not opinionated about that you might want to enforce in your project. 36 | 37 | To use IVWEB style in conjunction with ESLint's recommended rule set, extend them both, making sure to list `ivweb` last: 38 | 39 | ```js 40 | { 41 | "extends": ["eslint:recommended", "plugin:react/recommended", "ivweb"], 42 | "rules": { 43 | // Additional, per-project rules... 44 | } 45 | } 46 | ``` 47 | 48 | To see how the `ivweb` config compares with `eslint:recommended`, refer to the [source code of `index.js`](https://github.com/iv-web/eslint-config-ivweb/blob/master/index.js), which lists every ESLint rule along with whether (and how) it is enforced by the `ivweb` config. 49 | 50 | ## Contributing 51 | 52 | 1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug. 53 | 2. Fork [the repository](https://github.com/iv-web/eslint-config-ivweb)_ on GitHub to start making your changes to the **master** branch (or branch off of it). 54 | 3. Write a test which shows that the bug was fixed or that the feature works as expected. 55 | 4. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to [AUTHORS_](AUTHORS). 56 | 57 | ## License 58 | 59 | Apache-2 © IVWEB 60 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | ## [0.1.5](https://github.com/iv-web/eslint-config-ivweb/compare/v0.1.4...v0.1.5) (2018-11-13) 3 | 4 | 5 | ### Bug Fixes 6 | 7 | * 函数名前面不需要加上空格 ([88ac283](https://github.com/iv-web/eslint-config-ivweb/commit/88ac283)), closes [#5](https://github.com/iv-web/eslint-config-ivweb/issues/5) 8 | 9 | 10 | 11 | 12 | ## [0.1.4](https://github.com/iv-web/eslint-config-ivweb/compare/v0.1.3...v0.1.4) (2018-07-18) 13 | 14 | 15 | 16 | 17 | ## [0.1.3](https://github.com/iv-web/eslint-config-ivweb/compare/v0.1.2...v0.1.3) (2018-07-18) 18 | 19 | 20 | ### Bug Fixes 21 | 22 | * eslint-plugin-react dependices. ([92173bd](https://github.com/iv-web/eslint-config-ivweb/commit/92173bd)) 23 | 24 | 25 | 26 | 27 | ## [0.1.2](https://github.com/iv-web/eslint-config-ivweb/compare/v0.1.0...v0.1.2) (2018-05-11) 28 | 29 | 30 | ### Bug Fixes 31 | 32 | * update demo, parsing error: 'import' and 'export' may appear only with 'sourceType: module' ([0ae9617](https://github.com/iv-web/eslint-config-ivweb/commit/0ae9617)) 33 | 34 | 35 | ### Features 36 | 37 | * support react config ([03b09c0](https://github.com/iv-web/eslint-config-ivweb/commit/03b09c0)) 38 | * update config ([c50b596](https://github.com/iv-web/eslint-config-ivweb/commit/c50b596)) 39 | * update example ([76dbfb0](https://github.com/iv-web/eslint-config-ivweb/commit/76dbfb0)) 40 | * 修改配置 ([3c864c6](https://github.com/iv-web/eslint-config-ivweb/commit/3c864c6)) 41 | 42 | 43 | 44 | 45 | # [0.1.0](https://github.com/iv-web/eslint-config-ivweb/compare/v0.0.4...v0.1.0) (2017-10-02) 46 | 47 | 48 | ### Features 49 | 50 | * add rules in stylistic ([3bba823](https://github.com/iv-web/eslint-config-ivweb/commit/3bba823)) 51 | * add stylistic rules ([26034fa](https://github.com/iv-web/eslint-config-ivweb/commit/26034fa)) 52 | * ES6 rules supported ([3275a23](https://github.com/iv-web/eslint-config-ivweb/commit/3275a23)) 53 | 54 | 55 | 56 | 57 | ## [0.0.4](https://github.com/iv-web/eslint-config-ivweb/compare/v0.0.2...v0.0.4) (2017-09-29) 58 | 59 | 60 | ### Bug Fixes 61 | 62 | * code syntax error ([d6a042a](https://github.com/iv-web/eslint-config-ivweb/commit/d6a042a)) 63 | 64 | 65 | 66 | 67 | ## [0.0.2](https://github.com/iv-web/eslint-config-ivweb/compare/v0.0.1...v0.0.2) (2017-09-29) 68 | 69 | 70 | ### Features 71 | 72 | * add rule for best practice section. ([2e4e303](https://github.com/iv-web/eslint-config-ivweb/commit/2e4e303)) 73 | * add rules for possiable errors and best practice ([4b8a092](https://github.com/iv-web/eslint-config-ivweb/commit/4b8a092)) 74 | * improve best practice ([e5083ce](https://github.com/iv-web/eslint-config-ivweb/commit/e5083ce)) 75 | * modify eslint:recommend rules and add new rules ([437b47d](https://github.com/iv-web/eslint-config-ivweb/commit/437b47d)) 76 | 77 | 78 | 79 | 80 | ## [0.0.1](https://github.com/iv-web/eslint-config-ivweb/compare/ee765de...v0.0.1) (2017-09-16) 81 | 82 | 83 | ### Features 84 | 85 | * initial rule commit ([ee765de](https://github.com/iv-web/eslint-config-ivweb/commit/ee765de)) 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /docs/eslint-standard.md: -------------------------------------------------------------------------------- 1 | [ESLint](https://eslint.org/)于2013年6月份推出,至今4个年头,最新版本v4.8.0。它是目前主流的用于Javascript和JSX代码规范检查的利器,很多大公司比如[Airbnb](https://github.com/airbnb/javascript)和[Google](https://google.github.io/styleguide/javascriptguide.xml)均有一套自己的Javascript编码规范,而规范的实施背后离不开ESLint的支持。比如大名顶顶的[eslint-config-airbnb](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb)和[eslint-config-google](https://github.com/google/eslint-config-google)。为了更好的统一团队的JS编程风格和代码质量。[feflow](https://github.com/feflow)官方经过调研和探索,终于迎来了ESLint的解决方案,最核心的理念是:基于eslint:recommend做规则的定制化。 2 | 3 | ## 从一次生产事故说起 4 | 5 | 2017年4月13日,腾讯高级工程师小圣在做充值业务时,修改了苹果iap支付配置,将JSON配置增加了重复的key。代码发布后,有小部分使用了vivo手机的用户反馈充值页面白屏,无法在Now app内进行充值。最后问题定位是:vivo手机使用了系统自带的webview而没有使用X5内核,解析JSON时遇到重复key报错,导致页面白屏。 6 | 7 | 类似的问题其实很多: 比如变量未定义,方法被覆盖等等都会造成js代码执行时报错。那么如何避免呢?ESLint官方提供sharable config(可共享配置),前端团队可以根据自身团队情况定制ESLint规范配置。 8 | 9 | ## 规则定义准则 10 | * 不重复造轮子,基于eslint:recommend配置并改进 11 | * 能够帮助发现代码错误的规则,全部开启 12 | * 目的是团队的代码风格统一,而不是限制开发体验 13 | 14 | ## eslint-config-ivweb 介绍 15 | eslint-config-ivweb是腾讯NOW直播IVWEB团队的ESLint配置。目前发布初版,目前大约有130条规则,包含可能存在的错误、最佳实践、变量、代码风格、ES6相关等5个大的规则板块。 16 | 17 | 仓库地址:https://github.com/feflow/eslint-config-ivweb 18 | 欢迎提交issue或者PR一起参与团队规则维护 19 | 20 | ## 部分规则说明 21 | ![](https://pub.idqqimg.com/pc/misc/files/20171011/7a4572cf1c4b4690895f80bce33a76a1.jpg) 22 | 包含3个信息: 最左侧是规则,中间是错误级别,右侧是解释说明含义。错误级别包含:error、warn和off三个级别。 23 | 24 | 更加详细的规则说明可以前往: [规则文档](https://github.com/feflow/eslint-config-ivweb/blob/master/docs/RULE.md) 25 | 26 | ## 项目接入使用 27 | 28 | 基本理念: 项目代码太多,不影响历史代码。只针对有改动的代码(.js和.jsx后缀)才进行校验。 29 | 30 | 第一步:添加或者修改.eslintrc.js 配置文件 31 | 32 | ``` javascript 33 | module.exports = { 34 | "plugins": [ 35 | "react" 36 | ], 37 | "env": { 38 | "es6": true, 39 | "browser": true, 40 | "node": true 41 | }, 42 | "parserOptions": { 43 | "sourceType": "module" 44 | }, 45 | "extends": ["eslint:recommended", "plugin:react/recommended", "ivweb"], 46 | "globals": { 47 | "__inline": true, 48 | "IS_SERVER": true, 49 | "__uri": true 50 | } 51 | }; 52 | ``` 53 | 54 | 有部分eslint:recommended提到的规则在ivweb中没有提到,因此最好配合eslint:recommend一起使用。 55 | 56 | 只需要同时继承eslint:recommend 和 ivweb 即可,确保 ivweb 放置在最后。部分eslint:recommend定义的规则有点严格,ivweb里面有做定制化的修改。 57 | 58 | 第二步:增加precommit的hook和eslint-config-ivweb依赖 59 | 60 | 此处我们使用husky来管理所有的Hook,同之前的commit message校验。 61 | 62 | ``` 63 | { 64 | "name": "with-lint-staged", 65 | "version": "0.0.1", 66 | "scripts": { 67 | "precommit": "lint-staged" 68 | }, 69 | "lint-staged": { 70 | "src/*.{js,jsx}": [ 71 | "eslint --fix", 72 | "git add" 73 | ] 74 | }, 75 | "devDependencies": { 76 | "eslint": "^4.8.0", 77 | "eslint-plugin-react": "^7.4.0", 78 | "eslint-config-ivweb": "^0.1.0", 79 | "husky": "^0.14.3", 80 | "lint-staged": "^4.2.3" 81 | } 82 | } 83 | ``` 84 | 85 | ## 答疑互动 86 | 87 | Q: 为什么不直接使用airbnb团队的 eslint-config-airbnb? 88 | A: airbnb官方的规则过于庞大,有10多个规则文件。维护起来成本较高,选择基于轻量级的 eslint:recommend 基础之上定制团队ESLint规则更加简单,也便于维护。 89 | 90 | Q: 我觉得eslint-config-ivweb有些规则不太合适,怎么办? 91 | A: 欢迎提交issue讨论或者直接提交PR。仓库地址:https://github.com/feflow/eslint-config-ivweb 92 | 93 | Q: 为什么使用lint-staged? 94 | A: lint-staged只会对修改过的js文件行数进行代码规范检查,不会对所有的代码检查,更加合理和可操作。 95 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: ["./eslint-config-react/index.js"], 5 | rules: { 6 | /* section1 : 可能存在的错误 */ 7 | // error; for循转方向出错 8 | 'for-direction': 2, 9 | // error; getter必须有返回值,并且禁止返回值为undefined, 比如 return; 10 | 'getter-return': [2, {allowImplicit: false}], 11 | // off; 不允许在循环中出现await 12 | 'no-await-in-loop': 0, 13 | // off; 允许使用console进行代码调试 14 | 'no-console': 0, 15 | // warn; 直接调用对象原型链上的方法 16 | 'no-prototype-builtins': 1, 17 | // off; 函数注释一定要遵守jsdoc规则 18 | 'valid-jsdoc': 0, 19 | // warn; 在字符串里面出现{和}进行警告 20 | 'no-template-curly-in-string': 1, 21 | // warn; get和set没有成对出现时给出警告 22 | 23 | /* section2: 最佳实践 */ 24 | 'accessor-pairs': 1, 25 | // error; 对于数据相关操作函数比如reduce, map, filter等,callback必须有return 26 | 'array-callback-return': 2, 27 | // error; 把var关键字看成块级作用域,防止变量提升导致的bug 28 | 'block-scoped-var': 2, 29 | // off; 要求在Class里面合理使用this,如果某个方法没有使用this,则应该申明为静态方法 30 | 'class-methods-use-this': 0, 31 | // off; 关闭代码复杂度限制 32 | 'complexity': 0, 33 | // error; switch case语句里面一定需要default分支 34 | 'default-case': 2, 35 | // warn: 代码中使用了alert给出警告 36 | 'no-alert': 1, 37 | // off; 不允许使用空函数,除非在空函数里面给出注释说明 38 | 'no-empty-function': 0, 39 | // off; foo == null 用于判断 foo 不是 undefined 并且不是 null,比较常用,故允许此写法 40 | 'no-eq-null': 0, 41 | // error; 代码中不允许使用eval 42 | 'no-eval': 2, 43 | // error; 禁止修改原生对象 44 | 'no-extend-native': 2, 45 | // error; 禁止出现没必要的 bind 46 | 'no-extra-bind': 2, 47 | // error; 表示小数时,禁止省略 0,比如 .5 48 | 'no-floating-decimal': 2, 49 | // off; 允许这些写法,性能上更好 50 | 'no-implicit-coercion': 0, 51 | // error; 浏览器端不允许定义全局变量和全局函数,可以通过挂载到window对象上和使用IIFE表达式 52 | 'no-implicit-globals': 2, 53 | // off; this的使用比较灵活 54 | 'no-invalid-this': 0, 55 | // error; 禁止使用 __iterator__ 56 | 'no-iterator': 2, 57 | // error; 禁止使用没必要的 {} 作为代码块 58 | 'no-lone-blocks': 2, 59 | // off; 允许代码里面使用魔法数(多次使用,没有使用枚举的方式进行定义的数字) 60 | 'no-magic-numbers': 0, 61 | // error; 禁止出现连续的多个空格,除非是注释前,或对齐对象的属性、变量定义、import 等 62 | 'no-multi-spaces': [ 63 | 2, 64 | { 65 | ignoreEOLComments: true, 66 | exceptions: { 67 | Property: true, 68 | BinaryExpression: false, 69 | VariableDeclarator: true, 70 | ImportDeclaration: true 71 | } 72 | } 73 | ], 74 | // error; 禁止使用/来进行字符串换行 75 | 'no-multi-str': 2, 76 | // error; 禁止直接 new 一个类而不赋值 77 | 'no-new': 2, 78 | // error; 禁止使用 new Function,比如 const expression = new Function("a", "b", "return a + b"); 79 | 'no-new-func': 2, 80 | // error; 对于JS的原始类型比如String, Number, Boolean等,不允许使用new 操作符 81 | 'no-new-wrappers': 2, 82 | // error; 禁止使用八进制的转义符比如 "Copyright \251" 83 | 'no-octal-escape': 2, 84 | // error; 禁止对函数的参数重新赋值 85 | 'no-param-reassign': 2, 86 | // error; 禁止直接使用__proto__属性,可以使用getPrototypeOf替代 87 | 'no-proto': 2, 88 | // error; return语句中禁止进行赋值语句操作 89 | 'no-return-assign': 2, 90 | // error; 禁止在 return 语句里使用 await 91 | 'no-return-await': 2, 92 | // off; 允许location.href = 'javascript:void(0)'的形式 93 | 'no-script-url': 0, 94 | // error; 禁止throw一个字面量,比如 throw 2, throw "error"; 95 | 'no-throw-literal': 2, 96 | // error; 禁止出现没必要的 call 或 apply 97 | 'no-useless-call': 2, 98 | // error; 禁止出现没必要的字符串拼接,比如 'hello' + 'world',可以直接写成'hello world' 99 | 'no-useless-concat': 2, 100 | // off; 对return的使用不进行限制 101 | 'no-useless-return': 0, 102 | // error; 禁止在代码里面出现void 103 | 'no-void': 2, 104 | // off; TODO 和 FIXME 类型的注释用的比较多,不限制 105 | 'no-warning-comments': 0, 106 | // error; 代码里面禁止使用 with 表达式 107 | 'no-with': 2, 108 | // error; Promise 的 reject方法必须传入 Error 对象,而不能是字面量 109 | 'prefer-promise-reject-errors': 2, 110 | // off; parseInt的时候第二个参数可以不传入,默认就是10进制 111 | 'radix': 0, 112 | // error; async函数里面必须有await 113 | 'require-await': 2, 114 | // off; var变量定义没必要限制太严格 115 | 'vars-on-top': 0, 116 | 117 | /* section3: 变量 */ 118 | // off; 变量定义时强制赋值或者强制先定义后赋值有点严格 119 | 'init-declarations': 0, 120 | // error; 禁止label名称和var相同 121 | 'no-label-var': 2, 122 | // error; 禁止将undefined当成标志符 123 | 'no-undefined': 2, 124 | // error; 禁止使用未定义的变量, typeof 后面的变量除外 125 | 'no-undef': [ 126 | 2, 127 | { 128 | typeof: false 129 | } 130 | ], 131 | // error; 变量使用之前必须进行定义 132 | 'no-use-before-define': 2, 133 | 134 | // section 4: 代码风格相关 135 | // off; 数组前后括号必须换行的要求有点严格,不采纳 136 | 'array-bracket-newline': 0, 137 | // error; 数组的括号前后禁止有空格 138 | 'array-bracket-spacing': [2, 'never'], 139 | // off; 数组里面的元素强制换行有点严格,不采纳 140 | 'array-element-newline': 0, 141 | // error; 代码块如果在一行,则大括号内的首尾必须有空格,比如 function (a, b) { retur a + b; } 142 | 'block-spacing': [ 143 | 2, 144 | 'always' 145 | ], 146 | // error; 大括号的用法要求 147 | 'brace-style': 2, 148 | // off; 变量命名需要以驼峰命名法,对属性字段不做限制 149 | 'camelcase': [0, {properties: 'never'}], 150 | // off; 注释的首字母必须大写,对此不做限制 151 | 'capitalized-comments': 0, 152 | // error; 默认不允许尾随逗号, ie8及以下浏览器会报错 153 | 'comma-dangle': 2, 154 | // error; 逗号后面强制要求加空格 155 | 'comma-spacing': 2, 156 | // error; 逗号必须写在最后面 157 | 'comma-style': [ 158 | 2, 159 | 'last' 160 | ], 161 | // off; 文件尾部不限制是否有新的空行 162 | 'eol-last': 0, 163 | // off; 函数名和执行它的括号之间禁止有空格 164 | 'func-call-spacing': [2, 'never'], 165 | // off; 函数赋值给变量时,函数名必须和赋值的变量名一致的限制不采纳 166 | 'func-name-matching': 0, 167 | // off; 不限制匿名函数的命名问题 168 | 'func-names': 0, 169 | // off; 必须只使用函数申明或只使用函数表达式 170 | 'func-style': 0, 171 | // off; 变量黑名单,不采纳 172 | 'id-blacklist': 0, 173 | // off; 变量命名长度不做限制 174 | 'id-length': 0, 175 | // off; 变量命令的字符需要在某个正则匹配规则里面,不采纳 176 | 'id-match': 0, 177 | // error; 一个缩进必须用四个空格替代, switch语句里面的case 2个空格 178 | 'indent': [ 179 | 2, 180 | 4, 181 | { 182 | SwitchCase: 1, 183 | flatTernaryExpressions: true 184 | } 185 | ], 186 | // error; jsx 中的属性必须用双引号 187 | 'jsx-quotes': [2, 'prefer-double'], 188 | // error; 对象字面量中冒号前面禁止有空格,后面必须有空格 189 | 'key-spacing': [ 190 | 2, 191 | { 192 | beforeColon: false, 193 | afterColon: true, 194 | mode: 'strict', 195 | } 196 | ], 197 | // error; 关键字前后必须要加上空格 198 | 'keyword-spacing': [ 199 | 2, 200 | { 201 | before: true, 202 | after: true 203 | } 204 | ], 205 | // off; 注释的位置不进行限制 206 | 'line-comment-position': 0, 207 | // off; 对换行符不限制 208 | 'linebreak-style': 0, 209 | // off; 注释前后必须有空行的限制,不采纳 210 | 'lines-around-comment': 0, 211 | // error; 代码块嵌套的深度禁止超过 5 层 212 | 'max-depth': [ 213 | 2, 214 | 5 215 | ], 216 | // error; 单行最多允许200个字符, 对包含url的行不进行此限制 217 | 'max-len': [2, { 218 | code: 150, 219 | tabWidth: 2, 220 | ignoreUrls: true 221 | }], 222 | // off; 某个文件能够放置的最大代码行数,不限制 223 | 'max-lines': 0, 224 | // error; 回调函数嵌套禁止超过 3 层,多了请用 async await 替代 225 | 'max-nested-callbacks': [ 226 | 'error', 227 | 3 228 | ], 229 | // error; 函数的参数禁止超过 10 个 230 | 'max-params': [2, 10], 231 | // off; 一个函数块里面的语句行数的限制,不采纳 232 | 'max-statements': 0, 233 | // off; 一行中的语句数量 234 | 'max-statements-per-line': 0, 235 | // off; 三目元算语句换行限制,不采纳 236 | 'multiline-ternary': 0, 237 | // error; 构造函数的必须以大写字母开头 238 | 'new-cap': 2, 239 | // error; new 后面类必须带上括号 240 | 'new-parens': 2, 241 | // off; 链式调用必须换行的限制,不采纳 242 | 'newline-per-chained-call': 0, 243 | // error; 禁止使用 Array 构造函数 244 | 'no-array-constructor': 2, 245 | // off; 位操作,不进行限制 246 | 'no-bitwise': 0, 247 | // off; continue语句的使用,不限制 248 | 'no-continue': 0, 249 | // off; 内联注释不限制 250 | 'no-inline-comments': 0, 251 | // off; 允许单独使用if语句,而不配套使用else、else if等 252 | 'no-lonely-if': 0, 253 | // error; 禁止混用空格和缩进 254 | 'no-mixed-spaces-and-tabs': 2, 255 | // off; 连续赋值比如 a = b = c = 4; 不限制 256 | 'no-multi-assign': 0, 257 | // off; 连续空行,不限制 258 | 'no-multiple-empty-lines': 0, 259 | // off; if里面不允许出现否定表达式, 不采纳 260 | 'no-negated-condition': 0, 261 | // off; 允许三元表达式的嵌套使用 262 | 'no-nested-ternary': 0, 263 | // off; 禁止直接 new Object 264 | 'no-new-object': 2, 265 | // off; 允许使用 ++ 或 -- 266 | 'no-plusplus': 0, 267 | // off; 允许使用三元表达式 268 | 'no-ternary': 0, 269 | // error; 禁止行尾部有空格 270 | 'no-trailing-spaces': 2, 271 | // off; 允许变量名中出现下划线 272 | 'no-underscore-dangle': 0, 273 | 'no-unneeded-ternary': 0, 274 | // error; 禁止属性前有空格,比如 foo. bar() 275 | 'no-whitespace-before-property': 2, 276 | // error; 大括号内的首尾必须有换行 277 | 'object-curly-newline': [ 278 | 2, 279 | { 280 | multiline: true, 281 | consistent: true 282 | } 283 | ], 284 | // off; 对象字面量内的属性每行必须只有一个,不采纳 285 | 'object-property-newline': 0, 286 | // off; 声明变量时,禁止一条语句声明多个变量 287 | 'one-var': [0, { 288 | var: 'never', 289 | let: 'never', 290 | const: 'never', 291 | }], 292 | // error; 变量申明必须每行一个 293 | 'one-var-declaration-per-line': [2, 'always'], 294 | // error; 必须使用单引号 295 | 'quotes': [ 296 | 2, 297 | 'single', 298 | { 299 | avoidEscape: true, 300 | allowTemplateLiterals: true 301 | } 302 | ], 303 | // error; 结尾必须有分号 304 | 'semi': 2, 305 | // error; 一行有多个语句时,分号前面禁止有空格,分号后面必须有空格 306 | 'semi-spacing': [ 307 | 2, 308 | { 309 | before: false, 310 | after: true 311 | } 312 | ], 313 | // error; 分号必须写在行尾,禁止在行首出现 314 | 'semi-style': [2, 'last'], 315 | 'sort-keys': 0, 316 | 'sort-vars': 0, 317 | // error; if, function 等的大括号之前必须要有空格 318 | 'space-before-blocks': [2, 'always'], 319 | // error; function 的小括号前面必须有空格 320 | 'space-before-function-paren': [2, { 321 | 'anonymous': 'always', 322 | 'named': 'never', 323 | 'asyncArrow': 'always' 324 | }], 325 | // error; 小括号内的首尾禁止有空格 326 | 'space-in-parens': [2, 'never'], 327 | // error; 操作符左右必须有空格, const ret = 'hello' + 'world'; 328 | 'space-infix-ops': 2, 329 | // off; 注释空格不限制 330 | 'spaced-comment': 0, 331 | // off; case 子句冒号前禁止有空格,冒号后必须有空格 332 | 'switch-colon-spacing': [ 333 | 2, 334 | { 335 | after: true, 336 | before: false 337 | } 338 | ], 339 | 340 | // section 5: ES6 语法相关 341 | // off; 箭头函数返回值可以只是一个值,没必须一定用大括号写成多条语句. 342 | 'arrow-body-style': 0, 343 | // off; 箭头函数的参数必须用括号包裹起来,限制去掉。当只有一个参数时,没必要使用括号 344 | 'arrow-parens': 0, 345 | // error; 箭头函数的箭头前后必须有空格 346 | 'arrow-spacing': [ 347 | 2, 348 | { 349 | before: true, 350 | after: true 351 | } 352 | ], 353 | // error; generator 的 * 前面禁止有空格,后面必须有空格 354 | 'generator-star-spacing': [ 355 | 2, 356 | { 357 | before: false, 358 | after: true 359 | } 360 | ], 361 | // error; 禁止import重复模块 362 | 'no-duplicate-imports': 2, 363 | // error; 禁止采用var去定义变量,必须使用let或者const 364 | 'no-var': 2, 365 | // off; 必须使用箭头函数作为回调,不采纳 366 | 'prefer-arrow-callback': 0, 367 | // error; 变量如果没有发生修改,则必须使用const进行命名 368 | 'prefer-const': 2, 369 | // off; 强制使用结构的限制,不采纳 370 | 'prefer-destructuring': 0, 371 | // off; 不强制使用模板字符串,字符串拼接也是可取的 372 | 'prefer-template': 0, 373 | // error; ... 的后面禁止有空格 374 | 'rest-spread-spacing': [2, 'never'], 375 | // off; import 的排序不用限制 376 | 'sort-imports': 0, 377 | // error; 模板字符串内的首尾禁止有空格,比如${test}不要写成${ test } 378 | // TODO: 当jsx代码里有xxProp={``}会导致eslint出错奔溃,先注释 379 | // 'template-curly-spacing': [2, 'never'], 380 | // error; yield* 后面必须加空格 381 | 'yield-star-spacing': [2, 'after'], 382 | "react/prop-types": 0 383 | } 384 | }; 385 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /docs/RULE.md: -------------------------------------------------------------------------------- 1 | ## 规则列表 2 | 3 | | 规则名称 | 错误级别 | 说明 | 4 | | :------------- |:-------------| :-----| 5 | | [for-direction](https://eslint.org/docs/rules/for-direction) | error | for 循环的方向要求必须正确 | 6 | | [getter-return](https://eslint.org/docs/rules/getter-return) | error | getter必须有返回值,并且禁止返回值为undefined, 比如 return; | 7 | | [no-await-in-loop](https://eslint.org/docs/rules/no-await-in-loop)| off | 允许在循环里面使用await | 8 | | [no-console](https://eslint.org/docs/rules/no-console) | off | 允许在代码里面使用console | 9 | | [no-prototype-builtins](https://eslint.org/docs/rules/no-prototype-builtins) | warn | 直接调用对象原型链上的方法 | 10 | | [valid-jsdoc](https://eslint.org/docs/rules/valid-jsdoc) | off | 函数注释一定要遵守jsdoc规则 | 11 | | [no-template-curly-in-string](https://eslint.org/docs/rules/no-template-curly-in-string) | warn | 在字符串里面出现{和}进行警告 | 12 | | [accessor-pairs](https://eslint.org/docs/rules/accessor-pairs) | warn | getter和setter没有成对出现时给出警告 | 13 | | [array-callback-return](https://eslint.org/docs/rules/array-callback-return) | error | 对于数据相关操作函数比如reduce, map, filter等,callback必须有return | 14 | | [block-scoped-var](https://eslint.org/docs/rules/block-scoped-var) | error | 把var关键字看成块级作用域,防止变量提升导致的bug | 15 | | [class-methods-use-this](https://eslint.org/docs/rules/class-methods-use-this) | error | 要求在Class里面合理使用this,如果某个方法没有使用this,则应该申明为静态方法 | 16 | | [complexity](https://eslint.org/docs/rules/complexity) | off | 关闭代码复杂度限制 | 17 | | [default-case](https://eslint.org/docs/rules/default-case) | error | switch case语句里面一定需要default分支 | 18 | | [no-alert](https://eslint.org/docs/rules/no-alert) | warn | 代码中使用了alert给出警告 | 19 | | [no-empty-function](https://eslint.org/docs/rules/no-empty-function) | error | 不允许使用空函数,除非在空函数里面给出注释说明 | 20 | | [no-eq-null](https://eslint.org/docs/rules/no-eq-null)| off | foo == null 用于判断 foo 不是 undefined 并且不是 null,比较常用,故允许此写法| 21 | | [no-eval](https://eslint.org/docs/rules/no-eval)| error | 代码中不允许使用eval | 22 | | [no-extend-native](https://eslint.org/docs/rules/no-extend-native) | error | 禁止修改原生对象 | 23 | | [no-extra-bind](https://eslint.org/docs/rules/no-extra-bind) | error | 禁止出现没必要的 bind | 24 | | [no-floating-decimal](https://eslint.org/docs/rules/no-floating-decimal) | error | 表示小数时,禁止省略 0,比如 .5 | 25 | | [no-implicit-coercion](https://eslint.org/docs/rules/no-implicit-coercion) | off | 允许这些写法,性能上更好 | 26 | | [no-implicit-globals](https://eslint.org/docs/rules/no-implicit-globals) | error | 浏览器端不允许定义全局变量和全局函数,可以通过挂载到window对象上和使用IIFE表达式 | 27 | | [no-invalid-this](https://eslint.org/docs/rules/no-invalid-this) | off | this的使用比较灵活 | 28 | | [no-iterator](https://eslint.org/docs/rules/no-iterator) | error | 禁止使用 __iterator__ | 29 | | [no-lone-blocks](https://eslint.org/docs/rules/no-lone-blocks) | error | 禁止使用没必要的 {} 作为代码块 | 30 | | [no-magic-numbers](https://eslint.org/docs/rules/no-magic-numbers) | error | 允许代码里面使用魔法数(多次使用,没有使用枚举的方式进行定义的数字) | 31 | | [no-multi-spaces](https://eslint.org/docs/rules/no-multi-spaces) | error | 禁止出现连续的多个空格,除非是注释前,或对齐对象的属性、变量定义、import 等 | 32 | | [no-multi-str](https://eslint.org/docs/rules/no-multi-str) | error | 禁止使用/来进行字符串换行 | 33 | | [no-new](https://eslint.org/docs/rules/no-new) | error | 禁止直接 new 一个类而不赋值 | 34 | | [no-new-func](https://eslint.org/docs/rules/no-new-func) | error | 禁止使用 new Function,比如 const expression = new Function("a", "b", "return a + b"); | 35 | | [no-new-wrappers](https://eslint.org/docs/rules/no-new-wrappers) | error | 对于JS的原始类型比如String, Number, Boolean等,不允许使用new 操作符 | 36 | | [no-octal-escape](https://eslint.org/docs/rules/no-octal-escape) | error | 禁止使用八进制的转义符比如 "Copyright \251" | 37 | | [no-param-reassign](https://eslint.org/docs/rules/no-param-reassign) | error |禁止对函数的参数重新赋值 | 38 | | [no-proto](https://eslint.org/docs/rules/no-proto) | error | 禁止直接使用__proto__属性,可以使用getPrototypeOf替代 | 39 | | [no-return-assign](https://eslint.org/docs/rules/no-return-assign) | error | return语句中禁止进行赋值语句操作 | 40 | | [no-return-await](https://eslint.org/docs/rules/no-return-await) | error | 禁止在 return 语句里使用 await | 41 | | [no-script-url](https://eslint.org/docs/rules/no-script-url) | error | 允许location.href = 'javascript:void(0)'的形式 | 42 | | [no-throw-literal](https://eslint.org/docs/rules/no-throw-literal) | error | 禁止throw一个字面量,比如 throw 2, throw "error"; | 43 | | [no-useless-call](https://eslint.org/docs/rules/no-useless-call) | error | 禁止出现没必要的 call 或 apply | 44 | | [no-useless-concat](https://eslint.org/docs/rules/no-useless-concat) | error | 禁止出现没必要的字符串拼接,比如 'hello' + 'world',可以直接写成'hello world' | 45 | | [no-useless-return](https://eslint.org/docs/rules/no-useless-return) | off | 对return的使用不进行限制 | 46 | | [no-void](https://eslint.org/docs/rules/no-void) | error | 禁止在代码里面出现void | 47 | | [no-warning-comments](https://eslint.org/docs/rules/no-warning-comments) | off | TODO 和 FIXME 类型的注释用的比较多,不限制 | 48 | | [no-with](https://eslint.org/docs/rules/no-with) | error | 代码里面禁止使用 with 表达式 | 49 | | [prefer-promise-reject-errors](https://eslint.org/docs/rules/prefer-promise-reject-errors) | error | Promise 的 reject方法必须传入 Error 对象,而不能是字面量 | 50 | | [radix](https://eslint.org/docs/rules/radix) | error | parseInt的时候第二个参数可以不传入,默认就是10进制 | 51 | | [require-await](https://eslint.org/docs/rules/require-await) | error | async函数里面必须有await | 52 | | [vars-on-top](https://eslint.org/docs/rules/vars-on-top) | error | var变量定义没必要限制太严格 | 53 | | [init-declarations](https://eslint.org/docs/rules/init-declarations) | off | 变量定义时强制赋值或者强制先定义后赋值有点严格 | 54 | | [no-label-var](https://eslint.org/docs/rules/no-label-var) | error | 禁止label名称和var相同 | 55 | | [no-undefined](https://eslint.org/docs/rules/no-undefined) | error | 进制将undefined当成标志符 | 56 | | [no-use-before-define](https://eslint.org/docs/rules/no-use-before-define) | error | 变量使用之前必须进行定义 | 57 | | [no-undef](https://eslint.org/docs/rules/no-undef) | error | 禁止使用未定义的变量, typeof 后面的变量除外 | 58 | | [array-bracket-newline](https://eslint.org/docs/rules/array-bracket-newline) | off | 数组前后括号必须换行的要求有点严格,不采纳 | 59 | | [array-bracket-spacing](https://eslint.org/docs/rules/array-bracket-spacing) | error | 数组的括号前后禁止有空格 | 60 | | [array-element-newline](https://eslint.org/docs/rules/array-element-newline) | off | 数组里面的元素强制换行有点严格,不采纳 | 61 | | [block-spacing](https://eslint.org/docs/rules/block-spacing) | off | 代码块如果在一行,则大括号内的首尾必须有空格,比如 function (a, b) { retur a + b; } | 62 | | [brace-style](https://eslint.org/docs/rules/brace-style) | error | 大括号的用法要求 | 63 | | [camelcase](https://eslint.org/docs/rules/camelcase) | error | 变量命名需要以驼峰命名法,对属性字段不做限制 | 64 | | [capitalized-comments](https://eslint.org/docs/rules/capitalized-comments) | off | 注释的首字母必须大写,对此不做限制 | 65 | | [comma-dangle](https://eslint.org/docs/rules/comma-dangle) | error | 默认不允许尾随逗号, ie8及以下浏览器会报错 | 66 | | [comma-spacing](https://eslint.org/docs/rules/comma-spacing) | error | 逗号后面强制要求加空格 | 67 | | [comma-style](https://eslint.org/docs/rules/comma-style) | error | 逗号必须写在最后面 | 68 | | [func-call-spacing](https://eslint.org/docs/rules/func-call-spacing) | error | 函数名和执行它的括号之间禁止有空格 | 69 | | [func-name-matching](https://eslint.org/docs/rules/func-name-matching) | error | 函数赋值给变量时,函数名必须和赋值的变量名一致的限制不采纳 | 70 | | [func-names](https://eslint.org/docs/rules/func-names) | off | 不限制匿名函数的命名问题 | 71 | | [func-style](https://eslint.org/docs/rules/func-style) | off | 必须只使用函数申明或只使用函数表达式 | 72 | | [id-blacklist](https://eslint.org/docs/rules/id-blacklist) | off | 变量黑名单,不采纳 | 73 | | [id-length](https://eslint.org/docs/rules/id-length) | off | 变量命名长度不做限制 | 74 | | [id-match](https://eslint.org/docs/rules/id-match) | off | 变量命令的字符需要在某个正则匹配规则里面,不采纳 | 75 | | [indent](https://eslint.org/docs/rules/indent) | error | 一个缩进必须用四个空格替代, switch语句里面的case 2个空格 | 76 | | [jsx-quotes](https://eslint.org/docs/rules/jsx-quotes) | error | jsx 中的属性必须用双引号 | 77 | | [key-spacing](https://eslint.org/docs/rules/key-spacing) | error | 对象字面量中冒号前面禁止有空格,后面必须有空格 | 78 | | [keyword-spacing](https://eslint.org/docs/rules/keyword-spacing) | error | 关键字前后必须要加上空格 | 79 | | [line-comment-position](https://eslint.org/docs/rules/line-comment-position) | off | 注释的位置不进行限制 | 80 | | [linebreak-style](https://eslint.org/docs/rules/linebreak-style) | off | 对换行符不限制 | 81 | | [lines-around-comment](https://eslint.org/docs/rules/lines-around-comment) | off | 注释前后必须有空行的限制,不采纳 | 82 | | [max-depth](https://eslint.org/docs/rules/max-depth) | error | 代码块嵌套的深度禁止超过 5 层 | 83 | | [max-len](https://eslint.org/docs/rules/max-len) | error | 单行最多允许80个字符, 对包含url的行不进行此限制 | 84 | | [max-lines](https://eslint.org/docs/rules/max-lines) | off | 某个文件能够放置的最大代码行数,不限制 | 85 | | [max-nested-callbacks](https://eslint.org/docs/rules/max-nested-callbacks) | error | 回调函数嵌套禁止超过 3 层,多了请用 async await 替代 | 86 | | [max-params](https://eslint.org/docs/rules/max-params) | error | 函数的参数禁止超过 10 个 | 87 | | [max-statements](https://eslint.org/docs/rules/max-statements) | off | 一个函数块里面的语句行数的限制,不采纳 | 88 | | [max-statements-per-line](https://eslint.org/docs/rules/max-statements-per-line) | off | 一行中的语句数量 | 89 | | [multiline-ternary](https://eslint.org/docs/rules/multiline-ternary) | off | 三目元算语句换行限制,不采纳 | 90 | | [new-cap](https://eslint.org/docs/rules/new-cap) | error | 构造函数的必须以大写字母开头 | 91 | | [new-parens](https://eslint.org/docs/rules/new-parens) | error | new 后面类必须带上括号 | 92 | | [newline-per-chained-call](https://eslint.org/docs/rules/newline-per-chained-call) | off | 链式调用必须换行的限制,不采纳 | 93 | | [no-array-constructor](https://eslint.org/docs/rules/no-array-constructor) | error | 禁止使用 Array 构造函数 | 94 | | [no-bitwise](https://eslint.org/docs/rules/no-bitwise) | off | 位操作,不进行限制 | 95 | | [no-continue](https://eslint.org/docs/rules/no-continue) | off | continue语句的使用,不限制 | 96 | | [no-inline-comments](https://eslint.org/docs/rules/no-inline-comments) | off | 内联注释不限制 | 97 | | [no-lonely-if](https://eslint.org/docs/rules/no-lonely-if) | off | 允许单独使用if语句,而不配套使用else、else if等 | 98 | | [no-mixed-spaces-and-tabs](https://eslint.org/docs/rules/no-mixed-spaces-and-tabs) | error | 禁止混用空格和缩进 | 99 | | [no-multi-assign](https://eslint.org/docs/rules/no-multi-assign) | off | 连续赋值比如 a = b = c = 4; 不限制 | 100 | | [no-multiple-empty-lines](https://eslint.org/docs/rules/no-multiple-empty-lines) | off | 连续空行,不限制 | 101 | | [no-negated-condition](https://eslint.org/docs/rules/no-negated-condition) | off | if里面不允许出现否定表达式, 不采纳 | 102 | | [no-nested-ternary](https://eslint.org/docs/rules/no-nested-ternary) | off | 允许三元表达式的嵌套使用 | 103 | | [no-new-object](https://eslint.org/docs/rules/no-new-object) | error | 禁止直接 new Object | 104 | | [no-plusplus](https://eslint.org/docs/rules/no-plusplus) | off | 允许使用 ++ 或 -- | 105 | | [no-ternary](https://eslint.org/docs/rules/no-ternary) | off | 允许使用三元表达式 | 106 | | [no-trailing-spaces](https://eslint.org/docs/rules/no-trailing-spaces) | error | 禁止行尾部有空格 | 107 | | [no-underscore-dangle](https://eslint.org/docs/rules/no-underscore-dangle) | off | 允许变量名中出现下划线 | 108 | | [no-whitespace-before-property](https://eslint.org/docs/rules/no-whitespace-before-property) | error | 禁止属性前有空格,比如 foo. bar() | 109 | | [object-curly-newline](https://eslint.org/docs/rules/object-curly-newline) | error | 大括号内的首尾必须有换行 | 110 | | [object-property-newline](https://eslint.org/docs/rules/object-curly-spacing) | off | 对象字面量内的属性每行必须只有一个,不采纳 | 111 | | [one-var](https://eslint.org/docs/rules/one-var) | error | 声明变量时,禁止一条语句声明多个变量 | 112 | | [one-var-declaration-per-line](https://eslint.org/docs/rules/one-var-declaration-per-line) | error | 变量申明必须每行一个 | 113 | | [quotes](https://eslint.org/docs/rules/quotes) | error | 必须使用单引号 | 114 | | [semi](https://eslint.org/docs/rules/semi) | error | 结尾必须有分号 | 115 | | [semi-spacing](https://eslint.org/docs/rules/semi-spacing) | error | 一行有多个语句时,分号前面禁止有空格,分号后面必须有空格 | 116 | | [semi-style](https://eslint.org/docs/rules/semi-style) | error | 分号必须写在行尾,禁止在行首出现 | 117 | | [space-before-blocks](https://eslint.org/docs/rules/space-before-blocks) | error | if, function 等的大括号之前必须要有空格 | 118 | | [space-before-function-paren](https://eslint.org/docs/rules/space-before-function-paren) | error | function 的小括号前面必须有空格 | 119 | | [space-in-parens](https://eslint.org/docs/rules/space-in-parens) | error | 小括号内的首尾禁止有空格 | 120 | | [space-infix-ops](https://eslint.org/docs/rules/space-infix-ops) | error | 操作符左右必须有空格, const ret = 'hello' + 'world'| 121 | | [spaced-comment](https://eslint.org/docs/rules/spaced-comment) | off | 注释空格不限制 | 122 | | [switch-colon-spacing](https://eslint.org/docs/rules/switch-colon-spacing) | error | case 子句冒号前禁止有空格,冒号后必须有空格 | 123 | | [arrow-body-style](https://eslint.org/docs/rules/arrow-body-style) | off | 箭头函数返回值可以只是一个值,没必须一定用大括号写成多条语句. | 124 | | [arrow-parens](https://eslint.org/docs/rules/arrow-parens) | off | 箭头函数的参数必须用括号包裹起来,限制去掉。当只有一个参数时,没必要使用括号 | 125 | | [arrow-spacing](https://eslint.org/docs/rules/arrow-spacing) | error | 箭头函数的箭头前后必须有空格 | 126 | | [generator-star-spacing](https://eslint.org/docs/rules/generator-star-spacing) | error | generator 的 * 前面禁止有空格,后面必须有空格 | 127 | | [no-duplicate-imports](https://eslint.org/docs/rules/no-duplicate-imports) | error | 禁止import重复模块 | 128 | | [no-var](https://eslint.org/docs/rules/no-var) | error | 禁止采用var去定义变量,必须使用let或者const | 129 | | [prefer-arrow-callback](https://eslint.org/docs/rules/prefer-arrow-callback) | off | 禁止采用var去定义变量,必须使用let或者const | 130 | | [prefer-const](https://eslint.org/docs/rules/prefer-const) | error | 变量如果没有发生修改,则必须使用const进行命名 | 131 | | [prefer-destructuring](https://eslint.org/docs/rules/prefer-destructuring) | off | 强制使用结构的限制,不采纳 | 132 | | [prefer-template](https://eslint.org/docs/rules/prefer-template) | off | 不强制使用模板字符串,字符串拼接也是可取的 | 133 | | [rest-spread-spacing](https://eslint.org/docs/rules/rest-spread-spacing) | error | ... 的后面禁止有空格 | 134 | | [sort-imports](https://eslint.org/docs/rules/sort-imports) | off | import 排序不用限制| 135 | | [template-curly-spacing](https://eslint.org/docs/rules/template-curly-spacing) | error | 模板字符串内的首尾禁止有空格,比如${test}不要写成${ test } | 136 | | [yield-star-spacing](https://eslint.org/docs/rules/yield-star-spacing) | error | yield* 后面必须加空格 | 137 | --------------------------------------------------------------------------------