-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path.eslintrc.js
163 lines (161 loc) · 4.67 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
parser: '@typescript-eslint/parser',
extends: [
"plugin:@typescript-eslint/eslint-recommended", // eslint 处理typescript格式
"plugin:@typescript-eslint/recommended",
'plugin:react/recommended', // eslint处理react代码格式 https://github.com/yannickcr/eslint-plugin-react
'plugin:import/errors', // https://www.npmjs.com/package/eslint-plugin-import
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:prettier/recommended',
'prettier/@typescript-eslint', // 如果eslint和prettier有冲突,以prettier为主
],
plugins: ['@typescript-eslint', 'react', 'react-hooks'],
settings: { // 自动发现react版本
react: {
version: "detect"
},
'import/resolver': {
node: {
paths: ['src'],
extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts']
}
}
},
parserOptions: { // 指定eslint可以解析的jsx语法
ecmaVersion: 2019,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
// https://github.com/typescript-eslint/typescript-eslint/issues/46#issuecomment-470486034
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/no-unused-vars': [1, { args: 'none', "argsIgnorePattern": "^_" }],
'no-unused-expressions': 'off',
},
},
{
files: ['*.ts'],
rules: {
"@typescript-eslint/explicit-module-boundary-types": 0 // 函数的返回值类型一定要写 only ts
},
},
{
files: ['*.md'], // md检测
globals: {
React: true,
ReactDOM: true,
mountNode: true,
},
rules: {
'indent':0,
'no-console': 0,
'no-plusplus': 0,
'eol-last': 0,
'no-script-url': 0,
'prefer-rest-params': 0,
'react/no-access-state-in-setstate': 0,
'react/destructuring-assignment': 0,
'react/no-multi-comp': 0,
'import/no-extraneous-dependencies': 0,
},
},
],
rules: {
// 关闭对于jsx扩展名的检测
'react/jsx-filename-extension': 0,
'react/jsx-one-expression-per-line': 0,
'react/prop-types': 0,
'react/forbid-prop-types': 0,
'react/jsx-indent': 0,
'react/jsx-wrap-multilines': ['error', { declaration: false, assignment: false }],
'react/state-in-constructor': 0,
'react/jsx-props-no-spreading': 0,
'react/destructuring-assignment': 0, // TODO: remove later
'react/require-default-props': 0,
'react/sort-comp': 0,
'react/display-name': 0,
'react/static-property-placement': 0,
'react/no-find-dom-node': 0,
'react/no-unused-prop-types': 0,
'react/default-props-match-prop-types': 0,
'react-hooks/rules-of-hooks': 2, // Checks rules of Hooks
'react-hooks/exhaustive-deps': [1, { enableDangerousAutofixThisMayCauseInfiniteLoops: true }],
'@typescript-eslint/no-explicit-any': 0, // close use any typess
'import/extensions': 0,
'import/no-cycle': 0,
'import/order': ['error', { // 排序import引入顺序
'pathGroups': [
{
"pattern": "~/**",
"group": "external"
},
{
"pattern": "@/**",
"group": "external",
"position": "after"
},
{
pattern: '.\/*.scss',
group: 'object',
},
]
}],
"import/no-unresolved": [
2,
{
"ignore": ["^@/"] // @ 是设置的路径别名
},
],
// https://github.com/typescript-eslint/typescript-eslint/issues/2540#issuecomment-692866111
'no-use-before-define': 0,
'@typescript-eslint/no-use-before-define': 2,
'no-shadow': 0,
'@typescript-eslint/no-shadow': [2, { ignoreTypeValueShadow: true }],
// https://github.com/typescript-eslint/typescript-eslint/issues/2528#issuecomment-689369395
'no-undef': 0,
"@typescript-eslint/explicit-module-boundary-types": "off",
'@typescript-eslint/no-empty-function': 0, // 关闭ts空方法检测
'import/order': [
'warn',
{
pathGroups: [
{
pattern: '~/**',
group: 'external',
},
{
pattern: '@/**',
patternOptions: {
nocomment: false,
},
group: 'external',
position: 'after',
},
{
pattern: './*.scss',
group: 'object',
},
{
pattern: './*.less',
group: 'object',
},
{
pattern: './*.css',
group: 'object',
},
],
pathGroupsExcludedImportTypes: ['builtin'],
},
]
},
};