-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.js
91 lines (91 loc) · 3.2 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
module.exports = {
// 定义ESLint的解析器
parser: '@typescript-eslint/parser',
// 定义文件继承的子规范
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
// 定义该eslint文件所依赖的插件
plugins: ['@typescript-eslint', 'react', 'prettier', 'react-hooks'],
root: true,
// 指定代码的运行环境
env: {
browser: true,
node: true,
},
settings: {
// 自动发现React的版本,从而进行规范react代码
react: {
pragma: 'React',
version: 'detect',
},
},
// 指定ESLint解析参数
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
// 指定ESLint解析规则
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
// 检查 Hook 的规则
"react-hooks/rules-of-hooks": "error",
// 检查 effect 的依赖
"react-hooks/exhaustive-deps": "warn",
// 允许使用any类型
'@typescript-eslint/no-explicit-any': 0,
// 允许使用require
'@typescript-eslint/no-var-requires': 0,
// 不允许出现debugger语句
'no-debugger': 2,
// 函数定义的时候不允许出现重复的参数
'no-dupe-args': 2,
// 对象中不允许出现重复的键
'no-dupe-keys': 2,
// switch语句中不允许出现重复的case标签
'no-duplicate-case': 2,
// 不允许出现空的代码块
'no-empty': 2,
// 在return,throw,continue,break语句后不允许出现不可能到达的语句
'no-unreachable': 2,
// 比较的时候使用严格等于
eqeqeq: ['error', 'always'],
// 不允许使用eval()
'no-eval': 2,
// 不允许使用隐式eval()
'no-implied-eval': 2,
// 不允许不必要的嵌套代码块
'no-lone-blocks': 2,
// 不允许在循环语句中进行函数声明
'no-loop-func': 2,
// 不允许变量重复声明
'no-redeclare': 2,
// 不允许抛出字面量错误 throw "error"
'no-throw-literal': 2,
// js关键字和保留字不能作为函数名或者变量名
'no-shadow-restricted-names': 2,
// 不允许未声明的变量
'no-undef': 2,
// 强制驼峰命名规则
camelcase: [2, { properties: 'never' }],
'prefer-const': 1,
// 使用let和const代替var
'no-var': 2,
//不允许在嵌套代码块里声明函数
'no-inner-declarations': [2, 'functions'],
// 推荐使用es6结构语法赋值
'prefer-destructuring': ['error', { array: true, object: true }],
// 在构造函数中需要`super()`调用
'constructor-super': 1,
// //或/*后面必须至少有一个空格
'spaced-comment': [1, 'always'],
},
};