@agilebot/eslint-config 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +9 -9
- package/README.md +17 -17
- package/dist/index.d.ts +12 -0
- package/dist/index.js +604 -0
- package/package.json +17 -17
- package/bin/eslint-agilebot +0 -2
- package/lib/cli.js +0 -49
- package/lib/configs/agilebot.js +0 -12
- package/lib/configs/cspell.js +0 -12
- package/lib/configs/deprecation.js +0 -7
- package/lib/configs/env.js +0 -10
- package/lib/configs/eslint.js +0 -23
- package/lib/configs/godaddy.js +0 -19
- package/lib/configs/import.js +0 -40
- package/lib/configs/jsdoc.js +0 -14
- package/lib/configs/lodash.js +0 -4
- package/lib/configs/prettier.js +0 -12
- package/lib/configs/promise.js +0 -10
- package/lib/configs/react.js +0 -60
- package/lib/configs/standard.js +0 -21
- package/lib/configs/ts.js +0 -77
- package/lib/configs/unicorn.js +0 -35
- package/lib/index.js +0 -56
package/LICENSE
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2024 Agilebot, Inc.
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
-
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
-
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Agilebot, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
# @agilebot/eslint-config
|
2
|
-
|
3
|
-
### Usage
|
4
|
-
|
5
|
-
```bash
|
6
|
-
npm install --save-dev eslint \
|
7
|
-
@agilebot/eslint-config \
|
8
|
-
@agilebot/eslint-plugin \
|
9
|
-
@agilebot/eslint-utils
|
10
|
-
```
|
11
|
-
|
12
|
-
```js
|
13
|
-
// .eslintrc.js
|
14
|
-
const { agilebot } = require('@agilebot/eslint-utils');
|
15
|
-
|
16
|
-
module.exports = agilebot(__dirname);
|
17
|
-
```
|
1
|
+
# @agilebot/eslint-config
|
2
|
+
|
3
|
+
### Usage
|
4
|
+
|
5
|
+
```bash
|
6
|
+
npm install --save-dev eslint \
|
7
|
+
@agilebot/eslint-config \
|
8
|
+
@agilebot/eslint-plugin \
|
9
|
+
@agilebot/eslint-utils
|
10
|
+
```
|
11
|
+
|
12
|
+
```js
|
13
|
+
// .eslintrc.js
|
14
|
+
const { agilebot } = require('@agilebot/eslint-utils');
|
15
|
+
|
16
|
+
module.exports = agilebot(__dirname);
|
17
|
+
```
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Linter } from 'eslint';
|
2
|
+
|
3
|
+
interface FactoryOptions {
|
4
|
+
devDependencies?: string[];
|
5
|
+
cspellWords?: string[];
|
6
|
+
config?: Linter.Config;
|
7
|
+
react?: boolean;
|
8
|
+
godaddy?: boolean;
|
9
|
+
}
|
10
|
+
declare function factory(root: string, options?: FactoryOptions): Linter.BaseConfig;
|
11
|
+
|
12
|
+
export { factory as agilebot };
|
package/dist/index.js
ADDED
@@ -0,0 +1,604 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
|
30
|
+
// src/index.ts
|
31
|
+
var src_exports = {};
|
32
|
+
__export(src_exports, {
|
33
|
+
agilebot: () => factory
|
34
|
+
});
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
36
|
+
|
37
|
+
// src/factory.ts
|
38
|
+
var import_node_assert = __toESM(require("assert"));
|
39
|
+
var import_eslint_utils3 = require("@agilebot/eslint-utils");
|
40
|
+
var import_fast_glob = require("fast-glob");
|
41
|
+
|
42
|
+
// src/configs/env.ts
|
43
|
+
function env() {
|
44
|
+
return {
|
45
|
+
env: {
|
46
|
+
browser: true,
|
47
|
+
node: true,
|
48
|
+
es6: true,
|
49
|
+
mocha: true,
|
50
|
+
jest: true,
|
51
|
+
jasmine: true
|
52
|
+
}
|
53
|
+
};
|
54
|
+
}
|
55
|
+
|
56
|
+
// src/configs/standard.ts
|
57
|
+
function standard() {
|
58
|
+
return {
|
59
|
+
extends: ["love"],
|
60
|
+
rules: {
|
61
|
+
"no-alert": "error",
|
62
|
+
// 避免使用同步方法
|
63
|
+
"n/no-sync": "error",
|
64
|
+
// 尽量使用fs.promises而不是fs
|
65
|
+
"n/prefer-promises/fs": "error",
|
66
|
+
"arrow-body-style": "off",
|
67
|
+
curly: "error",
|
68
|
+
// 找出TODO注释,以便后期修复
|
69
|
+
"no-warning-comments": [
|
70
|
+
"warn",
|
71
|
+
{
|
72
|
+
terms: ["todo", "fixme"]
|
73
|
+
}
|
74
|
+
],
|
75
|
+
// 路径拼接使用path.join,而不是直接使用加号
|
76
|
+
"n/no-path-concat": "error"
|
77
|
+
}
|
78
|
+
};
|
79
|
+
}
|
80
|
+
|
81
|
+
// src/configs/ts.ts
|
82
|
+
function ts() {
|
83
|
+
return {
|
84
|
+
plugins: ["@typescript-eslint", "@stylistic"],
|
85
|
+
rules: {
|
86
|
+
"@typescript-eslint/no-unused-vars": "warn",
|
87
|
+
// 如果没用模板字符串,避免使用反引号
|
88
|
+
"@stylistic/quotes": ["error", "single", { avoidEscape: true }],
|
89
|
+
// 优先使用interface而不是type
|
90
|
+
"@typescript-eslint/consistent-type-definitions": "error",
|
91
|
+
// The `@typescript-eslint/naming-convention` rule allows `leadingUnderscore` and `trailingUnderscore` settings.
|
92
|
+
// However, the existing `no-underscore-dangle` rule already takes care of this.
|
93
|
+
"@typescript-eslint/naming-convention": [
|
94
|
+
"error",
|
95
|
+
// Allow camelCase variables (23.2), PascalCase variables (23.8), and UPPER_CASE variables (23.10)
|
96
|
+
{
|
97
|
+
selector: "variable",
|
98
|
+
format: ["camelCase", "PascalCase", "UPPER_CASE"],
|
99
|
+
filter: {
|
100
|
+
regex: "^(__dirname|__filename)$",
|
101
|
+
match: false
|
102
|
+
}
|
103
|
+
},
|
104
|
+
// Allow camelCase functions (23.2), and PascalCase functions (23.8)
|
105
|
+
{
|
106
|
+
selector: "function",
|
107
|
+
format: ["camelCase", "PascalCase"]
|
108
|
+
},
|
109
|
+
// Airbnb recommends PascalCase for classes (23.3),
|
110
|
+
// and although Airbnb does not make TypeScript recommendations,
|
111
|
+
// we are assuming this rule would similarly apply to anything "type like",
|
112
|
+
// including interfaces, type aliases, and enums
|
113
|
+
{
|
114
|
+
selector: "typeLike",
|
115
|
+
format: ["PascalCase"]
|
116
|
+
},
|
117
|
+
{
|
118
|
+
selector: "parameter",
|
119
|
+
format: ["camelCase"],
|
120
|
+
leadingUnderscore: "allow"
|
121
|
+
},
|
122
|
+
{
|
123
|
+
selector: "method",
|
124
|
+
format: ["camelCase", "PascalCase"]
|
125
|
+
},
|
126
|
+
{
|
127
|
+
selector: "typeProperty",
|
128
|
+
format: ["camelCase"]
|
129
|
+
},
|
130
|
+
{
|
131
|
+
selector: "enumMember",
|
132
|
+
format: ["PascalCase", "UPPER_CASE"]
|
133
|
+
}
|
134
|
+
],
|
135
|
+
// 禁止没有必要的初始化
|
136
|
+
"@typescript-eslint/no-inferrable-types": "error",
|
137
|
+
// 函数中未使用await,函数签名不要加async
|
138
|
+
"@typescript-eslint/require-await": "error",
|
139
|
+
// 没有必要的类型as
|
140
|
+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
141
|
+
// 数组用T[]而不是Array<T>
|
142
|
+
"@typescript-eslint/array-type": ["error", { default: "array" }],
|
143
|
+
// Promise必须加await或void
|
144
|
+
"@typescript-eslint/no-misused-promises": [
|
145
|
+
"error",
|
146
|
+
{
|
147
|
+
checksVoidReturn: false
|
148
|
+
}
|
149
|
+
],
|
150
|
+
// 以下是关闭的规则
|
151
|
+
"@typescript-eslint/strict-boolean-expressions": "off",
|
152
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
153
|
+
"@typescript-eslint/restrict-template-expressions": "off",
|
154
|
+
"@typescript-eslint/no-non-null-assertion": "off",
|
155
|
+
"@typescript-eslint/method-signature-style": "off",
|
156
|
+
"@typescript-eslint/consistent-type-assertions": "off",
|
157
|
+
"@typescript-eslint/no-extraneous-class": "off",
|
158
|
+
"@typescript-eslint/no-confusing-void-expression": "off",
|
159
|
+
"@typescript-eslint/explicit-member-accessibility": "off",
|
160
|
+
"@typescript-eslint/unbound-method": "off",
|
161
|
+
"@typescript-eslint/no-unsafe-argument": "off"
|
162
|
+
}
|
163
|
+
};
|
164
|
+
}
|
165
|
+
|
166
|
+
// src/configs/promise.ts
|
167
|
+
function promise() {
|
168
|
+
return {
|
169
|
+
plugins: ["promise"],
|
170
|
+
rules: {
|
171
|
+
"promise/no-nesting": "error",
|
172
|
+
"promise/no-promise-in-callback": "error",
|
173
|
+
"promise/param-names": "error",
|
174
|
+
"promise/no-multiple-resolved": "error",
|
175
|
+
"promise/no-return-in-finally": "error"
|
176
|
+
}
|
177
|
+
};
|
178
|
+
}
|
179
|
+
|
180
|
+
// src/configs/import.ts
|
181
|
+
var import_node_path = __toESM(require("path"));
|
182
|
+
var import_node_fs = __toESM(require("fs"));
|
183
|
+
var import_find_root = require("@manypkg/find-root");
|
184
|
+
var import_eslint_utils = require("@agilebot/eslint-utils");
|
185
|
+
function eslintImport(packageDir, devDependencies) {
|
186
|
+
const { rootDir } = (0, import_find_root.findRootSync)(__dirname);
|
187
|
+
const pkg = require(import_node_path.default.join(packageDir, "package.json"));
|
188
|
+
const tmpPkg = {
|
189
|
+
name: `${pkg.name}/tmp`,
|
190
|
+
dependencies: {
|
191
|
+
[pkg.name]: "*"
|
192
|
+
}
|
193
|
+
};
|
194
|
+
const tmpPkgSafeName = tmpPkg.name.replaceAll("/", "__");
|
195
|
+
const cacheDir = (0, import_eslint_utils.getCacheDir)(rootDir);
|
196
|
+
const tmpPkgDir = import_node_path.default.join(cacheDir, "tmp-pkg", tmpPkgSafeName);
|
197
|
+
if (!import_node_fs.default.existsSync(tmpPkgDir)) {
|
198
|
+
import_node_fs.default.mkdirSync(tmpPkgDir, { recursive: true });
|
199
|
+
}
|
200
|
+
const tmpPkgJson = JSON.stringify(tmpPkg, null, 2);
|
201
|
+
import_node_fs.default.writeFileSync(import_node_path.default.join(tmpPkgDir, "package.json"), tmpPkgJson);
|
202
|
+
return {
|
203
|
+
plugins: ["import", "no-relative-import-paths"],
|
204
|
+
extends: ["plugin:import/recommended", "plugin:import/typescript"],
|
205
|
+
rules: {
|
206
|
+
"import/no-unresolved": "error",
|
207
|
+
"import/no-named-as-default-member": "off",
|
208
|
+
"import/no-named-as-default": "off",
|
209
|
+
"import/no-useless-path-segments": [
|
210
|
+
"error",
|
211
|
+
{
|
212
|
+
noUselessIndex: true
|
213
|
+
}
|
214
|
+
],
|
215
|
+
"import/no-cycle": "error",
|
216
|
+
"import/newline-after-import": "error",
|
217
|
+
"import/first": "error",
|
218
|
+
"import/no-import-module-exports": "error",
|
219
|
+
"import/no-anonymous-default-export": [
|
220
|
+
"error",
|
221
|
+
{
|
222
|
+
allowArray: true,
|
223
|
+
allowObject: true
|
224
|
+
}
|
225
|
+
],
|
226
|
+
"import/no-extraneous-dependencies": [
|
227
|
+
"error",
|
228
|
+
{
|
229
|
+
packageDir: [packageDir, tmpPkgDir, rootDir],
|
230
|
+
devDependencies: [
|
231
|
+
"test/**/*",
|
232
|
+
"tests/**/*",
|
233
|
+
"**/__tests__/**",
|
234
|
+
"**/*.test.{ts,tsx}",
|
235
|
+
"**/*.config.{ts,js,cjs,mjs,mts,cts}",
|
236
|
+
"**/.storybook/**",
|
237
|
+
"**/*.stories.{ts,tsx}",
|
238
|
+
"**/scripts/*.{ts,mts}",
|
239
|
+
...devDependencies ?? []
|
240
|
+
],
|
241
|
+
includeInternal: true
|
242
|
+
}
|
243
|
+
],
|
244
|
+
"import/order": [
|
245
|
+
"error",
|
246
|
+
{
|
247
|
+
groups: [
|
248
|
+
"builtin",
|
249
|
+
"external",
|
250
|
+
"internal",
|
251
|
+
"parent",
|
252
|
+
"sibling",
|
253
|
+
"index",
|
254
|
+
"object"
|
255
|
+
],
|
256
|
+
pathGroups: [
|
257
|
+
{
|
258
|
+
pattern: `${pkg.name}/**`,
|
259
|
+
group: "parent",
|
260
|
+
position: "after"
|
261
|
+
}
|
262
|
+
],
|
263
|
+
"newlines-between": "never",
|
264
|
+
distinctGroup: false
|
265
|
+
}
|
266
|
+
],
|
267
|
+
"no-relative-import-paths/no-relative-import-paths": [
|
268
|
+
"warn",
|
269
|
+
{ allowSameFolder: true }
|
270
|
+
]
|
271
|
+
},
|
272
|
+
settings: {
|
273
|
+
"import/parsers": {
|
274
|
+
"@typescript-eslint/parser": [".ts", ".tsx"]
|
275
|
+
},
|
276
|
+
"import/resolver": {
|
277
|
+
typescript: {
|
278
|
+
alwaysTryTypes: true
|
279
|
+
}
|
280
|
+
}
|
281
|
+
}
|
282
|
+
};
|
283
|
+
}
|
284
|
+
|
285
|
+
// src/configs/unicorn.ts
|
286
|
+
function unicorn() {
|
287
|
+
return {
|
288
|
+
plugins: ["unicorn"],
|
289
|
+
extends: ["plugin:unicorn/recommended"],
|
290
|
+
rules: {
|
291
|
+
// unicorn默认规则太严格,屏蔽以下
|
292
|
+
"unicorn/filename-case": "off",
|
293
|
+
"unicorn/import-style": "off",
|
294
|
+
"unicorn/prefer-at": "off",
|
295
|
+
"unicorn/prevent-abbreviations": "off",
|
296
|
+
"unicorn/prefer-date-now": "off",
|
297
|
+
"unicorn/no-process-exit": "off",
|
298
|
+
"unicorn/prefer-module": "off",
|
299
|
+
"unicorn/no-null": "off",
|
300
|
+
"unicorn/prefer-top-level-await": "off",
|
301
|
+
"unicorn/consistent-function-scoping": "off",
|
302
|
+
"unicorn/numeric-separators-style": "off",
|
303
|
+
"unicorn/prefer-optional-catch-binding": "off",
|
304
|
+
"unicorn/no-negated-condition": "off",
|
305
|
+
"unicorn/switch-case-braces": "off",
|
306
|
+
"unicorn/no-array-for-each": "off",
|
307
|
+
"unicorn/prefer-ternary": "off",
|
308
|
+
"unicorn/better-regex": "off",
|
309
|
+
"unicorn/error-message": "off",
|
310
|
+
"unicorn/no-object-as-default-parameter": "off",
|
311
|
+
"unicorn/no-array-push-push": "off",
|
312
|
+
"unicorn/no-useless-undefined": "off",
|
313
|
+
"unicorn/prefer-blob-reading-methods": "off",
|
314
|
+
"unicorn/catch-error-name": [
|
315
|
+
"error",
|
316
|
+
{
|
317
|
+
name: "err"
|
318
|
+
}
|
319
|
+
]
|
320
|
+
}
|
321
|
+
};
|
322
|
+
}
|
323
|
+
|
324
|
+
// src/configs/react.ts
|
325
|
+
function react() {
|
326
|
+
return {
|
327
|
+
plugins: ["react", "react-hooks", "jsx-a11y"],
|
328
|
+
extends: [
|
329
|
+
"plugin:react/recommended",
|
330
|
+
"plugin:react-hooks/recommended",
|
331
|
+
"plugin:react-prefer-function-component/recommended",
|
332
|
+
"plugin:jsx-a11y/recommended"
|
333
|
+
],
|
334
|
+
rules: {
|
335
|
+
// 禁止没必要的Fragment,除了<>{foo}</>
|
336
|
+
"react/jsx-no-useless-fragment": ["error", { allowExpressions: true }],
|
337
|
+
// 优先使用<>而不是<Fragment>
|
338
|
+
"react/jsx-fragments": "error",
|
339
|
+
"react/jsx-handler-names": [
|
340
|
+
"error",
|
341
|
+
{
|
342
|
+
eventHandlerPrefix: "handle",
|
343
|
+
eventHandlerPropPrefix: "on",
|
344
|
+
checkLocalVariables: true
|
345
|
+
}
|
346
|
+
],
|
347
|
+
// useState必须以[example, setExample]命名
|
348
|
+
"react/hook-use-state": "error",
|
349
|
+
// 避免使用数组的 index 来作为 key 属性的值
|
350
|
+
"react/no-array-index-key": "error",
|
351
|
+
"react/self-closing-comp": "error",
|
352
|
+
// 组件命名符合帕斯卡
|
353
|
+
"react/jsx-pascal-case": [
|
354
|
+
"error",
|
355
|
+
{
|
356
|
+
allowNamespace: true
|
357
|
+
}
|
358
|
+
],
|
359
|
+
// 布尔属性如果为true,省略值
|
360
|
+
"react/jsx-boolean-value": "error",
|
361
|
+
// 已经有ts校验,此规则没有必要,会与带静态属性的Functional Component冲突
|
362
|
+
"react/prop-types": "off",
|
363
|
+
// <App prop={'Hello'} />没必要,使用<App prop="Hello" />
|
364
|
+
"react/jsx-curly-brace-presence": [
|
365
|
+
"error",
|
366
|
+
{
|
367
|
+
props: "never",
|
368
|
+
children: "never",
|
369
|
+
propElementValues: "always"
|
370
|
+
}
|
371
|
+
],
|
372
|
+
// 禁止声明未使用的props
|
373
|
+
"react/no-unused-prop-types": "error",
|
374
|
+
// img之类的void元素不应该有children
|
375
|
+
"react/void-dom-elements-no-children": "error",
|
376
|
+
"jsx-a11y/click-events-have-key-events": "off",
|
377
|
+
"jsx-a11y/no-static-element-interactions": "off",
|
378
|
+
"jsx-a11y/alt-text": "off"
|
379
|
+
},
|
380
|
+
settings: {
|
381
|
+
react: {
|
382
|
+
version: "detect"
|
383
|
+
}
|
384
|
+
}
|
385
|
+
};
|
386
|
+
}
|
387
|
+
|
388
|
+
// src/configs/jsdoc.ts
|
389
|
+
function jsdoc() {
|
390
|
+
return {
|
391
|
+
plugins: ["jsdoc"],
|
392
|
+
extends: ["plugin:jsdoc/recommended-typescript-error"],
|
393
|
+
rules: {
|
394
|
+
// 禁止有空行
|
395
|
+
"jsdoc/no-blank-block-descriptions": "error",
|
396
|
+
"jsdoc/no-blank-blocks": "error",
|
397
|
+
"jsdoc/require-returns": "off",
|
398
|
+
// @return注释不是很有必要
|
399
|
+
"jsdoc/require-returns-type": "off",
|
400
|
+
// 每行注释都有星号
|
401
|
+
"jsdoc/require-asterisk-prefix": "error"
|
402
|
+
}
|
403
|
+
};
|
404
|
+
}
|
405
|
+
|
406
|
+
// src/configs/lodash.ts
|
407
|
+
function lodash() {
|
408
|
+
return {
|
409
|
+
// lodash一些方法可能影响性能,如forEach等,优先使用js的原生方法
|
410
|
+
extends: ["plugin:you-dont-need-lodash-underscore/compatible"]
|
411
|
+
};
|
412
|
+
}
|
413
|
+
|
414
|
+
// src/configs/eslint.ts
|
415
|
+
var import_eslint_utils2 = require("@agilebot/eslint-utils");
|
416
|
+
function eslint() {
|
417
|
+
return {
|
418
|
+
plugins: ["eslint-comments", "file-progress"],
|
419
|
+
rules: {
|
420
|
+
// 禁止未使用的eslint-disable注释
|
421
|
+
"eslint-comments/no-unused-disable": "error",
|
422
|
+
// 禁止无限制的eslint-disable注释
|
423
|
+
"eslint-comments/no-unlimited-disable": "error",
|
424
|
+
// 禁止重复的eslint-disable注释
|
425
|
+
"eslint-comments/no-duplicate-disable": "error",
|
426
|
+
// 禁止聚合的eslint-enable注释
|
427
|
+
"eslint-comments/no-aggregating-enable": "error",
|
428
|
+
// 须说明原因eslint-disable
|
429
|
+
"eslint-comments/require-description": [
|
430
|
+
"error",
|
431
|
+
{
|
432
|
+
ignore: ["eslint-env", "exported", "global", "globals"]
|
433
|
+
}
|
434
|
+
],
|
435
|
+
"file-progress/activate": (0, import_eslint_utils2.isCI)() ? "off" : "warn"
|
436
|
+
}
|
437
|
+
};
|
438
|
+
}
|
439
|
+
|
440
|
+
// src/configs/deprecation.ts
|
441
|
+
function deprecation() {
|
442
|
+
return {
|
443
|
+
plugins: ["deprecation"],
|
444
|
+
rules: {
|
445
|
+
// 禁止使用带有deprecation标记的方法或属性
|
446
|
+
"deprecation/deprecation": "error"
|
447
|
+
}
|
448
|
+
};
|
449
|
+
}
|
450
|
+
|
451
|
+
// src/configs/cspell.ts
|
452
|
+
function cspell(words) {
|
453
|
+
return {
|
454
|
+
plugins: ["@cspell"],
|
455
|
+
rules: {
|
456
|
+
"@cspell/spellchecker": [
|
457
|
+
"warn",
|
458
|
+
{
|
459
|
+
checkComments: false,
|
460
|
+
autoFix: false,
|
461
|
+
cspell: {
|
462
|
+
words
|
463
|
+
}
|
464
|
+
}
|
465
|
+
]
|
466
|
+
}
|
467
|
+
};
|
468
|
+
}
|
469
|
+
|
470
|
+
// src/configs/agilebot.ts
|
471
|
+
function agilebot() {
|
472
|
+
return {
|
473
|
+
extends: ["plugin:@agilebot/recommended"]
|
474
|
+
};
|
475
|
+
}
|
476
|
+
|
477
|
+
// src/configs/prettier.ts
|
478
|
+
function prettier() {
|
479
|
+
return {
|
480
|
+
plugins: ["prettier"],
|
481
|
+
extends: ["plugin:prettier/recommended"],
|
482
|
+
rules: {
|
483
|
+
"prettier/prettier": [
|
484
|
+
"error",
|
485
|
+
{
|
486
|
+
endOfLine: "auto"
|
487
|
+
}
|
488
|
+
]
|
489
|
+
}
|
490
|
+
};
|
491
|
+
}
|
492
|
+
|
493
|
+
// src/configs/godaddy.ts
|
494
|
+
function godaddy() {
|
495
|
+
return {
|
496
|
+
extends: ["godaddy"],
|
497
|
+
rules: {
|
498
|
+
"quote-props": "off",
|
499
|
+
"linebreak-style": "off",
|
500
|
+
complexity: "off",
|
501
|
+
"max-statements": "off",
|
502
|
+
"id-length": "off",
|
503
|
+
"default-case": "off",
|
504
|
+
"valid-jsdoc": "off",
|
505
|
+
"generator-star-spacing": "off",
|
506
|
+
"max-params": "off",
|
507
|
+
"max-depth": "off",
|
508
|
+
"no-undefined": "off",
|
509
|
+
"no-process-env": "off",
|
510
|
+
"no-sync": "off"
|
511
|
+
}
|
512
|
+
};
|
513
|
+
}
|
514
|
+
|
515
|
+
// src/factory.ts
|
516
|
+
function factory(root, options) {
|
517
|
+
import_node_assert.default.ok(root, "root option is required");
|
518
|
+
if (options?.godaddy) {
|
519
|
+
return (0, import_eslint_utils3.mergeESLintConfig)(
|
520
|
+
godaddy(),
|
521
|
+
prettier(),
|
522
|
+
unicorn(),
|
523
|
+
eslint(),
|
524
|
+
eslintImport(root, options?.devDependencies),
|
525
|
+
options?.config ?? {}
|
526
|
+
);
|
527
|
+
}
|
528
|
+
const config = {
|
529
|
+
overrides: [
|
530
|
+
{
|
531
|
+
files: [
|
532
|
+
"*.ts",
|
533
|
+
"*.tsx",
|
534
|
+
"*.cts",
|
535
|
+
"*.mts",
|
536
|
+
"*.js",
|
537
|
+
"*.jsx",
|
538
|
+
"*.cjs",
|
539
|
+
"*.mjs"
|
540
|
+
],
|
541
|
+
parser: "@typescript-eslint/parser",
|
542
|
+
parserOptions: {
|
543
|
+
tsconfigRootDir: root
|
544
|
+
},
|
545
|
+
...(0, import_eslint_utils3.mergeESLintConfig)(
|
546
|
+
env(),
|
547
|
+
standard(),
|
548
|
+
ts(),
|
549
|
+
promise(),
|
550
|
+
eslintImport(root, options?.devDependencies),
|
551
|
+
unicorn(),
|
552
|
+
options?.react ? react() : {},
|
553
|
+
jsdoc(),
|
554
|
+
lodash(),
|
555
|
+
eslint(),
|
556
|
+
deprecation(),
|
557
|
+
cspell(options?.cspellWords ?? []),
|
558
|
+
agilebot(),
|
559
|
+
prettier(),
|
560
|
+
options?.config ?? {}
|
561
|
+
)
|
562
|
+
},
|
563
|
+
{
|
564
|
+
files: ["*.ts", "*.tsx"],
|
565
|
+
rules: {
|
566
|
+
"@typescript-eslint/explicit-member-accessibility": "error"
|
567
|
+
}
|
568
|
+
},
|
569
|
+
{
|
570
|
+
files: ["*.d.ts"],
|
571
|
+
rules: {
|
572
|
+
// .d.ts中支持导入ts文件中的类型
|
573
|
+
"@typescript-eslint/consistent-type-imports": "off",
|
574
|
+
// .d.ts中忽略属性命名规则
|
575
|
+
"@typescript-eslint/naming-convention": "off",
|
576
|
+
// .d.ts中忽略三斜线引用
|
577
|
+
"@typescript-eslint/triple-slash-reference": "off"
|
578
|
+
}
|
579
|
+
},
|
580
|
+
{
|
581
|
+
files: ["*.js", "*.jsx", "*.cjs"],
|
582
|
+
rules: {
|
583
|
+
"@typescript-eslint/no-var-requires": "off"
|
584
|
+
}
|
585
|
+
}
|
586
|
+
]
|
587
|
+
};
|
588
|
+
const tsconfigFiles = (0, import_fast_glob.globSync)("tsconfig*.json", {
|
589
|
+
cwd: root
|
590
|
+
});
|
591
|
+
if (config.parserOptions) {
|
592
|
+
if (tsconfigFiles.length > 0) {
|
593
|
+
config.parserOptions.project = tsconfigFiles;
|
594
|
+
} else {
|
595
|
+
config.parserOptions.project = true;
|
596
|
+
}
|
597
|
+
}
|
598
|
+
return config;
|
599
|
+
}
|
600
|
+
// Annotate the CommonJS export names for ESM import in node:
|
601
|
+
0 && (module.exports = {
|
602
|
+
agilebot
|
603
|
+
});
|
604
|
+
if (module.exports.default) module.exports = module.exports.default;
|
package/package.json
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "@agilebot/eslint-config",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.2.0",
|
4
4
|
"description": "Agilebot's ESLint config",
|
5
|
-
"
|
6
|
-
|
7
|
-
},
|
8
|
-
"main": "lib",
|
5
|
+
"main": "dist",
|
6
|
+
"types": "dist/index.d.ts",
|
9
7
|
"license": "MIT",
|
10
8
|
"keywords": [
|
11
9
|
"eslint",
|
@@ -17,12 +15,13 @@
|
|
17
15
|
},
|
18
16
|
"homepage": "https://github.com/sh-agilebot/frontend-toolkit/tree/master/packages/eslint-config#readme",
|
19
17
|
"dependencies": {
|
20
|
-
"@cspell/eslint-plugin": "^8.
|
18
|
+
"@cspell/eslint-plugin": "^8.7.0",
|
19
|
+
"@manypkg/find-root": "^2.2.1",
|
21
20
|
"@stylistic/eslint-plugin": "^1.7.0",
|
22
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
23
|
-
"@typescript-eslint/parser": "^7.
|
21
|
+
"@typescript-eslint/eslint-plugin": "^7.6.0",
|
22
|
+
"@typescript-eslint/parser": "^7.6.0",
|
24
23
|
"eslint-config-godaddy": "^6.0.0",
|
25
|
-
"eslint-config-love": "^
|
24
|
+
"eslint-config-love": "^47.0.0",
|
26
25
|
"eslint-config-prettier": "^9.1.0",
|
27
26
|
"eslint-import-resolver-typescript": "^3.6.1",
|
28
27
|
"eslint-plugin-deprecation": "^2.0.0",
|
@@ -31,26 +30,27 @@
|
|
31
30
|
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
|
32
31
|
"eslint-plugin-jsdoc": "^48.2.1",
|
33
32
|
"eslint-plugin-jsx-a11y": "^6.8.0",
|
34
|
-
"eslint-plugin-n": "^
|
35
|
-
"eslint-plugin-no-relative-import-paths": "^1.5.
|
33
|
+
"eslint-plugin-n": "^17.2.0",
|
34
|
+
"eslint-plugin-no-relative-import-paths": "^1.5.4",
|
36
35
|
"eslint-plugin-prettier": "^5.1.3",
|
37
36
|
"eslint-plugin-promise": "^6.0.0",
|
38
37
|
"eslint-plugin-react": "^7.34.1",
|
39
38
|
"eslint-plugin-react-hooks": "^4.6.0",
|
40
39
|
"eslint-plugin-react-prefer-function-component": "^3.3.0",
|
41
|
-
"eslint-plugin-unicorn": "^
|
42
|
-
"eslint-plugin-you-dont-need-lodash-underscore": "^6.13.0"
|
40
|
+
"eslint-plugin-unicorn": "^52.0.0",
|
41
|
+
"eslint-plugin-you-dont-need-lodash-underscore": "^6.13.0",
|
42
|
+
"fast-glob": "^3.3.2",
|
43
|
+
"@agilebot/eslint-utils": "0.2.0"
|
43
44
|
},
|
44
45
|
"peerDependencies": {
|
45
46
|
"@agilebot/eslint-plugin": "*",
|
46
|
-
"@agilebot/eslint-utils": "*",
|
47
47
|
"eslint": "^7.0.0 || ^8.0.0"
|
48
48
|
},
|
49
49
|
"files": [
|
50
|
-
"
|
51
|
-
"bin"
|
50
|
+
"dist"
|
52
51
|
],
|
53
52
|
"scripts": {
|
54
|
-
"
|
53
|
+
"build": "tsup",
|
54
|
+
"lint": "eslint src --fix"
|
55
55
|
}
|
56
56
|
}
|
package/bin/eslint-agilebot
DELETED
package/lib/cli.js
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
const fs = require('node:fs');
|
2
|
-
const path = require('node:path');
|
3
|
-
|
4
|
-
module.exports = function (filename) {
|
5
|
-
filename = filename || path.join(__dirname, 'index');
|
6
|
-
|
7
|
-
const isEslint = /^\.eslint.*/;
|
8
|
-
const cwd = process.cwd();
|
9
|
-
const has = {
|
10
|
-
fix: false,
|
11
|
-
config: false
|
12
|
-
};
|
13
|
-
|
14
|
-
process.argv.forEach(function (arg) {
|
15
|
-
has.fix = has.fix || arg === '--fix';
|
16
|
-
has.config = has.config || arg === '-c' || arg === '--config';
|
17
|
-
});
|
18
|
-
|
19
|
-
if (!has.fix) {
|
20
|
-
process.argv.splice(2, 0, '--fix');
|
21
|
-
}
|
22
|
-
|
23
|
-
//
|
24
|
-
// Only force our config file if there is one not in the current
|
25
|
-
// directory AND not specified by the command line.
|
26
|
-
//
|
27
|
-
|
28
|
-
// eslint-disable-next-line n/prefer-promises/fs -- Not available in Node.js 10
|
29
|
-
fs.readdir(cwd, function (err, files) {
|
30
|
-
if (err) {
|
31
|
-
throw err;
|
32
|
-
}
|
33
|
-
|
34
|
-
has.config =
|
35
|
-
has.config ||
|
36
|
-
files.some(function (file) {
|
37
|
-
return isEslint.test(file);
|
38
|
-
});
|
39
|
-
|
40
|
-
if (!has.config) {
|
41
|
-
process.argv.splice(2, 0, '-c', require.resolve(filename));
|
42
|
-
}
|
43
|
-
|
44
|
-
const pkg = require.resolve('eslint/package.json');
|
45
|
-
const bin = path.join(pkg, '..', 'bin', 'eslint.js');
|
46
|
-
|
47
|
-
require(bin);
|
48
|
-
});
|
49
|
-
};
|
package/lib/configs/agilebot.js
DELETED
package/lib/configs/cspell.js
DELETED
package/lib/configs/env.js
DELETED
package/lib/configs/eslint.js
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
const { isCI } = require('@agilebot/eslint-utils');
|
2
|
-
|
3
|
-
module.exports = {
|
4
|
-
plugins: ['eslint-comments', 'file-progress'],
|
5
|
-
rules: {
|
6
|
-
// 禁止未使用的eslint-disable注释
|
7
|
-
'eslint-comments/no-unused-disable': 'error',
|
8
|
-
// 禁止无限制的eslint-disable注释
|
9
|
-
'eslint-comments/no-unlimited-disable': 'error',
|
10
|
-
// 禁止重复的eslint-disable注释
|
11
|
-
'eslint-comments/no-duplicate-disable': 'error',
|
12
|
-
// 禁止聚合的eslint-enable注释
|
13
|
-
'eslint-comments/no-aggregating-enable': 'error',
|
14
|
-
// 须说明原因eslint-disable
|
15
|
-
'eslint-comments/require-description': [
|
16
|
-
'error',
|
17
|
-
{
|
18
|
-
ignore: ['eslint-env', 'exported', 'global', 'globals']
|
19
|
-
}
|
20
|
-
],
|
21
|
-
'file-progress/activate': isCI() ? 'off' : 'warn'
|
22
|
-
}
|
23
|
-
};
|
package/lib/configs/godaddy.js
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
// config for eslint plugins, DO NOT use for ts
|
2
|
-
module.exports = {
|
3
|
-
extends: ['godaddy'],
|
4
|
-
rules: {
|
5
|
-
'quote-props': 'off',
|
6
|
-
'linebreak-style': 'off',
|
7
|
-
complexity: 'off',
|
8
|
-
'max-statements': 'off',
|
9
|
-
'id-length': 'off',
|
10
|
-
'default-case': 'off',
|
11
|
-
'valid-jsdoc': 'off',
|
12
|
-
'generator-star-spacing': 'off',
|
13
|
-
'max-params': 'off',
|
14
|
-
'max-depth': 'off',
|
15
|
-
'no-undefined': 'off',
|
16
|
-
'no-process-env': 'off',
|
17
|
-
'no-sync': 'off'
|
18
|
-
}
|
19
|
-
};
|
package/lib/configs/import.js
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module.exports = {
|
2
|
-
plugins: ['import', 'no-relative-import-paths'],
|
3
|
-
extends: ['plugin:import/recommended', 'plugin:import/typescript'],
|
4
|
-
rules: {
|
5
|
-
'import/no-unresolved': 'error',
|
6
|
-
'import/no-named-as-default-member': 'off',
|
7
|
-
'import/no-named-as-default': 'off',
|
8
|
-
'import/no-useless-path-segments': [
|
9
|
-
'error',
|
10
|
-
{
|
11
|
-
noUselessIndex: true
|
12
|
-
}
|
13
|
-
],
|
14
|
-
'import/no-cycle': 'error',
|
15
|
-
'import/newline-after-import': 'error',
|
16
|
-
'import/first': 'error',
|
17
|
-
'import/no-import-module-exports': 'error',
|
18
|
-
'import/no-anonymous-default-export': [
|
19
|
-
'error',
|
20
|
-
{
|
21
|
-
allowArray: true,
|
22
|
-
allowObject: true
|
23
|
-
}
|
24
|
-
],
|
25
|
-
'no-relative-import-paths/no-relative-import-paths': [
|
26
|
-
'warn',
|
27
|
-
{ allowSameFolder: true }
|
28
|
-
]
|
29
|
-
},
|
30
|
-
settings: {
|
31
|
-
'import/parsers': {
|
32
|
-
'@typescript-eslint/parser': ['.ts', '.tsx']
|
33
|
-
},
|
34
|
-
'import/resolver': {
|
35
|
-
typescript: {
|
36
|
-
alwaysTryTypes: true
|
37
|
-
}
|
38
|
-
}
|
39
|
-
}
|
40
|
-
};
|
package/lib/configs/jsdoc.js
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module.exports = {
|
2
|
-
plugins: ['jsdoc'],
|
3
|
-
extends: ['plugin:jsdoc/recommended-typescript-error'],
|
4
|
-
rules: {
|
5
|
-
// 禁止有空行
|
6
|
-
'jsdoc/no-blank-block-descriptions': 'error',
|
7
|
-
'jsdoc/no-blank-blocks': 'error',
|
8
|
-
'jsdoc/require-returns': 'off',
|
9
|
-
// @return注释不是很有必要
|
10
|
-
'jsdoc/require-returns-type': 'off',
|
11
|
-
// 每行注释都有星号
|
12
|
-
'jsdoc/require-asterisk-prefix': 'error'
|
13
|
-
}
|
14
|
-
};
|
package/lib/configs/lodash.js
DELETED
package/lib/configs/prettier.js
DELETED
package/lib/configs/promise.js
DELETED
package/lib/configs/react.js
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
module.exports = {
|
2
|
-
plugins: ['react', 'react-hooks', 'jsx-a11y'],
|
3
|
-
extends: [
|
4
|
-
'plugin:react/recommended',
|
5
|
-
'plugin:react-hooks/recommended',
|
6
|
-
'plugin:react-prefer-function-component/recommended',
|
7
|
-
'plugin:jsx-a11y/recommended'
|
8
|
-
],
|
9
|
-
rules: {
|
10
|
-
// 禁止没必要的Fragment,除了<>{foo}</>
|
11
|
-
'react/jsx-no-useless-fragment': ['error', { allowExpressions: true }],
|
12
|
-
// 优先使用<>而不是<Fragment>
|
13
|
-
'react/jsx-fragments': 'error',
|
14
|
-
'react/jsx-handler-names': [
|
15
|
-
'error',
|
16
|
-
{
|
17
|
-
eventHandlerPrefix: 'handle',
|
18
|
-
eventHandlerPropPrefix: 'on',
|
19
|
-
checkLocalVariables: true
|
20
|
-
}
|
21
|
-
],
|
22
|
-
// useState必须以[example, setExample]命名
|
23
|
-
'react/hook-use-state': 'error',
|
24
|
-
// 避免使用数组的 index 来作为 key 属性的值
|
25
|
-
'react/no-array-index-key': 'error',
|
26
|
-
'react/self-closing-comp': 'error',
|
27
|
-
// 组件命名符合帕斯卡
|
28
|
-
'react/jsx-pascal-case': [
|
29
|
-
'error',
|
30
|
-
{
|
31
|
-
allowNamespace: true
|
32
|
-
}
|
33
|
-
],
|
34
|
-
// 布尔属性如果为true,省略值
|
35
|
-
'react/jsx-boolean-value': 'error',
|
36
|
-
// 已经有ts校验,此规则没有必要,会与带静态属性的Functional Component冲突
|
37
|
-
'react/prop-types': 'off',
|
38
|
-
// <App prop={'Hello'} />没必要,使用<App prop="Hello" />
|
39
|
-
'react/jsx-curly-brace-presence': [
|
40
|
-
'error',
|
41
|
-
{
|
42
|
-
props: 'never',
|
43
|
-
children: 'never',
|
44
|
-
propElementValues: 'always'
|
45
|
-
}
|
46
|
-
],
|
47
|
-
// 禁止声明未使用的props
|
48
|
-
'react/no-unused-prop-types': 'error',
|
49
|
-
// img之类的void元素不应该有children
|
50
|
-
'react/void-dom-elements-no-children': 'error',
|
51
|
-
'jsx-a11y/click-events-have-key-events': 'off',
|
52
|
-
'jsx-a11y/no-static-element-interactions': 'off',
|
53
|
-
'jsx-a11y/alt-text': 'off'
|
54
|
-
},
|
55
|
-
settings: {
|
56
|
-
react: {
|
57
|
-
version: 'detect'
|
58
|
-
}
|
59
|
-
}
|
60
|
-
};
|
package/lib/configs/standard.js
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module.exports = {
|
2
|
-
extends: ['love'],
|
3
|
-
rules: {
|
4
|
-
'no-alert': 'error',
|
5
|
-
// 避免使用同步方法
|
6
|
-
'n/no-sync': 'error',
|
7
|
-
// 尽量使用fs.promises而不是fs
|
8
|
-
'n/prefer-promises/fs': 'error',
|
9
|
-
'arrow-body-style': 'error',
|
10
|
-
curly: 'error',
|
11
|
-
// 找出TODO注释,以便后期修复
|
12
|
-
'no-warning-comments': [
|
13
|
-
'warn',
|
14
|
-
{
|
15
|
-
terms: ['todo', 'fixme']
|
16
|
-
}
|
17
|
-
],
|
18
|
-
// 路径拼接使用path.join,而不是直接使用加号
|
19
|
-
'n/no-path-concat': 'error'
|
20
|
-
}
|
21
|
-
};
|
package/lib/configs/ts.js
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
module.exports = {
|
2
|
-
plugins: ['@typescript-eslint', '@stylistic'],
|
3
|
-
rules: {
|
4
|
-
'@typescript-eslint/no-unused-vars': 'warn',
|
5
|
-
// 如果没用模板字符串,避免使用反引号
|
6
|
-
'@stylistic/quotes': ['error', 'single', { avoidEscape: true }],
|
7
|
-
// 优先使用interface而不是type
|
8
|
-
'@typescript-eslint/consistent-type-definitions': 'error',
|
9
|
-
// The `@typescript-eslint/naming-convention` rule allows `leadingUnderscore` and `trailingUnderscore` settings.
|
10
|
-
// However, the existing `no-underscore-dangle` rule already takes care of this.
|
11
|
-
'@typescript-eslint/naming-convention': [
|
12
|
-
'error',
|
13
|
-
// Allow camelCase variables (23.2), PascalCase variables (23.8), and UPPER_CASE variables (23.10)
|
14
|
-
{
|
15
|
-
selector: 'variable',
|
16
|
-
format: ['camelCase', 'PascalCase', 'UPPER_CASE']
|
17
|
-
},
|
18
|
-
// Allow camelCase functions (23.2), and PascalCase functions (23.8)
|
19
|
-
{
|
20
|
-
selector: 'function',
|
21
|
-
format: ['camelCase', 'PascalCase']
|
22
|
-
},
|
23
|
-
// Airbnb recommends PascalCase for classes (23.3),
|
24
|
-
// and although Airbnb does not make TypeScript recommendations,
|
25
|
-
// we are assuming this rule would similarly apply to anything "type like",
|
26
|
-
// including interfaces, type aliases, and enums
|
27
|
-
{
|
28
|
-
selector: 'typeLike',
|
29
|
-
format: ['PascalCase']
|
30
|
-
},
|
31
|
-
{
|
32
|
-
selector: 'parameter',
|
33
|
-
format: ['camelCase'],
|
34
|
-
leadingUnderscore: 'allow'
|
35
|
-
},
|
36
|
-
{
|
37
|
-
selector: 'method',
|
38
|
-
format: ['camelCase', 'PascalCase']
|
39
|
-
},
|
40
|
-
{
|
41
|
-
selector: 'typeProperty',
|
42
|
-
format: ['camelCase']
|
43
|
-
},
|
44
|
-
{
|
45
|
-
selector: 'enumMember',
|
46
|
-
format: ['PascalCase', 'UPPER_CASE']
|
47
|
-
}
|
48
|
-
],
|
49
|
-
// 禁止没有必要的初始化
|
50
|
-
'@typescript-eslint/no-inferrable-types': 'error',
|
51
|
-
// 函数中未使用await,函数签名不要加async
|
52
|
-
'@typescript-eslint/require-await': 'error',
|
53
|
-
// 没有必要的类型as
|
54
|
-
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
|
55
|
-
// 数组用T[]而不是Array<T>
|
56
|
-
'@typescript-eslint/array-type': ['error', { default: 'array' }],
|
57
|
-
// Promise必须加await或void
|
58
|
-
'@typescript-eslint/no-misused-promises': [
|
59
|
-
'error',
|
60
|
-
{
|
61
|
-
checksVoidReturn: false
|
62
|
-
}
|
63
|
-
],
|
64
|
-
// 以下是关闭的规则
|
65
|
-
'@typescript-eslint/strict-boolean-expressions': 'off',
|
66
|
-
'@typescript-eslint/explicit-function-return-type': 'off',
|
67
|
-
'@typescript-eslint/restrict-template-expressions': 'off',
|
68
|
-
'@typescript-eslint/no-non-null-assertion': 'off',
|
69
|
-
'@typescript-eslint/method-signature-style': 'off',
|
70
|
-
'@typescript-eslint/consistent-type-assertions': 'off',
|
71
|
-
'@typescript-eslint/no-extraneous-class': 'off',
|
72
|
-
'@typescript-eslint/no-confusing-void-expression': 'off',
|
73
|
-
'@typescript-eslint/explicit-member-accessibility': 'off',
|
74
|
-
'@typescript-eslint/unbound-method': 'off',
|
75
|
-
'@typescript-eslint/no-unsafe-argument': 'off'
|
76
|
-
}
|
77
|
-
};
|
package/lib/configs/unicorn.js
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
module.exports = {
|
2
|
-
plugins: ['unicorn'],
|
3
|
-
extends: ['plugin:unicorn/recommended'],
|
4
|
-
rules: {
|
5
|
-
// unicorn默认规则太严格,屏蔽以下
|
6
|
-
'unicorn/filename-case': 'off',
|
7
|
-
'unicorn/import-style': 'off',
|
8
|
-
'unicorn/prefer-at': 'off',
|
9
|
-
'unicorn/prevent-abbreviations': 'off',
|
10
|
-
'unicorn/prefer-date-now': 'off',
|
11
|
-
'unicorn/no-process-exit': 'off',
|
12
|
-
'unicorn/prefer-module': 'off',
|
13
|
-
'unicorn/no-null': 'off',
|
14
|
-
'unicorn/prefer-top-level-await': 'off',
|
15
|
-
'unicorn/consistent-function-scoping': 'off',
|
16
|
-
'unicorn/numeric-separators-style': 'off',
|
17
|
-
'unicorn/prefer-optional-catch-binding': 'off',
|
18
|
-
'unicorn/no-negated-condition': 'off',
|
19
|
-
'unicorn/switch-case-braces': 'off',
|
20
|
-
'unicorn/no-array-for-each': 'off',
|
21
|
-
'unicorn/prefer-ternary': 'off',
|
22
|
-
'unicorn/better-regex': 'off',
|
23
|
-
'unicorn/error-message': 'off',
|
24
|
-
'unicorn/no-object-as-default-parameter': 'off',
|
25
|
-
'unicorn/no-array-push-push': 'off',
|
26
|
-
'unicorn/no-useless-undefined': 'off',
|
27
|
-
'unicorn/prefer-blob-reading-methods': 'off',
|
28
|
-
'unicorn/catch-error-name': [
|
29
|
-
'error',
|
30
|
-
{
|
31
|
-
name: 'err'
|
32
|
-
}
|
33
|
-
]
|
34
|
-
}
|
35
|
-
};
|
package/lib/index.js
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
module.exports = {
|
2
|
-
overrides: [
|
3
|
-
{
|
4
|
-
files: [
|
5
|
-
'*.ts',
|
6
|
-
'*.tsx',
|
7
|
-
'*.cts',
|
8
|
-
'*.mts',
|
9
|
-
'*.js',
|
10
|
-
'*.jsx',
|
11
|
-
'*.cjs',
|
12
|
-
'*.mjs'
|
13
|
-
],
|
14
|
-
parser: '@typescript-eslint/parser',
|
15
|
-
extends: [
|
16
|
-
'./configs/env',
|
17
|
-
'./configs/standard',
|
18
|
-
'./configs/ts',
|
19
|
-
'./configs/promise',
|
20
|
-
'./configs/import',
|
21
|
-
'./configs/unicorn',
|
22
|
-
'./configs/react',
|
23
|
-
'./configs/jsdoc',
|
24
|
-
'./configs/lodash',
|
25
|
-
'./configs/eslint',
|
26
|
-
'./configs/deprecation',
|
27
|
-
'./configs/cspell',
|
28
|
-
'./configs/agilebot',
|
29
|
-
'./configs/prettier'
|
30
|
-
]
|
31
|
-
},
|
32
|
-
{
|
33
|
-
files: ['*.ts', '*.tsx'],
|
34
|
-
rules: {
|
35
|
-
'@typescript-eslint/explicit-member-accessibility': 'error'
|
36
|
-
}
|
37
|
-
},
|
38
|
-
{
|
39
|
-
files: ['*.d.ts'],
|
40
|
-
rules: {
|
41
|
-
// .d.ts中支持导入ts文件中的类型
|
42
|
-
'@typescript-eslint/consistent-type-imports': 'off',
|
43
|
-
// .d.ts中忽略属性命名规则
|
44
|
-
'@typescript-eslint/naming-convention': 'off',
|
45
|
-
// .d.ts中忽略三斜线引用
|
46
|
-
'@typescript-eslint/triple-slash-reference': 'off'
|
47
|
-
}
|
48
|
-
},
|
49
|
-
{
|
50
|
-
files: ['*.js', '*.jsx', '*.cjs'],
|
51
|
-
rules: {
|
52
|
-
'@typescript-eslint/no-var-requires': 'off'
|
53
|
-
}
|
54
|
-
}
|
55
|
-
]
|
56
|
-
};
|