Skip to content

Commit 2ca8400

Browse files
committed
eslint 配置
1 parent bac8aa2 commit 2ca8400

File tree

10 files changed

+192
-176
lines changed

10 files changed

+192
-176
lines changed

.eslintrc

Lines changed: 0 additions & 43 deletions
This file was deleted.

.eslintrc.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
// JS 书写规范
3+
// http://eslint.org
4+
// http://standardjs.com/rules.html
5+
//
6+
// @dependencies 安装到全局,就不用每个项目单独安装了
7+
// npm install -g eslint eslint-plugin-import
8+
// standard: npm install -g eslint-config-standard eslint-plugin-standard eslint-plugin-promise
9+
// airbnb: npm install -g eslint-plugin-react eslint-plugin-jsx-a11y eslint-plugin-airbnb
10+
11+
// NOTE: 在新项目中使用 error 级别,在老项目中使用 warning 级别
12+
13+
module.exports = {
14+
root: true,
15+
parser: 'babel-eslint',
16+
installedESLint: true,
17+
parserOptions: {
18+
ecmaVersion: 6,
19+
sourceType: 'module',
20+
},
21+
globals: {
22+
Vue: false,
23+
},
24+
25+
plugins: [
26+
'html',
27+
],
28+
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
29+
// https://github.com/feross/eslint-config-standard/blob/master/eslintrc.json
30+
// extends: 'standard',
31+
// ES6 推荐规范
32+
extends: 'airbnb',
33+
// extends: 'defaults/configurations/airbnb/es6',
34+
35+
// add your custom rules here
36+
rules: {
37+
// 行尾分号,默认配置always,要求在行末加上分号,standard 配置强制不带
38+
semi: ['error', "never"],
39+
// 多行模式必须带逗号,单行模式不能带逗号
40+
'comma-dangle': ['error', 'always-multiline'],
41+
// "max-len": ['error', 120],
42+
// 禁止使用 console debugger
43+
// 'no-console': 1,
44+
// 'no-debugger': 1,
45+
},
46+
}

docs/.eslintignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
node_modules/*
1+
# /node_modules/* and /bower_components/* ignored by default
2+
3+
# Ignore built files except build/index.js
4+
build/*
5+
!build/build-test.js
6+
27
**/vendor/*.js
38
dist/

docs/.eslintrc

Lines changed: 0 additions & 43 deletions
This file was deleted.

docs/config-eslint.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
# 配置使用
3+
4+
拷贝 [.eslintrc.js](../.eslintrc.js) 到项目根目录
5+
6+
> 为什么选用 `.eslintrc.js` 后缀名?因为 `.json` 没法加注释,格式要求比较严格,而 `.eslintrc` 格式在 vscode 中默认做 json 处理了,其中的注释 # 就显示为了异常,所以统一使用 js 格式,通用了
7+
8+
## 项目配置,安装 ESLint 依赖
9+
10+
可以安装到全局,全部共用
11+
12+
```
13+
// ES6 推荐使用 airbnb
14+
npm install -g eslint eslint-plugin-import eslint-plugin-react eslint-plugin-jsx-a11y eslint-plugin-airbnb
15+
16+
// 如果使用 standardjs(仅仅涉及 ES5)
17+
npm install -g eslint-config-standard eslint-plugin-standard eslint-plugin-promise
18+
```
19+
20+
21+
## 编辑器配置
22+
23+
### Atom
24+
25+
```
26+
编辑器要安装 linter-eslint 插件
27+
配置 .eslintrc filePath 为 .eslintrc.js
28+
勾选选项 Use global ESLint installation
29+
```
30+
31+
### VSCode
32+
33+
```
34+
编辑器要安装 eslint 插件
35+
编辑器增加全局配置
36+
"eslint.options": {
37+
"configFile": "./.eslintrc.js"
38+
},
39+
```

docs/es5.eslintrc

Lines changed: 0 additions & 43 deletions
This file was deleted.

docs/es5.eslintrc.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
// JS 书写规范
3+
// http://eslint.org
4+
// http://standardjs.com/rules.html
5+
//
6+
// @dependencies 安装到全局,就不用每个项目单独安装了
7+
// standard: npm install -g eslint-config-standard eslint-plugin-standard eslint-plugin-promise
8+
// airbnb: npm install -g eslint eslint-plugin-import eslint-plugin-react eslint-plugin-jsx-a11y eslint-plugin-airbnb
9+
10+
// NOTE: 在新项目中使用 error 级别,在老项目中使用 warning 级别
11+
12+
module.exports = {
13+
root: true,
14+
parser: 'babel-eslint',
15+
parserOptions: {
16+
ecmaVersion: 6,
17+
sourceType: 'module',
18+
},
19+
globals: {
20+
Vue: false,
21+
},
22+
23+
plugins: [
24+
'html',
25+
],
26+
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
27+
// https://github.com/feross/eslint-config-standard/blob/master/eslintrc.json
28+
// extends: 'standard',
29+
// ES5 推荐规范
30+
// extends: 'airbnb',
31+
extends: 'defaults/configurations/airbnb/es5',
32+
33+
// add your custom rules here
34+
rules: {
35+
// 行尾分号,默认配置always,要求在行末加上分号,standard 配置强制不带
36+
semi: ['error', 'never'],
37+
// 多行模式必须带逗号,单行模式不能带逗号
38+
'comma-dangle': ['error', 'always-multiline'],
39+
// 禁止使用 console debugger
40+
// 'no-console': 1,
41+
// 'no-debugger': 1,
42+
},
43+
}

docs/es6.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// ES6 代码规范练习场
33

44
// 为便于测试,关闭部分规则检测
5-
/* eslint no-unused-vars: 0 */
5+
/* eslint no-unused-vars: 0, no-console: 0, prefer-const: 0, */
66

77
// [类型](#types)
88
// 使用 let const 替代 var

docs/es6_zh-cn_v3.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,7 @@ NOTE: 本文对[Airbnb JavaScript Style Guide](https://github.com/airbnb/javascr
2828

2929
## Usage
3030

31-
```
32-
# 安装依赖到全局,就不用每个项目单独安装了
33-
# standard: npm install -g eslint-config-standard eslint-plugin-standard eslint-plugin-promise
34-
# airbnb: npm install -g eslint eslint-plugin-import eslint-plugin-react eslint-plugin-jsx-a11y eslint-plugin-airbnb
35-
36-
# 最新项目推荐使用 airbnb,目前稍有改动,[ES6 规则配置 .eslintrc](.eslintrc)
37-
38-
# 老旧项目,可以使用 [ES5 规则配置 .eslintrc](es5.eslintrc)
39-
40-
# 将 ES6配置 放置在项目根目录,如果有老旧项目同时维护,可以将 ES5配置 放在全局。
41-
```
31+
参见[config-eslint](./config-eslint.md)
4232

4333
NOTE: 使用规范最好的方式,就是配置好,直接用,然后各种问题就出来了
4434

0 commit comments

Comments
 (0)