-
Notifications
You must be signed in to change notification settings - Fork 16
/
eslint.config.js
148 lines (141 loc) · 4 KB
/
eslint.config.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
import path from "node:path";
import yamlModule from "./scripts/modules/yamlModule.js";
import { configs } from "@annangela/eslint-config";
import readDir from "./scripts/modules/readDir.js";
/**
* @type { import("eslint").Linter.Config["ignores"] }
*/
const ignores = [
"**/dist/**",
"**/.*/**",
"node_modules",
"src/gadgets/libPolyfill/*",
];
const srcESlintrcFiles = (await readDir("./src")).filter((n) => path.basename(n) === ".eslintrc.yaml");
for (const srcESlintrcFile of srcESlintrcFiles) {
const dir = path.dirname(srcESlintrcFile);
const srcESlintrc = await yamlModule.readFile(srcESlintrcFile);
if (Array.isArray(srcESlintrc.ignorePatterns)) {
for (const ignorePattern of srcESlintrc.ignorePatterns) {
ignores.push(path.join(dir, ignorePattern));
}
}
}
/**
* @typedef { Pick<import("eslint").Linter.Config, "files" | "ignores"> } FileSpec
*/
/**
* @type { { browser: FileSpec, node: FileSpec } }
*/
const fileSpec = {
browser: {
files: [
"src/**/*",
"scripts/generatePolyfill/customPolyfills/**/*",
],
ignores: [
...ignores,
],
},
node: {
files: [
"scripts/**/*",
"eslint.config.js",
],
ignores: [
...ignores,
"scripts/generatePolyfill/customPolyfills/**/*",
],
},
};
/**
* @type { import("eslint").Linter.Config[] }
*/
const config = [
// base
{
...configs.base,
ignores,
},
{
...configs.browser,
...fileSpec.browser,
},
{
...fileSpec.browser,
languageOptions: {
globals: {
mw: false,
mediaWiki: false,
OO: false,
localforage: false,
moment: false,
LocalObjectStorage: false,
insertToBottomRightCorner: false,
wgULS: false,
wgUVS: false,
hashwasm: false,
oouiDialog: false,
echarts: false,
MOE_SKIN_GLOBAL_DATA_REF: false,
ace: false,
libCachedCode: false,
CodeMirror: false,
Prism: false,
},
},
},
{
...configs.node,
...fileSpec.node,
},
{
ignores,
rules: {
// other disabled rules for all files
"@stylistic/no-mixed-operators": "off",
},
},
{
...fileSpec.browser,
rules: {
// other disabled rules for browser files
"promise/prefer-await-to-callbacks": "off",
},
},
{
...fileSpec.node,
rules: {
// Running in trusted environment
"security/detect-unsafe-regex": "off",
"security/detect-object-injection": "off",
"security/detect-non-literal-fs-filename": "off",
"security/detect-non-literal-regexp": "off",
"security/detect-child-process": "off",
"n/no-extraneous-import": "off",
"n/no-process-exit": "off",
// @TODO: 临时修复
"n/no-unsupported-features/es-builtins": ["error", { version: "^18.17 || ^20.1" }],
"n/no-unsupported-features/es-syntax": ["error", { version: "^18.17 || ^20.1", ignores: ["modules"] }],
// github api use underscores naming
camelcase: [
"error",
{
allow: [
"pull_number",
"issue_number",
"head_commit",
"commit_long",
"state_reason",
"workflow_id",
"exclude_pull_requests",
"per_page",
"workflow_runs",
],
},
],
// other disabled rules for node files
},
},
];
export default config;