-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
210 lines (194 loc) · 6.08 KB
/
Copy patheslint.config.js
File metadata and controls
210 lines (194 loc) · 6.08 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import js from "@eslint/js";
import globals from "globals";
import reactPlugin from "eslint-plugin-react";
import reactHooksPlugin from "eslint-plugin-react-hooks";
import jsxA11yPlugin from "eslint-plugin-jsx-a11y";
import importPlugin from "eslint-plugin-import";
import promisePlugin from "eslint-plugin-promise";
import unicornPlugin from "eslint-plugin-unicorn";
import eslintConfigPrettier from "eslint-config-prettier";
const webFiles = ["web/**/*.{js,jsx}"];
export default [
{
ignores: [
"**/dist/**",
"**/node_modules/**",
"**/.build/**"
]
},
js.configs.recommended,
{
files: webFiles,
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
parserOptions: {
ecmaFeatures: {
jsx: true
}
},
globals: {
...globals.browser
}
},
plugins: {
react: reactPlugin,
"react-hooks": reactHooksPlugin,
"jsx-a11y": jsxA11yPlugin,
import: importPlugin,
promise: promisePlugin,
unicorn: unicornPlugin
},
settings: {
react: {
version: "detect"
},
"import/resolver": {
node: {
extensions: [".js", ".jsx"]
}
}
},
rules: {
// 已有推荐规则
...reactPlugin.configs.recommended.rules,
...reactPlugin.configs["jsx-runtime"].rules,
...reactHooksPlugin.configs.recommended.rules,
...jsxA11yPlugin.flatConfigs.recommended.rules,
// ----------------------------
// 1) 基础正确性 / 安全 / 坏味道
// ----------------------------
"no-console": ["warn", { allow: ["warn", "error"] }],
"no-debugger": "error",
"no-alert": "error",
"no-caller": "error",
"eqeqeq": ["error", "smart"],
"curly": ["error", "all"],
"consistent-return": "error",
"default-case-last": "error",
"dot-notation": "error",
"no-implicit-coercion": "warn",
"no-lonely-if": "warn",
"no-nested-ternary": "warn",
"no-shadow": "warn",
"no-unneeded-ternary": "warn",
"no-param-reassign": ["warn", { props: false }],
"object-shorthand": ["warn", "always"],
"prefer-arrow-callback": ["warn", { allowNamedFunctions: false, allowUnboundThis: true }],
"prefer-const": ["error", { destructuring: "all" }],
"prefer-destructuring": ["warn", { object: true, array: false }],
"prefer-template": "warn",
"no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
ignoreRestSiblings: true
}
],
// ----------------------------
// 2) 复杂度 / 规模约束
// ----------------------------
// cyclop / cyclomatic 对应的核心就是 complexity
"complexity": ["warn", 10],
"max-depth": ["warn", 4],
"max-lines": [
"warn",
{
max: 500,
skipBlankLines: true,
skipComments: true
}
],
"max-lines-per-function": [
"warn",
{
max: 80,
skipBlankLines: true,
skipComments: true
}
],
"max-nested-callbacks": ["warn", 3],
"max-params": ["warn", 4],
"max-statements": ["warn", 20],
// ----------------------------
// 3) import 规范
// ----------------------------
"import/first": "error",
"import/newline-after-import": ["warn", { count: 1 }],
"import/no-absolute-path": "error",
"import/no-cycle": "warn",
"import/no-duplicates": "error",
"import/no-mutable-exports": "error",
"import/no-named-as-default": "warn",
"import/no-unresolved": "error",
"import/order": [
"warn",
{
groups: [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
"object",
"type"
],
"newlines-between": "always",
alphabetize: {
order: "asc",
caseInsensitive: true
}
}
],
// ----------------------------
// 4) Promise / async 最佳实践
// ----------------------------
"promise/always-return": "error",
"promise/catch-or-return": "error",
"promise/no-callback-in-promise": "warn",
"promise/no-multiple-resolved": "error",
"promise/no-nesting": "warn",
"promise/no-new-statics": "error",
"promise/no-promise-in-callback": "warn",
"promise/no-return-in-finally": "error",
"promise/no-return-wrap": "error",
"promise/param-names": "error",
"promise/prefer-await-to-then": "warn",
"promise/valid-params": "error",
// ----------------------------
// 5) React / JSX 编码习惯
// ----------------------------
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"react/jsx-no-target-blank": "error",
"react/button-has-type": "warn",
"react/self-closing-comp": "warn",
"react/jsx-boolean-value": ["warn", "never"],
"react/jsx-fragments": ["warn", "syntax"],
"react/jsx-no-useless-fragment": "warn",
"react/no-array-index-key": "warn",
"react-hooks/exhaustive-deps": "warn",
// ----------------------------
// 6) 现代 JS 习惯(高价值精选)
// ----------------------------
"unicorn/consistent-function-scoping": "warn",
"unicorn/error-message": "error",
"unicorn/no-array-for-each": "warn",
"unicorn/no-instanceof-array": "error",
"unicorn/no-useless-undefined": "warn",
"unicorn/prefer-add-event-listener": "warn",
"unicorn/prefer-array-find": "warn",
"unicorn/prefer-dom-node-append": "warn",
"unicorn/prefer-modern-dom-apis": "warn",
"unicorn/prefer-optional-catch-binding": "warn",
"unicorn/prefer-string-replace-all": "warn",
"unicorn/prefer-string-slice": "warn",
"unicorn/prevent-abbreviations": "off",
"unicorn/throw-new-error": "error"
}
},
// 必须放最后,关闭和 Prettier 冲突的格式类规则
eslintConfigPrettier
];