-
257 |
- 260 | {text0} 261 | 262 |
- 265 | {text1} 266 | 267 |
├── .eslintrc ├── .travis.yml ├── weapp.js ├── docs ├── .vuepress │ └── config.js ├── .deploy.sh └── README.md ├── .npmignore ├── .gitignore ├── package.json ├── LICENSE ├── README.md └── index.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./index.js" 3 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "8" 4 | - "9" 5 | - "10" 6 | - "11" 7 | 8 | install: 9 | - npm install 10 | 11 | script: 12 | - npm run lint 13 | -------------------------------------------------------------------------------- /weapp.js: -------------------------------------------------------------------------------- 1 | const config = require('./index'); 2 | 3 | config.globals = { 4 | wx: false, 5 | App: false, 6 | Page: false, 7 | getApp: false, 8 | Component: false, 9 | Behavior: false, 10 | requirePlugin: false, 11 | getCurrentPages: false, 12 | }; 13 | 14 | module.exports = config; 15 | -------------------------------------------------------------------------------- /docs/.vuepress/config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | base: '/eslint-config-imweb/', // Github Page 路径 3 | title: 'eslint-config-imweb', 4 | description: 'eslint-config-imweb 文档', 5 | themeConfig: { 6 | sidebar: [ 7 | '/', 8 | ], 9 | sidebarDepth: 2, 10 | }, 11 | markdown: { 12 | lineNumbers: true, 13 | }, 14 | } -------------------------------------------------------------------------------- /docs/.deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 确保脚本抛出遇到的错误 4 | set -e 5 | 6 | # 生成静态文件 7 | npm run docs:build 8 | 9 | # 进入生成的文件夹 10 | cd docs/.vuepress/dist 11 | 12 | # 新建 Git 仓库 13 | git init 14 | git add -A 15 | git commit -m 'deploy doc' 16 | 17 | # 发布到 Github 18 | git push -f https://github.com/imweb/eslint-config-imweb.git master:gh-pages 19 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | # Vue Press Dist 40 | 41 | /docs -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | # Vue Press Dist 40 | 41 | docs/.vuepress/dist -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-config-imweb", 3 | "version": "0.2.19", 4 | "description": "IMWeb团队eslint配置规则", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/imweb/eslint-config-imweb.git" 8 | }, 9 | "keywords": [ 10 | "eslint", 11 | "style", 12 | "imweb" 13 | ], 14 | "scripts": { 15 | "lint": "eslint *.js", 16 | "lintfix": "eslint --fix *.js", 17 | "docs:dev": "vuepress dev docs", 18 | "docs:build": "vuepress build docs", 19 | "docs:deploy": "./docs/.deploy.sh" 20 | }, 21 | "author": "IMWeb Team", 22 | "license": "MIT", 23 | "dependencies": { 24 | "eslint-config-airbnb": "^17.1.0", 25 | "eslint-plugin-babel": "^5.3.0", 26 | "eslint-plugin-import": "^2.14.0", 27 | "eslint-plugin-jsx-a11y": "^6.1.2", 28 | "eslint-plugin-react": "^7.12.1" 29 | }, 30 | "engines": { 31 | "node": ">= 6" 32 | }, 33 | "devDependencies": { 34 | "babel-eslint": "^8.2.6", 35 | "eslint": "^5.0.0", 36 | "vuepress": "^1.0.2" 37 | }, 38 | "peerDependencies": { 39 | "eslint": "^5.3.0" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 IMWeb 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # eslint-config-imweb 2 | [](http://nodejs.org/download/) 3 | [](https://travis-ci.org/imweb/eslint-config-imweb) 4 | [](https://david-dm.org/imweb/eslint-config-imweb) 5 | [](https://www.npmjs.com/package/eslint-config-imweb) 6 | 7 | IMWeb团队eslint配置规则。 8 | 9 | # 安装 10 | 安装依赖: 11 | 12 | npm i --save-dev eslint babel-eslint eslint-config-imweb 13 | 14 | 配置 `.eslintrc` : 15 | 16 | - 小程序项目: 17 | 18 | ```json 19 | { 20 | "extends": "eslint-config-imweb/weapp" 21 | } 22 | ``` 23 | 24 | - 非小程序项目 25 | 26 | ```json 27 | { 28 | "extends": "eslint-config-imweb" 29 | } 30 | ``` 31 | 32 | 配置 `package.json` 的scripts: 33 | 34 | "scripts": { 35 | "lint": "eslint *.js lib test xxx", 36 | "lintfix": "eslint --fix *.js lib test xxx" 37 | } 38 | 39 | 运行: 40 | 41 | npm run lint 42 | 43 | [文档链接](https://imweb.github.io/eslint-config-imweb/) 44 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | 'eslint-config-airbnb', 4 | ], 5 | env: { 6 | browser: true, 7 | node: true, 8 | mocha: true, 9 | jest: true, 10 | es6: true, 11 | }, 12 | parser: 'babel-eslint', 13 | parserOptions: { 14 | ecmaVersion: 6, 15 | ecmaFeatures: { 16 | jsx: true, 17 | experimentalObjectRestSpread: true, 18 | }, 19 | }, 20 | plugins: [ 21 | 'react', 22 | 'babel', 23 | ], 24 | rules: { 25 | 'arrow-parens': 0, 26 | 'function-paren-newline': [ 27 | 2, 28 | 'multiline', 29 | ], 30 | 'object-curly-newline': 0, 31 | 'space-before-function-paren': 0, 32 | curly: [ 33 | 2, 34 | 'all', 35 | ], 36 | 'no-sync': 1, 37 | 'react/no-did-mount-set-state': 0, 38 | 'react/forbid-prop-types': 0, 39 | 'jsx-a11y/no-static-element-interactions': 0, 40 | 'jsx-a11y/click-events-have-key-events': 0, 41 | 'jsx-a11y/no-noninteractive-element-to-interactive-role': 0, 42 | 'jsx-a11y/no-noninteractive-element-interactions': 0, 43 | 'jsx-a11y/mouse-events-have-key-events': 0, 44 | 'jsx-a11y/no-noninteractive-tabindex': 0, 45 | 'jsx-a11y/anchor-is-valid': 0, 46 | 'array-callback-return': 0, 47 | 'comma-dangle': ['error', { 48 | arrays: 'always-multiline', 49 | objects: 'always-multiline', 50 | imports: 'always-multiline', 51 | exports: 'always-multiline', 52 | functions: 'never', 53 | }], 54 | 'func-names': 0, 55 | 'arrow-body-style': 0, 56 | 'react/prop-types': 0, 57 | 'react/jsx-filename-extension': 0, 58 | 'react/jsx-one-expression-per-line': 0, 59 | 'react/destructuring-assignment': 0, 60 | 'import/no-unresolved': 0, 61 | 'no-param-reassign': 0, 62 | 'no-return-assign': 0, 63 | 'no-mixed-operators': [ 64 | 'error', { 65 | groups: [['&', '|', '^', '~', '<<', '>>', '>>>'], ['&&', '||']], 66 | allowSamePrecedence: true, 67 | }, 68 | ], 69 | 'max-len': [ 70 | 2, 71 | { 72 | code: 120, 73 | ignoreUrls: true, 74 | ignoreStrings: true, 75 | ignoreTemplateLiterals: true, 76 | }, 77 | ], 78 | 'consistent-return': 0, 79 | 'class-methods-use-this': 0, 80 | 'no-plusplus': 0, 81 | 'no-underscore-dangle': 0, 82 | 'no-empty': ['error', { 83 | allowEmptyCatch: true, 84 | }], 85 | 'import/no-extraneous-dependencies': [ 86 | 0, 87 | { 88 | devDependencies: [ 89 | '/src', 90 | '/test', 91 | ], 92 | peerDependencies: 0, 93 | }, 94 | ], 95 | 'prefer-const': ['error', { 96 | destructuring: 'all', 97 | }], 98 | 'prefer-destructuring': ['error', { 99 | VariableDeclarator: { 100 | array: false, 101 | object: true, 102 | }, 103 | AssignmentExpression: { 104 | array: false, 105 | object: false, 106 | }, 107 | }, { 108 | enforceForRenamedProperties: false, 109 | }], 110 | }, 111 | }; 112 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # eslint-config-imweb 文档 2 | 3 | [IMWeb](https://imweb.io/) 团队 eslint 配置规则,基于 [eslint-config-airbnb](https://www.npmjs.com/package/eslint-config-airbnb) 封装。 4 | 5 | ## 使用方法 6 | 7 | 1. 安装依赖: 8 | 9 | ``` sh 10 | npm i --save-dev eslint@5 babel-eslint eslint-config-imweb 11 | ``` 12 | 13 | 2. 配置 `.eslintrc`: 14 | 15 | - 小程序项目: 16 | 17 | ``` json 18 | { 19 | "extends": "eslint-config-imweb/weapp" 20 | } 21 | ``` 22 | 23 | - 非小程序项目 24 | 25 | ``` json 26 | { 27 | "extends": "eslint-config-imweb" 28 | } 29 | ``` 30 | 31 | 3. 配置`package.json`的scripts: 32 | 33 | ``` json 34 | { 35 | ... 36 | "scripts": { 37 | "lint": "eslint *.js lib test xxx", 38 | "lintfix": "eslint --fix *.js lib test xxx" 39 | } 40 | } 41 | ``` 42 | 43 | 4. 运行: 44 | 45 | ``` sh 46 | npm run lint 47 | ``` 48 | 49 | ## 规则说明 50 | 51 | 主要在 [eslint-config-airbnb](https://www.npmjs.com/package/eslint-config-airbnb) 的基础上,关闭了一些规则,下面会一一说明。如果有不同意的地方,欢迎提 [issue](https://github.com/imweb/eslint-config-imweb/issues) 进行讨论。 52 | 53 | ### [array-callback-return](https://eslint.org/docs/rules/array-callback-return) 54 | 55 | 要求下列数组方法的回调函数有返回值: 56 | 57 | - Array.from 58 | - Array.prototype.every 59 | - Array.prototype.filter 60 | - Array.prototype.find 61 | - Array.prototype.findIndex 62 | - Array.prototype.map 63 | - Array.prototype.reduce 64 | - Array.prototype.reduceRight 65 | - Array.prototype.some 66 | - Array.prototype.sort 67 | 68 | **规则被关闭**,*关闭原因待补充*。 69 | 70 | ### [arrow-body-style](https://eslint.org/docs/rules/arrow-body-style) 71 | 72 | 在箭头函数能够省略 return 的时候,规定写成 `() => ... ` 还是 `() => { ... }` 的形式。例如 `() => 0` 还是 `() => { return 0; }`。 73 | 74 | **规则被关闭**,可以灵活设置。 75 | 76 | ### [arrow-parens](https://eslint.org/docs/rules/arrow-parens) 77 | 78 | 箭头函数只有一个参数的时候,规定是否必须加括号。例如 `(x) => x + 1` 还是 `x => x + 1`。 79 | 80 | **规则被关闭**,可以灵活设置。 81 | 82 | ### [class-methods-use-this](https://eslint.org/docs/rules/class-methods-use-this) 83 | 84 | 当类的方法中没有使用 `this` 时,规定该方法应设为静态方法,且调用方式应该变为 `MyClass.callStaticMethod()`。例如: 85 | 86 | ``` js{2,7} 87 | class Hello { 88 | static sayHello() { 89 | console.log("Hello!"); 90 | } 91 | } 92 | 93 | Hello.sayHello(); 94 | ``` 95 | 96 | **规则被关闭**,因为若该方法将来需要使用 `this` 时,所有的调用处均需发生更改。 97 | 98 | ### [comma-dangle](https://eslint.org/docs/rules/comma-dangle) 99 | 100 | 要求对象属性、数组元素等最后一个加上末尾逗号。例如: 101 | 102 | ``` js{3,6} 103 | const x = { 104 | a = 1, 105 | b = 2, 106 | } 107 | 108 | const y = { a = 1, b = 2 }; 109 | ``` 110 | 111 | **规则被开启**,配置为多行时必须加上,单行时不应加上。 112 | 113 | ### [consistent-return](https://eslint.org/docs/rules/consistent-return) 114 | 115 | 规定函数所有的分支要么都指明返回值,要么都不指明。 116 | 117 | **规则被关闭**,因为经常会写如下代码,在判断条件不符合后直接返回 `undefined`: 118 | 119 | ``` js 120 | function doSomething(condition) { 121 | if (condition) { 122 | return; 123 | } 124 | 125 | // do something here ... 126 | return result; 127 | } 128 | ``` 129 | 130 | ### [curly](https://eslint.org/docs/rules/curly) 131 | 132 | 规定 `if`, `else`, `for`, `while` 等语句的 `{}` 均不可以被省略。例如: 133 | 134 | ``` js{1,3} 135 | if (A) { 136 | doSomething() 137 | } 138 | ``` 139 | 140 | **规则被开启**,因为若省略 `{}`,则将来该代码块添加其他语句时,容易忘记再写上 `{}`。 141 | 142 | ### [func-names](https://eslint.org/docs/rules/func-names) 143 | 144 | 规定函数必须有名字。 145 | 146 | **规则被关闭**,因为经常会写如下代码,无需函数名也可清晰表达含义: 147 | 148 | ``` js{1} 149 | Foo.prototype.bar = function() { 150 | // do something here ... 151 | }; 152 | ``` 153 | 154 | ### [function-paren-newline](https://eslint.org/docs/rules/function-paren-newline) 155 | 156 | **规定函数**参数要么均在一行,要么每行一个,例如: 157 | 158 | ``` js{1,4,5,6} 159 | function foo(a, b, c) {} 160 | 161 | function bar( 162 | a, 163 | b, 164 | c, 165 | ) 166 | ``` 167 | 168 | 规则被开启。 169 | 170 | ### [import/no-extraneous-dependencies](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md) 171 | 172 | 规定不能引入未在 `package.json` 中 `dependencies`, `devDependencies`, `optionalDependencies` or `peerDependencies` 声明的模块。 173 | 174 | **规则被开启**。 175 | 176 | ### [import/no-unresolved](https://eslint.org/docs/rules/import/no-unresolved) 177 | 178 | 规定不能引入本地找不到的模块。 179 | 180 | **规则被关闭**,因为该规则不能很好的适配 `node` 或者 `webpack` 外的模块系统,例如 `fis`。 181 | 182 | ### [jsx-a11y/anchor-is-valid](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md) 183 | 184 | 规定所有的 `` 标签链接均是有效的。 185 | 186 | **规则被关闭**,因为经常会写如下代码,把 `` 当作按钮使用: 187 | 188 | ``` jsx{2} 189 | 193 | {text} 194 | 195 | ``` 196 | 197 | ### [jsx-a11y/click-events-have-key-events](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/click-events-have-key-events.md) 198 | 199 | 规定所有绑定了 `onClick` 事件的元素,都必须绑定 `onKeyUp`, `onKeyDown`, `onKeyPress` 事件之一,例如: 200 | 201 | ``` jsx 202 |