-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.eslintrc.js
93 lines (93 loc) · 2.5 KB
/
.eslintrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
module.exports = {
env: {
es6: true,
node: true,
commonjs: true,
},
// 启用TypeScript插件
plugins: [
'react',
'@typescript-eslint'
],
parser: '@typescript-eslint/parser',
extends: [
'airbnb-base',
// 启用react的规则
'plugin:react/recommended',
// 启用typescript的规则
'plugin:@typescript-eslint/recommended',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 2018, // ES的版本
// 支持JSX语法
ecmaFeatures: {
jsx: true,
},
},
env: {
browser: true, // 是否启用浏览器全局变量
jquery: true, // 是否启用jquery
},
globals: {
CodeMirror: false,
},
settings: {
'import/resolver': {
node: { // 限制node端的import
extensions: ['.js', '.ts']
},
webpack: { // 限制webpack方式的import,主要用于解决tsx的问题,需要引入eslint-import-resolver-webpack
config: './webpack.config.js',
},
}
},
rules: {
'indent': ['error', 4, {
'SwitchCase': 1
}],
'no-console': ['error', {
'allow': ['log', 'error']
}],
'no-underscore-dangle': ['error', {
'allowAfterThis': true
}],
'no-unused-expressions': ['error', {
'allowShortCircuit': true
}],
'spaced-comment': ['error', 'always', {
'exceptions': ['*']
}],
'no-await-in-loop': 'off',
'no-use-before-define': ['error', 'nofunc'],
'class-methods-use-this': ['error', {
'exceptMethods': [
'render',
'getInitialState',
'getDefaultProps',
'getChildContext',
'componentWillMount',
'componentDidMount',
'componentWillReceiveProps',
'shouldComponentUpdate',
'componentWillUpdate',
'componentDidUpdate',
'componentWillUnmount',
],
}],
// 解决airbnb新版导致的问题
'import/extensions': [
'error',
'ignorePackages',
{
'js': 'never',
'jsx': 'never',
'ts': 'never',
'tsx': 'never'
}
]
},
};