@cuiqg/eslint-config 2.2.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -24
- package/README.md +3 -45
- package/dist/index.d.ts +124 -0
- package/dist/index.js +388 -883
- package/package.json +69 -47
package/dist/index.js
CHANGED
|
@@ -1,53 +1,41 @@
|
|
|
1
1
|
import { FlatConfigComposer } from "eslint-flat-config-utils";
|
|
2
|
-
import
|
|
3
|
-
import process from "node:process";
|
|
2
|
+
import process$1 from "node:process";
|
|
4
3
|
import { isPackageExists } from "local-pkg";
|
|
5
|
-
import
|
|
6
|
-
import { dirname, resolve } from "node:path";
|
|
7
|
-
import { loadConfig } from "unconfig";
|
|
8
|
-
|
|
9
|
-
//#region src/utils.js
|
|
10
|
-
async function interopDefault(m) {
|
|
11
|
-
const resolved = await m;
|
|
12
|
-
return resolved.default || m;
|
|
13
|
-
}
|
|
14
|
-
function renameRules(rules, map) {
|
|
15
|
-
return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
|
|
16
|
-
for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
|
|
17
|
-
return [key, value];
|
|
18
|
-
}));
|
|
19
|
-
}
|
|
4
|
+
import globals from "globals";
|
|
20
5
|
|
|
21
|
-
//#
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const comments = async () => {
|
|
30
|
-
const pluginComments = await interopDefault(import("eslint-plugin-eslint-comments"));
|
|
31
|
-
return [{
|
|
32
|
-
name: "cuiqg/eslint-comments",
|
|
33
|
-
plugins: { "eslint-comments": pluginComments },
|
|
34
|
-
rules: { ...pluginComments.configs.recommended.rules }
|
|
35
|
-
}];
|
|
6
|
+
//#region src/env.ts
|
|
7
|
+
const isInGitHookOrLintStaged = () => {
|
|
8
|
+
return !!(process$1.env.GIT_PARAMS || process$1.env.VSCODE_GIT_COMMAND || process$1.env.npm_lifecycle_script?.startsWith("lint-staged"));
|
|
9
|
+
};
|
|
10
|
+
const isInEditor = () => {
|
|
11
|
+
if (process$1.env.CI) return false;
|
|
12
|
+
if (isInGitHookOrLintStaged()) return false;
|
|
13
|
+
return !!(process$1.env.VSCODE_PID || process$1.env.VSCODE_CWD || process$1.env.JETBRAINS_IDE || process$1.env.VIM || process$1.env.NVIM);
|
|
36
14
|
};
|
|
15
|
+
const hasVue = () => [
|
|
16
|
+
"vue",
|
|
17
|
+
"nuxt",
|
|
18
|
+
"vitepress",
|
|
19
|
+
"@slidev/cli"
|
|
20
|
+
].some((i) => isPackageExists("vue"));
|
|
21
|
+
const hasTypeScript = () => isPackageExists("typescript");
|
|
22
|
+
const hasUnoCss = () => isPackageExists("unocss");
|
|
23
|
+
const hasNextjs = () => isPackageExists("next");
|
|
37
24
|
|
|
38
25
|
//#endregion
|
|
39
|
-
//#region src/globs.
|
|
26
|
+
//#region src/globs.ts
|
|
40
27
|
const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
|
|
41
|
-
const GLOB_SRC =
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
28
|
+
const GLOB_SRC = `**/*.${GLOB_SRC_EXT}`;
|
|
29
|
+
const GLOB_TS = `**/*.?([cm])ts`;
|
|
30
|
+
const GLOB_TSX = `**/*.?([cm])tsx`;
|
|
31
|
+
const GLOB_JS = `**/*.?([cm])js`;
|
|
32
|
+
const GLOB_JSX = `**/*.?([cm])jsx`;
|
|
46
33
|
const GLOB_STYLE = "**/*.{c,le,sc}ss";
|
|
47
34
|
const GLOB_CSS = "**/*.css";
|
|
48
|
-
const GLOB_POSTCSS = "**/*.{p,post}css";
|
|
49
|
-
const GLOB_LESS = "**/*.less";
|
|
50
35
|
const GLOB_SCSS = "**/*.scss";
|
|
36
|
+
const GLOB_LESS = "**/*.less";
|
|
37
|
+
const GLOB_STYLUS = "**/*.styl";
|
|
38
|
+
const GLOB_POSTCSS = "**/*.{p,post}css";
|
|
51
39
|
const GLOB_JSON = "**/*.json";
|
|
52
40
|
const GLOB_JSON5 = "**/*.json5";
|
|
53
41
|
const GLOB_JSONC = "**/*.jsonc";
|
|
@@ -58,6 +46,17 @@ const GLOB_TOML = "**/*.toml";
|
|
|
58
46
|
const GLOB_XML = "**/*.xml";
|
|
59
47
|
const GLOB_SVG = "**/*.svg";
|
|
60
48
|
const GLOB_HTML = "**/*.htm?(l)";
|
|
49
|
+
const GLOB_ALL_SRC = [
|
|
50
|
+
GLOB_SRC,
|
|
51
|
+
GLOB_STYLE,
|
|
52
|
+
GLOB_HTML,
|
|
53
|
+
GLOB_VUE,
|
|
54
|
+
GLOB_YAML,
|
|
55
|
+
GLOB_XML,
|
|
56
|
+
GLOB_JSONC,
|
|
57
|
+
GLOB_JSON5,
|
|
58
|
+
GLOB_JSON
|
|
59
|
+
];
|
|
61
60
|
const GLOB_EXCLUDE = [
|
|
62
61
|
"**/node_modules",
|
|
63
62
|
"**/dist",
|
|
@@ -67,14 +66,15 @@ const GLOB_EXCLUDE = [
|
|
|
67
66
|
"**/bun.lockb",
|
|
68
67
|
"**/output",
|
|
69
68
|
"**/coverage",
|
|
70
|
-
"**/tmp",
|
|
71
|
-
"**/.tmp",
|
|
72
69
|
"**/temp",
|
|
73
70
|
"**/.temp",
|
|
71
|
+
"**/tmp",
|
|
72
|
+
"**/.tmp",
|
|
74
73
|
"**/.history",
|
|
75
74
|
"**/.vitepress/cache",
|
|
76
75
|
"**/.nuxt",
|
|
77
76
|
"**/.next",
|
|
77
|
+
"**/.svelte-kit",
|
|
78
78
|
"**/.vercel",
|
|
79
79
|
"**/.changeset",
|
|
80
80
|
"**/.idea",
|
|
@@ -83,7 +83,6 @@ const GLOB_EXCLUDE = [
|
|
|
83
83
|
"**/.vite-inspect",
|
|
84
84
|
"**/.yarn",
|
|
85
85
|
"**/vite.config.*.timestamp-*",
|
|
86
|
-
"**/.eslint-config-inspector",
|
|
87
86
|
"**/CHANGELOG*.md",
|
|
88
87
|
"**/*.min.*",
|
|
89
88
|
"**/LICENSE*",
|
|
@@ -93,120 +92,306 @@ const GLOB_EXCLUDE = [
|
|
|
93
92
|
];
|
|
94
93
|
|
|
95
94
|
//#endregion
|
|
96
|
-
//#region src/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
95
|
+
//#region src/utils.ts
|
|
96
|
+
async function interopDefault(module) {
|
|
97
|
+
try {
|
|
98
|
+
let resolved = await module;
|
|
99
|
+
return resolved.default || resolved;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
throw new Error(`Cannot import module: ${String(error)}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function renameRules(rules, map) {
|
|
105
|
+
return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
|
|
106
|
+
for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
|
|
107
|
+
return [key, value];
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/configs/nextjs.ts
|
|
113
|
+
function normalizeRules(rules) {
|
|
114
|
+
return Object.fromEntries(Object.entries(rules).map(([key, value]) => [key, typeof value === "string" ? [value] : value]));
|
|
115
|
+
}
|
|
116
|
+
async function nextjs() {
|
|
117
|
+
const files = [GLOB_SRC];
|
|
118
|
+
const pluginNextJS = await interopDefault(import("@next/eslint-plugin-next"));
|
|
104
119
|
return [{
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
name: "cuiqg/nextjs/setup",
|
|
121
|
+
plugins: { next: pluginNextJS }
|
|
122
|
+
}, {
|
|
123
|
+
files,
|
|
124
|
+
languageOptions: {
|
|
125
|
+
parserOptions: { ecmaFeatures: { jsx: true } },
|
|
126
|
+
sourceType: "module"
|
|
127
|
+
},
|
|
128
|
+
name: "cuiqg/nextjs/rules",
|
|
129
|
+
rules: {
|
|
130
|
+
...normalizeRules(pluginNextJS.configs.recommended.rules),
|
|
131
|
+
...normalizeRules(pluginNextJS.configs["core-web-vitals"].rules)
|
|
132
|
+
},
|
|
133
|
+
settings: { react: { version: "detect" } }
|
|
112
134
|
}];
|
|
113
|
-
}
|
|
135
|
+
}
|
|
114
136
|
|
|
115
137
|
//#endregion
|
|
116
|
-
//#region src/configs/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return [pluginGitignore({
|
|
126
|
-
name: "cuiqg/gitignore",
|
|
127
|
-
strict: false
|
|
128
|
-
})];
|
|
129
|
-
};
|
|
138
|
+
//#region src/configs/node.ts
|
|
139
|
+
async function node() {
|
|
140
|
+
const pluginNode = await interopDefault(import("eslint-plugin-n"));
|
|
141
|
+
return [{
|
|
142
|
+
name: "cuiqg/node/rules",
|
|
143
|
+
plugins: { node: pluginNode },
|
|
144
|
+
rules: { ...pluginNode.configs.recommended.rules }
|
|
145
|
+
}];
|
|
146
|
+
}
|
|
130
147
|
|
|
131
148
|
//#endregion
|
|
132
|
-
//#region src/configs/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
*
|
|
136
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
137
|
-
*/
|
|
138
|
-
const ignores = () => {
|
|
149
|
+
//#region src/configs/package-json.ts
|
|
150
|
+
async function packageJson() {
|
|
151
|
+
const [pluginPackageJson, parserJson] = await Promise.all([interopDefault(import("eslint-plugin-package-json")), interopDefault(import("jsonc-eslint-parser"))]);
|
|
139
152
|
return [{
|
|
140
|
-
|
|
141
|
-
|
|
153
|
+
files: ["**/package.json"],
|
|
154
|
+
plugins: { "package-json": pluginPackageJson },
|
|
155
|
+
name: "cuiqg/package-json/setup",
|
|
156
|
+
languageOptions: { parser: parserJson }
|
|
157
|
+
}, {
|
|
158
|
+
name: "cuiqg/package-json/rules",
|
|
159
|
+
rules: { ...pluginPackageJson.configs.recommended.rules }
|
|
142
160
|
}];
|
|
143
|
-
}
|
|
161
|
+
}
|
|
144
162
|
|
|
145
163
|
//#endregion
|
|
146
|
-
//#region src/configs/
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
* @see https://npm.im/eslint-plugin-import-x
|
|
151
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
152
|
-
*/
|
|
153
|
-
const imports = async () => {
|
|
154
|
-
const pluginImport = await interopDefault(import("eslint-plugin-import-x"));
|
|
164
|
+
//#region src/configs/vue.ts
|
|
165
|
+
async function vue() {
|
|
166
|
+
const files = [GLOB_VUE];
|
|
167
|
+
const [pluginVue, parserVue] = await Promise.all([interopDefault(import("eslint-plugin-vue")), interopDefault(import("vue-eslint-parser"))]);
|
|
155
168
|
return [{
|
|
156
|
-
|
|
157
|
-
|
|
169
|
+
languageOptions: { globals: {
|
|
170
|
+
computed: "readonly",
|
|
171
|
+
defineEmits: "readonly",
|
|
172
|
+
defineExpose: "readonly",
|
|
173
|
+
defineProps: "readonly",
|
|
174
|
+
onMounted: "readonly",
|
|
175
|
+
onUnmounted: "readonly",
|
|
176
|
+
reactive: "readonly",
|
|
177
|
+
ref: "readonly",
|
|
178
|
+
shallowReactive: "readonly",
|
|
179
|
+
shallowRef: "readonly",
|
|
180
|
+
toRef: "readonly",
|
|
181
|
+
toRefs: "readonly",
|
|
182
|
+
watch: "readonly",
|
|
183
|
+
watchEffect: "readonly"
|
|
184
|
+
} },
|
|
185
|
+
name: "cuiqg/vue/setup",
|
|
186
|
+
plugins: { vue: pluginVue }
|
|
187
|
+
}, {
|
|
188
|
+
files,
|
|
189
|
+
languageOptions: {
|
|
190
|
+
parser: parserVue,
|
|
191
|
+
parserOptions: {
|
|
192
|
+
ecmaFeatures: { jsx: true },
|
|
193
|
+
extraFileExtensions: [".vue"],
|
|
194
|
+
parser: hasTypeScript() ? await interopDefault(import("@typescript-eslint/parser")) : null,
|
|
195
|
+
sourceType: "module"
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
name: "cuiqg/vue/rules",
|
|
199
|
+
processor: pluginVue.processors[".vue"],
|
|
158
200
|
rules: {
|
|
159
|
-
|
|
160
|
-
"
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
"
|
|
165
|
-
|
|
166
|
-
|
|
201
|
+
...pluginVue.configs.base.rules,
|
|
202
|
+
...pluginVue.configs["flat/essential"].map((c) => c.rules).reduce((acc, c) => ({
|
|
203
|
+
...acc,
|
|
204
|
+
...c
|
|
205
|
+
}), {}),
|
|
206
|
+
...pluginVue.configs["flat/strongly-recommended"].map((c) => c.rules).reduce((acc, c) => ({
|
|
207
|
+
...acc,
|
|
208
|
+
...c
|
|
209
|
+
}), {}),
|
|
210
|
+
...pluginVue.configs["flat/recommended"].map((c) => c.rules).reduce((acc, c) => ({
|
|
211
|
+
...acc,
|
|
212
|
+
...c
|
|
213
|
+
}), {}),
|
|
214
|
+
"node/prefer-global/process": "off",
|
|
215
|
+
"ts/explicit-function-return-type": "off",
|
|
216
|
+
"vue/block-order": ["error", { order: [
|
|
217
|
+
"script",
|
|
218
|
+
"template",
|
|
219
|
+
"style"
|
|
220
|
+
] }],
|
|
221
|
+
"vue/component-name-in-template-casing": ["error", "PascalCase"],
|
|
222
|
+
"vue/component-options-name-casing": ["error", "PascalCase"],
|
|
223
|
+
"vue/component-tags-order": "off",
|
|
224
|
+
"vue/custom-event-name-casing": ["error", "camelCase"],
|
|
225
|
+
"vue/define-macros-order": ["error", { order: [
|
|
226
|
+
"defineOptions",
|
|
227
|
+
"defineProps",
|
|
228
|
+
"defineEmits",
|
|
229
|
+
"defineSlots"
|
|
230
|
+
] }],
|
|
231
|
+
"vue/dot-location": ["error", "property"],
|
|
232
|
+
"vue/dot-notation": ["error", { allowKeywords: true }],
|
|
233
|
+
"vue/eqeqeq": ["error", "smart"],
|
|
234
|
+
"vue/html-indent": ["error", 2],
|
|
235
|
+
"vue/html-quotes": ["error", "double"],
|
|
236
|
+
"vue/max-attributes-per-line": "off",
|
|
237
|
+
"vue/multi-word-component-names": "off",
|
|
238
|
+
"vue/no-dupe-keys": "off",
|
|
239
|
+
"vue/no-empty-pattern": "error",
|
|
240
|
+
"vue/no-irregular-whitespace": "error",
|
|
241
|
+
"vue/no-loss-of-precision": "error",
|
|
242
|
+
"vue/no-restricted-syntax": [
|
|
243
|
+
"error",
|
|
244
|
+
"DebuggerStatement",
|
|
245
|
+
"LabeledStatement",
|
|
246
|
+
"WithStatement"
|
|
247
|
+
],
|
|
248
|
+
"vue/no-restricted-v-bind": ["error", "/^v-/"],
|
|
249
|
+
"vue/no-setup-props-reactivity-loss": "off",
|
|
250
|
+
"vue/no-sparse-arrays": "error",
|
|
251
|
+
"vue/no-unused-refs": "error",
|
|
252
|
+
"vue/no-useless-v-bind": "error",
|
|
253
|
+
"vue/no-v-html": "off",
|
|
254
|
+
"vue/object-shorthand": [
|
|
255
|
+
"error",
|
|
256
|
+
"always",
|
|
257
|
+
{
|
|
258
|
+
avoidQuotes: true,
|
|
259
|
+
ignoreConstructors: false
|
|
260
|
+
}
|
|
261
|
+
],
|
|
262
|
+
"vue/prefer-separate-static-class": "error",
|
|
263
|
+
"vue/prefer-template": "error",
|
|
264
|
+
"vue/prop-name-casing": ["error", "camelCase"],
|
|
265
|
+
"vue/require-default-prop": "off",
|
|
266
|
+
"vue/require-prop-types": "off",
|
|
267
|
+
"vue/space-infix-ops": "error",
|
|
268
|
+
"vue/space-unary-ops": ["error", {
|
|
269
|
+
nonwords: false,
|
|
270
|
+
words: true
|
|
271
|
+
}],
|
|
272
|
+
"vue/array-bracket-spacing": ["error", "never"],
|
|
273
|
+
"vue/arrow-spacing": ["error", {
|
|
274
|
+
after: true,
|
|
275
|
+
before: true
|
|
276
|
+
}],
|
|
277
|
+
"vue/block-spacing": ["error", "always"],
|
|
278
|
+
"vue/block-tag-newline": ["error", {
|
|
279
|
+
multiline: "always",
|
|
280
|
+
singleline: "always"
|
|
281
|
+
}],
|
|
282
|
+
"vue/brace-style": [
|
|
283
|
+
"error",
|
|
284
|
+
"stroustrup",
|
|
285
|
+
{ allowSingleLine: true }
|
|
286
|
+
],
|
|
287
|
+
"vue/comma-dangle": ["error", "always-multiline"],
|
|
288
|
+
"vue/comma-spacing": ["error", {
|
|
289
|
+
after: true,
|
|
290
|
+
before: false
|
|
291
|
+
}],
|
|
292
|
+
"vue/comma-style": ["error", "last"],
|
|
293
|
+
"vue/html-comment-content-spacing": [
|
|
294
|
+
"error",
|
|
295
|
+
"always",
|
|
296
|
+
{ exceptions: ["-"] }
|
|
297
|
+
],
|
|
298
|
+
"vue/key-spacing": ["error", {
|
|
299
|
+
afterColon: true,
|
|
300
|
+
beforeColon: false
|
|
301
|
+
}],
|
|
302
|
+
"vue/keyword-spacing": ["error", {
|
|
303
|
+
after: true,
|
|
304
|
+
before: true
|
|
305
|
+
}],
|
|
306
|
+
"vue/object-curly-newline": "off",
|
|
307
|
+
"vue/object-curly-spacing": ["error", "always"],
|
|
308
|
+
"vue/object-property-newline": ["error", { allowAllPropertiesOnSameLine: true }],
|
|
309
|
+
"vue/operator-linebreak": ["error", "before"],
|
|
310
|
+
"vue/padding-line-between-blocks": ["error", "always"],
|
|
311
|
+
"vue/quote-props": ["error", "consistent-as-needed"],
|
|
312
|
+
"vue/space-in-parens": ["error", "never"],
|
|
313
|
+
"vue/template-curly-spacing": "error"
|
|
167
314
|
}
|
|
168
315
|
}];
|
|
169
|
-
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region src/configs/ignores.ts
|
|
320
|
+
async function ignores() {
|
|
321
|
+
const configGitignore = await interopDefault(import("eslint-config-flat-gitignore"));
|
|
322
|
+
return [{
|
|
323
|
+
ignores: [...GLOB_EXCLUDE],
|
|
324
|
+
name: "cuiqg/ignores"
|
|
325
|
+
}, configGitignore({
|
|
326
|
+
name: "cuiqg/ignores/gitignore",
|
|
327
|
+
strict: false
|
|
328
|
+
})];
|
|
329
|
+
}
|
|
170
330
|
|
|
171
331
|
//#endregion
|
|
172
|
-
//#region src/
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
332
|
+
//#region src/configs/unocss.ts
|
|
333
|
+
async function unocss() {
|
|
334
|
+
const [pluginUnoCSS] = await Promise.all([interopDefault(import("@unocss/eslint-plugin"))]);
|
|
335
|
+
return [{
|
|
336
|
+
name: "cuiqg/unocss",
|
|
337
|
+
plugins: { unocss: pluginUnoCSS },
|
|
338
|
+
rules: { ...renameRules(pluginUnoCSS.configs.recommended.rules, { "@unocss": "unocss" }) }
|
|
339
|
+
}];
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
//#endregion
|
|
343
|
+
//#region src/configs/de-morgan.ts
|
|
344
|
+
async function deMorgan() {
|
|
345
|
+
const pluginDeMorgan = await interopDefault(import("eslint-plugin-de-morgan"));
|
|
346
|
+
return [{
|
|
347
|
+
...pluginDeMorgan.configs.recommended,
|
|
348
|
+
name: "cuiqg/de-morgan"
|
|
349
|
+
}];
|
|
180
350
|
}
|
|
181
|
-
|
|
182
|
-
|
|
351
|
+
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region src/configs/prettier.ts
|
|
354
|
+
async function prettier() {
|
|
355
|
+
const [pluginPrettier, recommendedPrettier] = await Promise.all([interopDefault(import("eslint-plugin-prettier")), interopDefault(import("eslint-plugin-prettier/recommended"))]);
|
|
356
|
+
return [{
|
|
357
|
+
plugins: { prettier: pluginPrettier },
|
|
358
|
+
name: "cuiqg/prettier",
|
|
359
|
+
rules: {
|
|
360
|
+
...recommendedPrettier.rules,
|
|
361
|
+
"prettier/prettier": "warn"
|
|
362
|
+
}
|
|
363
|
+
}];
|
|
183
364
|
}
|
|
184
365
|
|
|
185
366
|
//#endregion
|
|
186
|
-
//#region src/configs/javascript.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
*
|
|
190
|
-
* @see https://npm.im/@eslint/js
|
|
191
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
192
|
-
*/
|
|
193
|
-
const javascript = async () => {
|
|
367
|
+
//#region src/configs/javascript.ts
|
|
368
|
+
async function javascript() {
|
|
369
|
+
const [pluginUnuseImports, pluginJs] = await Promise.all([interopDefault(import("eslint-plugin-unused-imports")), interopDefault(import("@eslint/js"))]);
|
|
194
370
|
return [{
|
|
195
|
-
name: "cuiqg/javascript",
|
|
371
|
+
name: "cuiqg/javascript/setup",
|
|
196
372
|
languageOptions: {
|
|
373
|
+
ecmaVersion: "latest",
|
|
197
374
|
globals: {
|
|
198
375
|
...globals.browser,
|
|
199
|
-
...globals.
|
|
376
|
+
...globals.es2025,
|
|
200
377
|
...globals.node
|
|
201
378
|
},
|
|
202
379
|
parserOptions: {
|
|
203
380
|
ecmaFeatures: { jsx: true },
|
|
381
|
+
ecmaVersion: "latest",
|
|
204
382
|
sourceType: "module"
|
|
205
383
|
},
|
|
206
384
|
sourceType: "module"
|
|
207
385
|
},
|
|
208
|
-
linterOptions: { reportUnusedDisableDirectives: true }
|
|
386
|
+
linterOptions: { reportUnusedDisableDirectives: true }
|
|
387
|
+
}, {
|
|
388
|
+
plugins: {
|
|
389
|
+
"unused-imports": pluginUnuseImports,
|
|
390
|
+
js: pluginJs
|
|
391
|
+
},
|
|
392
|
+
name: "cuiqg/javascript/rules",
|
|
209
393
|
rules: {
|
|
394
|
+
...pluginJs.configs.recommended.rules,
|
|
210
395
|
"accessor-pairs": ["error", {
|
|
211
396
|
enforceForClassMembers: true,
|
|
212
397
|
setWithoutGet: true
|
|
@@ -216,7 +401,7 @@ const javascript = async () => {
|
|
|
216
401
|
"constructor-super": "error",
|
|
217
402
|
"default-case-last": "error",
|
|
218
403
|
"dot-notation": ["error", { allowKeywords: true }],
|
|
219
|
-
|
|
404
|
+
eqeqeq: ["error", "smart"],
|
|
220
405
|
"new-cap": ["error", {
|
|
221
406
|
capIsNew: false,
|
|
222
407
|
newIsCap: true,
|
|
@@ -380,806 +565,126 @@ const javascript = async () => {
|
|
|
380
565
|
"prefer-template": "error",
|
|
381
566
|
"symbol-description": "error",
|
|
382
567
|
"unicode-bom": ["error", "never"],
|
|
568
|
+
"unused-imports/no-unused-imports": isInEditor() ? "warn" : "error",
|
|
569
|
+
"unused-imports/no-unused-vars": ["error", {
|
|
570
|
+
args: "after-used",
|
|
571
|
+
argsIgnorePattern: "^_",
|
|
572
|
+
ignoreRestSiblings: true,
|
|
573
|
+
vars: "all",
|
|
574
|
+
varsIgnorePattern: "^_"
|
|
575
|
+
}],
|
|
383
576
|
"use-isnan": ["error", {
|
|
384
577
|
enforceForIndexOf: true,
|
|
385
578
|
enforceForSwitchCase: true
|
|
386
579
|
}],
|
|
387
580
|
"valid-typeof": ["error", { requireStringLiterals: true }],
|
|
388
581
|
"vars-on-top": "error",
|
|
389
|
-
|
|
582
|
+
yoda: ["error", "never"]
|
|
390
583
|
}
|
|
391
584
|
}];
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
//#endregion
|
|
395
|
-
//#region src/configs/jsdoc.js
|
|
396
|
-
/**
|
|
397
|
-
* JsDoc
|
|
398
|
-
* @see https://npm.im/eslint-plugin-jsdoc
|
|
399
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
400
|
-
*/
|
|
401
|
-
const jsdoc = async () => {
|
|
402
|
-
const pluginJsdoc = await interopDefault(import("eslint-plugin-jsdoc"));
|
|
403
|
-
const files = [GLOB_JS];
|
|
404
|
-
return [{
|
|
405
|
-
files,
|
|
406
|
-
name: "cuiqg/jsdoc",
|
|
407
|
-
plugins: { jsdoc: pluginJsdoc },
|
|
408
|
-
rules: { ...pluginJsdoc.configs["flat/recommended"].rules }
|
|
409
|
-
}];
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
//#endregion
|
|
413
|
-
//#region src/configs/jsonc.js
|
|
414
|
-
/**
|
|
415
|
-
* JSONC
|
|
416
|
-
*
|
|
417
|
-
* @link https://ota-meshi.github.io/eslint-plugin-jsonc/
|
|
418
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
419
|
-
*/
|
|
420
|
-
const jsonc = async () => {
|
|
421
|
-
const files = [
|
|
422
|
-
GLOB_JSON,
|
|
423
|
-
GLOB_JSON5,
|
|
424
|
-
GLOB_JSONC
|
|
425
|
-
];
|
|
426
|
-
const [pluginJsonc, parserJsonc] = await Promise.all([interopDefault(import("eslint-plugin-jsonc")), interopDefault(import("jsonc-eslint-parser"))]);
|
|
427
|
-
return [{
|
|
428
|
-
name: "cuiqg/jsonc",
|
|
429
|
-
files,
|
|
430
|
-
plugins: { jsonc: pluginJsonc },
|
|
431
|
-
languageOptions: { parser: parserJsonc },
|
|
432
|
-
rules: {
|
|
433
|
-
...pluginJsonc.configs["recommended-with-jsonc"].rules,
|
|
434
|
-
"jsonc/array-bracket-spacing": ["error", "never"],
|
|
435
|
-
"jsonc/comma-dangle": ["error", "never"],
|
|
436
|
-
"jsonc/comma-style": ["error", "last"],
|
|
437
|
-
"jsonc/indent": ["error", 2],
|
|
438
|
-
"jsonc/key-spacing": ["error", {
|
|
439
|
-
afterColon: true,
|
|
440
|
-
beforeColon: false
|
|
441
|
-
}],
|
|
442
|
-
"jsonc/object-curly-newline": ["error", {
|
|
443
|
-
consistent: true,
|
|
444
|
-
multiline: true
|
|
445
|
-
}],
|
|
446
|
-
"jsonc/object-curly-spacing": ["error", "always"],
|
|
447
|
-
"jsonc/object-property-newline": ["error", { allowMultiplePropertiesPerLine: true }],
|
|
448
|
-
"jsonc/quote-props": "error",
|
|
449
|
-
"jsonc/quotes": "error"
|
|
450
|
-
}
|
|
451
|
-
}];
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
//#endregion
|
|
455
|
-
//#region src/configs/macros.js
|
|
456
|
-
/**
|
|
457
|
-
* Vue Macros
|
|
458
|
-
* @see https://vue-macros.dev/zh-CN/guide/eslint-integration.html
|
|
459
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
460
|
-
*/
|
|
461
|
-
const macros = () => {
|
|
462
|
-
return [{
|
|
463
|
-
name: "cuiqg/macros",
|
|
464
|
-
languageOptions: { globals: {
|
|
465
|
-
$: "readonly",
|
|
466
|
-
$$: "readonly",
|
|
467
|
-
$computed: "readonly",
|
|
468
|
-
$customRef: "readonly",
|
|
469
|
-
$defineModels: "readonly",
|
|
470
|
-
$defineProps: "readonly",
|
|
471
|
-
$definePropsRefs: "readonly",
|
|
472
|
-
$ref: "readonly",
|
|
473
|
-
$shallowRef: "readonly",
|
|
474
|
-
$toRef: "readonly",
|
|
475
|
-
defineEmit: "readonly",
|
|
476
|
-
defineModels: "readonly",
|
|
477
|
-
defineOptions: "readonly",
|
|
478
|
-
defineProp: "readonly",
|
|
479
|
-
defineProps: "readonly",
|
|
480
|
-
defineRender: "readonly",
|
|
481
|
-
defineSetupComponent: "readonly",
|
|
482
|
-
defineSlots: "readonly"
|
|
483
|
-
} },
|
|
484
|
-
rules: {
|
|
485
|
-
"vue/no-export-in-script-setup": "off",
|
|
486
|
-
"vue/valid-attribute-name": "off",
|
|
487
|
-
"vue/valid-define-props": "off",
|
|
488
|
-
"vue/valid-v-bind": "off"
|
|
489
|
-
}
|
|
490
|
-
}];
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
//#endregion
|
|
494
|
-
//#region src/configs/node.js
|
|
495
|
-
/**
|
|
496
|
-
* Node
|
|
497
|
-
*
|
|
498
|
-
* @see https://github.com/eslint-community/eslint-plugin-n
|
|
499
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
500
|
-
*/
|
|
501
|
-
const node = async () => {
|
|
502
|
-
const pluginNode = await interopDefault(import("eslint-plugin-n"));
|
|
503
|
-
return [{
|
|
504
|
-
name: "cuiqg/node",
|
|
505
|
-
plugins: { node: pluginNode },
|
|
506
|
-
rules: {
|
|
507
|
-
"node/handle-callback-err": ["error", "^(err|error)$"],
|
|
508
|
-
"node/no-deprecated-api": "error",
|
|
509
|
-
"node/no-exports-assign": "error",
|
|
510
|
-
"node/no-new-require": "error",
|
|
511
|
-
"node/no-path-concat": "error",
|
|
512
|
-
"node/prefer-global/buffer": ["error", "never"],
|
|
513
|
-
"node/prefer-global/process": ["error", "never"],
|
|
514
|
-
"node/process-exit-as-throw": "error"
|
|
515
|
-
}
|
|
516
|
-
}];
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
//#endregion
|
|
520
|
-
//#region src/configs/pnpm.js
|
|
521
|
-
const pnpm = async () => {
|
|
522
|
-
const [parserJsonc, parserYaml, pluginPnpm] = await Promise.all([
|
|
523
|
-
interopDefault(import("jsonc-eslint-parser")),
|
|
524
|
-
interopDefault(import("yaml-eslint-parser")),
|
|
525
|
-
interopDefault(import("eslint-plugin-pnpm"))
|
|
526
|
-
]);
|
|
527
|
-
return [{
|
|
528
|
-
files: ["package.json", "**/package.json"],
|
|
529
|
-
languageOptions: { parser: parserJsonc },
|
|
530
|
-
name: "cuiqg/pnpm/package-json",
|
|
531
|
-
plugins: { pnpm: pluginPnpm },
|
|
532
|
-
rules: {
|
|
533
|
-
"pnpm/json-enforce-catalog": "error",
|
|
534
|
-
"pnpm/json-prefer-workspace-settings": "error",
|
|
535
|
-
"pnpm/json-valid-catalog": "error"
|
|
536
|
-
}
|
|
537
|
-
}, {
|
|
538
|
-
files: ["pnpm-workspace.yaml"],
|
|
539
|
-
languageOptions: { parser: parserYaml },
|
|
540
|
-
name: "cuiqg/pnpm/pnpm-workspace-yaml",
|
|
541
|
-
plugins: { pnpm: pluginPnpm },
|
|
542
|
-
rules: {
|
|
543
|
-
"pnpm/yaml-no-duplicate-catalog-item": "error",
|
|
544
|
-
"pnpm/yaml-no-unused-catalog-item": "error",
|
|
545
|
-
"yaml/sort-keys": [
|
|
546
|
-
"error",
|
|
547
|
-
{
|
|
548
|
-
order: [
|
|
549
|
-
"packages",
|
|
550
|
-
"overrides",
|
|
551
|
-
"patchedDependencies",
|
|
552
|
-
"hoistPattern",
|
|
553
|
-
"catalog",
|
|
554
|
-
"catalogs",
|
|
555
|
-
"allowedDeprecatedVersions",
|
|
556
|
-
"allowNonAppliedPatches",
|
|
557
|
-
"configDependencies",
|
|
558
|
-
"ignoredBuiltDependencies",
|
|
559
|
-
"ignoredOptionalDependencies",
|
|
560
|
-
"neverBuiltDependencies",
|
|
561
|
-
"onlyBuiltDependencies",
|
|
562
|
-
"onlyBuiltDependenciesFile",
|
|
563
|
-
"packageExtensions",
|
|
564
|
-
"peerDependencyRules",
|
|
565
|
-
"supportedArchitectures"
|
|
566
|
-
],
|
|
567
|
-
pathPattern: "^$"
|
|
568
|
-
},
|
|
569
|
-
{
|
|
570
|
-
order: { type: "asc" },
|
|
571
|
-
pathPattern: ".*"
|
|
572
|
-
}
|
|
573
|
-
]
|
|
574
|
-
}
|
|
575
|
-
}];
|
|
576
|
-
};
|
|
577
|
-
|
|
578
|
-
//#endregion
|
|
579
|
-
//#region src/configs/prettier.js
|
|
580
|
-
/**
|
|
581
|
-
* Prettier
|
|
582
|
-
*
|
|
583
|
-
* @see https://github.com/prettier/eslint-plugin-prettier
|
|
584
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
585
|
-
*/
|
|
586
|
-
const prettier = async () => {
|
|
587
|
-
const [pluginJsonc, pluginPrettier] = await Promise.all([interopDefault(import("eslint-plugin-jsonc")), interopDefault(import("eslint-plugin-prettier"))]);
|
|
588
|
-
return [{
|
|
589
|
-
name: "cuiqg/prettier",
|
|
590
|
-
plugins: { prettier: pluginPrettier },
|
|
591
|
-
rules: {
|
|
592
|
-
...pluginPrettier.configs.recommended.rules,
|
|
593
|
-
...pluginJsonc.configs.prettier.rules,
|
|
594
|
-
"prettier/prettier": "warn"
|
|
595
|
-
}
|
|
596
|
-
}];
|
|
597
|
-
};
|
|
598
|
-
|
|
599
|
-
//#endregion
|
|
600
|
-
//#region src/configs/sorts.js
|
|
601
|
-
/**
|
|
602
|
-
* Sort package.json
|
|
603
|
-
*
|
|
604
|
-
* Requires `jsonc` config
|
|
605
|
-
*/
|
|
606
|
-
const sortPackageJson = async () => {
|
|
607
|
-
return [{
|
|
608
|
-
name: "cuiqg/sort/package-json",
|
|
609
|
-
files: ["**/package.json"],
|
|
610
|
-
rules: {
|
|
611
|
-
"jsonc/sort-array-values": ["error", {
|
|
612
|
-
order: { type: "asc" },
|
|
613
|
-
pathPattern: "^files$"
|
|
614
|
-
}],
|
|
615
|
-
"jsonc/sort-keys": [
|
|
616
|
-
"error",
|
|
617
|
-
{
|
|
618
|
-
order: [
|
|
619
|
-
"name",
|
|
620
|
-
"version",
|
|
621
|
-
"private",
|
|
622
|
-
"packageManager",
|
|
623
|
-
"description",
|
|
624
|
-
"type",
|
|
625
|
-
"keywords",
|
|
626
|
-
"license",
|
|
627
|
-
"homepage",
|
|
628
|
-
"bugs",
|
|
629
|
-
"repository",
|
|
630
|
-
"author",
|
|
631
|
-
"contributors",
|
|
632
|
-
"funding",
|
|
633
|
-
"files",
|
|
634
|
-
"main",
|
|
635
|
-
"module",
|
|
636
|
-
"types",
|
|
637
|
-
"exports",
|
|
638
|
-
"typesVersions",
|
|
639
|
-
"sideEffects",
|
|
640
|
-
"unpkg",
|
|
641
|
-
"jsdelivr",
|
|
642
|
-
"browser",
|
|
643
|
-
"bin",
|
|
644
|
-
"man",
|
|
645
|
-
"directories",
|
|
646
|
-
"publishConfig",
|
|
647
|
-
"scripts",
|
|
648
|
-
"peerDependencies",
|
|
649
|
-
"peerDependenciesMeta",
|
|
650
|
-
"optionalDependencies",
|
|
651
|
-
"dependencies",
|
|
652
|
-
"devDependencies",
|
|
653
|
-
"engines",
|
|
654
|
-
"config",
|
|
655
|
-
"overrides",
|
|
656
|
-
"pnpm",
|
|
657
|
-
"husky",
|
|
658
|
-
"lint-staged",
|
|
659
|
-
"eslintConfig",
|
|
660
|
-
"prettier"
|
|
661
|
-
],
|
|
662
|
-
pathPattern: "^$"
|
|
663
|
-
},
|
|
664
|
-
{
|
|
665
|
-
order: { type: "asc" },
|
|
666
|
-
pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies$"
|
|
667
|
-
},
|
|
668
|
-
{
|
|
669
|
-
order: [
|
|
670
|
-
"types",
|
|
671
|
-
"require",
|
|
672
|
-
"import",
|
|
673
|
-
"default"
|
|
674
|
-
],
|
|
675
|
-
pathPattern: "^exports.*$"
|
|
676
|
-
},
|
|
677
|
-
{
|
|
678
|
-
order: { type: "asc" },
|
|
679
|
-
pathPattern: "^resolutions$"
|
|
680
|
-
},
|
|
681
|
-
{
|
|
682
|
-
order: { type: "asc" },
|
|
683
|
-
pathPattern: "^pnpm.overrides$"
|
|
684
|
-
}
|
|
685
|
-
]
|
|
686
|
-
}
|
|
687
|
-
}];
|
|
688
|
-
};
|
|
689
|
-
/**
|
|
690
|
-
* Sort jsconfig.json
|
|
691
|
-
*
|
|
692
|
-
* Requires `jsonc` config
|
|
693
|
-
*/
|
|
694
|
-
const sortJsconfig = () => {
|
|
695
|
-
return [{
|
|
696
|
-
name: "cuiqg/sort/jsconfig-json",
|
|
697
|
-
files: ["**/jsconfig.json", "**/jsconfig.*.json"],
|
|
698
|
-
rules: { "jsonc/sort-keys": [
|
|
699
|
-
"error",
|
|
700
|
-
{
|
|
701
|
-
order: [
|
|
702
|
-
"extends",
|
|
703
|
-
"compilerOptions",
|
|
704
|
-
"references",
|
|
705
|
-
"files",
|
|
706
|
-
"include",
|
|
707
|
-
"exclude"
|
|
708
|
-
],
|
|
709
|
-
pathPattern: "^$"
|
|
710
|
-
},
|
|
711
|
-
{
|
|
712
|
-
order: [
|
|
713
|
-
"incremental",
|
|
714
|
-
"composite",
|
|
715
|
-
"tsBuildInfoFile",
|
|
716
|
-
"disableSourceOfProjectReferenceRedirect",
|
|
717
|
-
"disableSolutionSearching",
|
|
718
|
-
"disableReferencedProjectLoad",
|
|
719
|
-
"target",
|
|
720
|
-
"jsx",
|
|
721
|
-
"jsxFactory",
|
|
722
|
-
"jsxFragmentFactory",
|
|
723
|
-
"jsxImportSource",
|
|
724
|
-
"lib",
|
|
725
|
-
"moduleDetection",
|
|
726
|
-
"noLib",
|
|
727
|
-
"reactNamespace",
|
|
728
|
-
"useDefineForClassFields",
|
|
729
|
-
"emitDecoratorMetadata",
|
|
730
|
-
"experimentalDecorators",
|
|
731
|
-
"baseUrl",
|
|
732
|
-
"rootDir",
|
|
733
|
-
"rootDirs",
|
|
734
|
-
"customConditions",
|
|
735
|
-
"module",
|
|
736
|
-
"moduleResolution",
|
|
737
|
-
"moduleSuffixes",
|
|
738
|
-
"noResolve",
|
|
739
|
-
"paths",
|
|
740
|
-
"resolveJsonModule",
|
|
741
|
-
"resolvePackageJsonExports",
|
|
742
|
-
"resolvePackageJsonImports",
|
|
743
|
-
"typeRoots",
|
|
744
|
-
"types",
|
|
745
|
-
"allowArbitraryExtensions",
|
|
746
|
-
"allowImportingTsExtensions",
|
|
747
|
-
"allowUmdGlobalAccess",
|
|
748
|
-
"allowJs",
|
|
749
|
-
"checkJs",
|
|
750
|
-
"maxNodeModuleJsDepth",
|
|
751
|
-
"strict",
|
|
752
|
-
"strictBindCallApply",
|
|
753
|
-
"strictFunctionTypes",
|
|
754
|
-
"strictNullChecks",
|
|
755
|
-
"strictPropertyInitialization",
|
|
756
|
-
"allowUnreachableCode",
|
|
757
|
-
"allowUnusedLabels",
|
|
758
|
-
"alwaysStrict",
|
|
759
|
-
"exactOptionalPropertyTypes",
|
|
760
|
-
"noFallthroughCasesInSwitch",
|
|
761
|
-
"noImplicitAny",
|
|
762
|
-
"noImplicitOverride",
|
|
763
|
-
"noImplicitReturns",
|
|
764
|
-
"noImplicitThis",
|
|
765
|
-
"noPropertyAccessFromIndexSignature",
|
|
766
|
-
"noUncheckedIndexedAccess",
|
|
767
|
-
"noUnusedLocals",
|
|
768
|
-
"noUnusedParameters",
|
|
769
|
-
"useUnknownInCatchVariables",
|
|
770
|
-
"declaration",
|
|
771
|
-
"declarationDir",
|
|
772
|
-
"declarationMap",
|
|
773
|
-
"downlevelIteration",
|
|
774
|
-
"emitBOM",
|
|
775
|
-
"emitDeclarationOnly",
|
|
776
|
-
"importHelpers",
|
|
777
|
-
"importsNotUsedAsValues",
|
|
778
|
-
"inlineSourceMap",
|
|
779
|
-
"inlineSources",
|
|
780
|
-
"mapRoot",
|
|
781
|
-
"newLine",
|
|
782
|
-
"noEmit",
|
|
783
|
-
"noEmitHelpers",
|
|
784
|
-
"noEmitOnError",
|
|
785
|
-
"outDir",
|
|
786
|
-
"outFile",
|
|
787
|
-
"preserveConstEnums",
|
|
788
|
-
"preserveValueImports",
|
|
789
|
-
"removeComments",
|
|
790
|
-
"sourceMap",
|
|
791
|
-
"sourceRoot",
|
|
792
|
-
"stripInternal",
|
|
793
|
-
"allowSyntheticDefaultImports",
|
|
794
|
-
"esModuleInterop",
|
|
795
|
-
"forceConsistentCasingInFileNames",
|
|
796
|
-
"isolatedModules",
|
|
797
|
-
"preserveSymlinks",
|
|
798
|
-
"verbatimModuleSyntax",
|
|
799
|
-
"skipDefaultLibCheck",
|
|
800
|
-
"skipLibCheck"
|
|
801
|
-
],
|
|
802
|
-
pathPattern: "^compilerOptions$"
|
|
803
|
-
}
|
|
804
|
-
] }
|
|
805
|
-
}];
|
|
806
|
-
};
|
|
807
|
-
|
|
808
|
-
//#endregion
|
|
809
|
-
//#region src/configs/stylistic.js
|
|
810
|
-
/**
|
|
811
|
-
* Stylistic
|
|
812
|
-
*
|
|
813
|
-
* @see https://eslint.style/
|
|
814
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
815
|
-
*/
|
|
816
|
-
const stylistic = async () => {
|
|
817
|
-
const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
|
|
818
|
-
const config = pluginStylistic.configs.customize({
|
|
819
|
-
flat: true,
|
|
820
|
-
pluginName: "style",
|
|
821
|
-
indent: 2,
|
|
822
|
-
jsx: true,
|
|
823
|
-
quotes: "single",
|
|
824
|
-
semi: false,
|
|
825
|
-
commaDangle: "never"
|
|
826
|
-
});
|
|
827
|
-
return [{
|
|
828
|
-
name: "cuiqg/stylistic",
|
|
829
|
-
plugins: { style: pluginStylistic },
|
|
830
|
-
rules: { ...config.rules }
|
|
831
|
-
}];
|
|
832
|
-
};
|
|
833
|
-
|
|
834
|
-
//#endregion
|
|
835
|
-
//#region src/configs/toml.js
|
|
836
|
-
/**
|
|
837
|
-
* TOML
|
|
838
|
-
*
|
|
839
|
-
* @see https://ota-meshi.github.io/eslint-plugin-yml/
|
|
840
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
841
|
-
*/
|
|
842
|
-
const toml = async () => {
|
|
843
|
-
const files = [GLOB_TOML];
|
|
844
|
-
const [pluginToml, parserToml] = await Promise.all([interopDefault(import("eslint-plugin-toml")), interopDefault(import("toml-eslint-parser"))]);
|
|
845
|
-
return [{
|
|
846
|
-
name: "cuiqg/toml",
|
|
847
|
-
files,
|
|
848
|
-
plugins: { toml: pluginToml },
|
|
849
|
-
languageOptions: { parser: parserToml },
|
|
850
|
-
rules: { ...pluginToml.configs.recommended.rules }
|
|
851
|
-
}];
|
|
852
|
-
};
|
|
585
|
+
}
|
|
853
586
|
|
|
854
587
|
//#endregion
|
|
855
|
-
//#region src/configs/typescript.
|
|
856
|
-
/**
|
|
857
|
-
* TypeScript
|
|
858
|
-
*
|
|
859
|
-
* @see https://typescript-eslint.io/
|
|
860
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
861
|
-
*/
|
|
588
|
+
//#region src/configs/typescript.ts
|
|
862
589
|
async function typescript() {
|
|
863
590
|
const files = [GLOB_TS, GLOB_TSX];
|
|
864
591
|
const [pluginTs, parserTs] = await Promise.all([interopDefault(import("@typescript-eslint/eslint-plugin")), interopDefault(import("@typescript-eslint/parser"))]);
|
|
865
592
|
return [{
|
|
866
593
|
files,
|
|
594
|
+
name: "cuiqg/typescript/setup",
|
|
595
|
+
plugins: { ts: pluginTs },
|
|
867
596
|
languageOptions: {
|
|
868
597
|
parser: parserTs,
|
|
869
|
-
parserOptions: { sourceType: "module" }
|
|
870
|
-
},
|
|
871
|
-
name: "cuiqg/typescript",
|
|
872
|
-
plugins: { "ts": pluginTs },
|
|
873
|
-
rules: { ...renameRules(pluginTs.configs["flat/recommended"].rules, { "@typescript-eslint": "ts" }) }
|
|
874
|
-
}];
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
//#endregion
|
|
878
|
-
//#region src/configs/unicorn.js
|
|
879
|
-
/**
|
|
880
|
-
* Unicorn
|
|
881
|
-
*
|
|
882
|
-
* @see https://github.com/sindresorhus/eslint-plugin-unicorn
|
|
883
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
884
|
-
*/
|
|
885
|
-
const unicorn = async () => {
|
|
886
|
-
const pluginUnicorn = await interopDefault(import("eslint-plugin-unicorn"));
|
|
887
|
-
return [{
|
|
888
|
-
name: "cuiqg/unicorn",
|
|
889
|
-
plugins: { unicorn: pluginUnicorn },
|
|
890
|
-
rules: {
|
|
891
|
-
"unicorn/consistent-empty-array-spread": "error",
|
|
892
|
-
"unicorn/error-message": "error",
|
|
893
|
-
"unicorn/escape-case": "error",
|
|
894
|
-
"unicorn/new-for-builtins": "error",
|
|
895
|
-
"unicorn/no-new-array": "error",
|
|
896
|
-
"unicorn/no-new-buffer": "error",
|
|
897
|
-
"unicorn/number-literal-case": "error",
|
|
898
|
-
"unicorn/prefer-dom-node-text-content": "error",
|
|
899
|
-
"unicorn/prefer-includes": "error",
|
|
900
|
-
"unicorn/prefer-node-protocol": "error",
|
|
901
|
-
"unicorn/prefer-number-properties": "error",
|
|
902
|
-
"unicorn/prefer-string-starts-ends-with": "error",
|
|
903
|
-
"unicorn/prefer-type-error": "error",
|
|
904
|
-
"unicorn/throw-new-error": "error"
|
|
905
|
-
}
|
|
906
|
-
}];
|
|
907
|
-
};
|
|
908
|
-
|
|
909
|
-
//#endregion
|
|
910
|
-
//#region src/configs/unocss.js
|
|
911
|
-
/**
|
|
912
|
-
* UnoCSS
|
|
913
|
-
*
|
|
914
|
-
* @see https://unocss.dev/integrations/eslint
|
|
915
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
916
|
-
*/
|
|
917
|
-
const unocss = async () => {
|
|
918
|
-
const pluginUnoCSS = await interopDefault(import("@unocss/eslint-plugin"));
|
|
919
|
-
return [{
|
|
920
|
-
...pluginUnoCSS.configs.flat,
|
|
921
|
-
name: "cuiqg/unocss"
|
|
922
|
-
}];
|
|
923
|
-
};
|
|
924
|
-
|
|
925
|
-
//#endregion
|
|
926
|
-
//#region src/configs/unplugin.js
|
|
927
|
-
/**
|
|
928
|
-
* UnPlugin
|
|
929
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
930
|
-
*/
|
|
931
|
-
const unplugin = async () => {
|
|
932
|
-
const resolved = resolve(process.cwd(), `./.eslintrc-auto-import.json`);
|
|
933
|
-
let globals$1 = {};
|
|
934
|
-
if (fs.existsSync(resolved) && fs.statSync(resolved).isFile) {
|
|
935
|
-
const cwd = dirname(resolved);
|
|
936
|
-
const { config } = await loadConfig({
|
|
937
|
-
sources: [{
|
|
938
|
-
files: resolved,
|
|
939
|
-
extensions: [],
|
|
940
|
-
rewrite(config$1) {
|
|
941
|
-
return config$1?.globals;
|
|
942
|
-
}
|
|
943
|
-
}],
|
|
944
|
-
cwd
|
|
945
|
-
});
|
|
946
|
-
globals$1 = { ...config };
|
|
947
|
-
}
|
|
948
|
-
return [{
|
|
949
|
-
name: "cuiqg/unplugin/auto-import",
|
|
950
|
-
languageOptions: { globals: globals$1 }
|
|
951
|
-
}];
|
|
952
|
-
};
|
|
953
|
-
|
|
954
|
-
//#endregion
|
|
955
|
-
//#region src/configs/vue.js
|
|
956
|
-
/**
|
|
957
|
-
* Vue
|
|
958
|
-
*
|
|
959
|
-
* @see https://eslint.vuejs.org/
|
|
960
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
961
|
-
*/
|
|
962
|
-
const vue = async () => {
|
|
963
|
-
const files = [GLOB_VUE];
|
|
964
|
-
const [pluginVue, parserVue] = await Promise.all([interopDefault(import("eslint-plugin-vue")), interopDefault(import("vue-eslint-parser"))]);
|
|
965
|
-
return [{
|
|
966
|
-
files,
|
|
967
|
-
languageOptions: {
|
|
968
|
-
globals: {
|
|
969
|
-
computed: "readonly",
|
|
970
|
-
defineModel: "readonly",
|
|
971
|
-
defineOptions: "readonly",
|
|
972
|
-
defineProps: "readonly",
|
|
973
|
-
defineRender: "readonly",
|
|
974
|
-
defineSlots: "readonly",
|
|
975
|
-
defineEmits: "readonly",
|
|
976
|
-
defineExpose: "readonly",
|
|
977
|
-
definePage: "readonly",
|
|
978
|
-
onMounted: "readonly",
|
|
979
|
-
onUnmounted: "readonly",
|
|
980
|
-
onActivated: "readonly",
|
|
981
|
-
onDeactivated: "readonly",
|
|
982
|
-
reactive: "readonly",
|
|
983
|
-
ref: "readonly",
|
|
984
|
-
shallowReactive: "readonly",
|
|
985
|
-
shallowRef: "readonly",
|
|
986
|
-
toRef: "readonly",
|
|
987
|
-
toRefs: "readonly",
|
|
988
|
-
watch: "readonly",
|
|
989
|
-
watchEffect: "readonly"
|
|
990
|
-
},
|
|
991
|
-
parser: parserVue,
|
|
992
598
|
parserOptions: {
|
|
993
599
|
ecmaFeatures: { jsx: true },
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
sourceType: "module"
|
|
600
|
+
ecmaVersion: "latest",
|
|
601
|
+
projectService: true,
|
|
602
|
+
sourceType: "module",
|
|
603
|
+
tsconfigRootDir: process.cwd()
|
|
997
604
|
}
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
processor: pluginVue.processors[".vue"],
|
|
605
|
+
}
|
|
606
|
+
}, {
|
|
607
|
+
name: "cuiqg/typescript/rules",
|
|
1002
608
|
rules: {
|
|
1003
|
-
...
|
|
1004
|
-
...
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
"
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
"vue/component-tags-order": "off",
|
|
1016
|
-
"vue/custom-event-name-casing": ["error", "camelCase"],
|
|
1017
|
-
"vue/define-macros-order": ["error", { order: [
|
|
1018
|
-
"defineOptions",
|
|
1019
|
-
"defineProps",
|
|
1020
|
-
"defineEmits",
|
|
1021
|
-
"defineSlots"
|
|
1022
|
-
] }],
|
|
1023
|
-
"vue/dot-location": ["error", "property"],
|
|
1024
|
-
"vue/dot-notation": ["error", { allowKeywords: true }],
|
|
1025
|
-
"vue/eqeqeq": ["error", "smart"],
|
|
1026
|
-
"vue/html-indent": ["error", 2],
|
|
1027
|
-
"vue/html-quotes": ["error", "double"],
|
|
1028
|
-
"vue/max-attributes-per-line": ["error", {
|
|
1029
|
-
singleline: { max: 1 },
|
|
1030
|
-
multiline: { max: 1 }
|
|
1031
|
-
}],
|
|
1032
|
-
"vue/multi-word-component-names": "off",
|
|
1033
|
-
"vue/no-dupe-keys": "off",
|
|
1034
|
-
"vue/no-empty-pattern": "error",
|
|
1035
|
-
"vue/no-irregular-whitespace": "error",
|
|
1036
|
-
"vue/no-loss-of-precision": "error",
|
|
1037
|
-
"vue/no-restricted-syntax": [
|
|
1038
|
-
"error",
|
|
1039
|
-
"DebuggerStatement",
|
|
1040
|
-
"LabeledStatement",
|
|
1041
|
-
"WithStatement"
|
|
1042
|
-
],
|
|
1043
|
-
"vue/no-restricted-v-bind": ["error", "/^v-/"],
|
|
1044
|
-
"vue/no-setup-props-reactivity-loss": "off",
|
|
1045
|
-
"vue/no-sparse-arrays": "error",
|
|
1046
|
-
"vue/no-unused-refs": "error",
|
|
1047
|
-
"vue/no-useless-v-bind": "error",
|
|
1048
|
-
"vue/no-v-html": "off",
|
|
1049
|
-
"vue/object-shorthand": [
|
|
1050
|
-
"error",
|
|
1051
|
-
"always",
|
|
1052
|
-
{
|
|
1053
|
-
avoidQuotes: true,
|
|
1054
|
-
ignoreConstructors: false
|
|
1055
|
-
}
|
|
1056
|
-
],
|
|
1057
|
-
"vue/prefer-separate-static-class": "error",
|
|
1058
|
-
"vue/prefer-template": "error",
|
|
1059
|
-
"vue/prop-name-casing": ["error", "camelCase"],
|
|
1060
|
-
"vue/require-default-prop": "off",
|
|
1061
|
-
"vue/require-prop-types": "off",
|
|
1062
|
-
"vue/space-infix-ops": "error",
|
|
1063
|
-
"vue/space-unary-ops": ["error", {
|
|
1064
|
-
nonwords: false,
|
|
1065
|
-
words: true
|
|
1066
|
-
}],
|
|
1067
|
-
"vue/array-bracket-spacing": ["error", "never"],
|
|
1068
|
-
"vue/arrow-spacing": ["error", {
|
|
1069
|
-
after: true,
|
|
1070
|
-
before: true
|
|
1071
|
-
}],
|
|
1072
|
-
"vue/block-spacing": ["error", "always"],
|
|
1073
|
-
"vue/block-tag-newline": ["error", {
|
|
1074
|
-
multiline: "always",
|
|
1075
|
-
singleline: "always"
|
|
1076
|
-
}],
|
|
1077
|
-
"vue/brace-style": [
|
|
1078
|
-
"error",
|
|
1079
|
-
"stroustrup",
|
|
1080
|
-
{ allowSingleLine: true }
|
|
1081
|
-
],
|
|
1082
|
-
"vue/comma-dangle": ["error", "always-multiline"],
|
|
1083
|
-
"vue/comma-spacing": ["error", {
|
|
1084
|
-
after: true,
|
|
1085
|
-
before: false
|
|
609
|
+
...renameRules(pluginTs.configs["eslint-recommended"].overrides[0].rules, { "@typescript-eslint": "ts" }),
|
|
610
|
+
...renameRules(pluginTs.configs.strict.rules, { "@typescript-eslint": "ts" }),
|
|
611
|
+
"no-dupe-class-members": "off",
|
|
612
|
+
"no-redeclare": "off",
|
|
613
|
+
"no-use-before-define": "off",
|
|
614
|
+
"no-useless-constructor": "off",
|
|
615
|
+
"ts/ban-ts-comment": ["error", { "ts-expect-error": "allow-with-description" }],
|
|
616
|
+
"ts/consistent-type-definitions": ["error", "interface"],
|
|
617
|
+
"ts/consistent-type-imports": ["error", {
|
|
618
|
+
disallowTypeAnnotations: false,
|
|
619
|
+
fixStyle: "separate-type-imports",
|
|
620
|
+
prefer: "type-imports"
|
|
1086
621
|
}],
|
|
1087
|
-
"
|
|
1088
|
-
"
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
"
|
|
1094
|
-
|
|
1095
|
-
|
|
622
|
+
"ts/method-signature-style": ["error", "property"],
|
|
623
|
+
"ts/no-dupe-class-members": "error",
|
|
624
|
+
"ts/no-dynamic-delete": "off",
|
|
625
|
+
"ts/no-empty-object-type": ["error", { allowInterfaces: "always" }],
|
|
626
|
+
"ts/no-explicit-any": "off",
|
|
627
|
+
"ts/no-extraneous-class": "off",
|
|
628
|
+
"ts/no-import-type-side-effects": "error",
|
|
629
|
+
"ts/no-invalid-void-type": "off",
|
|
630
|
+
"ts/no-non-null-assertion": "off",
|
|
631
|
+
"ts/no-redeclare": ["error", { builtinGlobals: false }],
|
|
632
|
+
"ts/no-require-imports": "error",
|
|
633
|
+
"ts/no-unused-expressions": ["error", {
|
|
634
|
+
allowShortCircuit: true,
|
|
635
|
+
allowTaggedTemplates: true,
|
|
636
|
+
allowTernary: true
|
|
1096
637
|
}],
|
|
1097
|
-
"
|
|
1098
|
-
|
|
1099
|
-
|
|
638
|
+
"ts/no-unused-vars": "off",
|
|
639
|
+
"ts/no-use-before-define": ["error", {
|
|
640
|
+
classes: false,
|
|
641
|
+
functions: false,
|
|
642
|
+
variables: true
|
|
1100
643
|
}],
|
|
1101
|
-
"
|
|
1102
|
-
"
|
|
1103
|
-
"
|
|
1104
|
-
"
|
|
1105
|
-
"vue/padding-line-between-blocks": ["error", "always"],
|
|
1106
|
-
"vue/quote-props": ["error", "consistent-as-needed"],
|
|
1107
|
-
"vue/space-in-parens": ["error", "never"],
|
|
1108
|
-
"vue/template-curly-spacing": "error",
|
|
1109
|
-
"vue/no-export-in-script-setup": "off",
|
|
1110
|
-
"vue/valid-attribute-name": "off",
|
|
1111
|
-
"vue/valid-define-props": "off",
|
|
1112
|
-
"vue/valid-v-bind": "off",
|
|
1113
|
-
"vue/no-unused-vars": "off"
|
|
644
|
+
"ts/no-useless-constructor": "off",
|
|
645
|
+
"ts/no-wrapper-object-types": "error",
|
|
646
|
+
"ts/triple-slash-reference": "off",
|
|
647
|
+
"ts/unified-signatures": "off"
|
|
1114
648
|
}
|
|
1115
649
|
}];
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
//#endregion
|
|
1119
|
-
//#region src/configs/yaml.js
|
|
1120
|
-
/**
|
|
1121
|
-
* Yaml
|
|
1122
|
-
*
|
|
1123
|
-
* @see https://ota-meshi.github.io/eslint-plugin-yml/
|
|
1124
|
-
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
1125
|
-
*/
|
|
1126
|
-
const yaml = async () => {
|
|
1127
|
-
const files = [GLOB_YAML];
|
|
1128
|
-
const [pluginYaml, parserYaml] = await Promise.all([interopDefault(import("eslint-plugin-yml")), interopDefault(import("yaml-eslint-parser"))]);
|
|
1129
|
-
return [{
|
|
1130
|
-
name: "cuiqg/yaml",
|
|
1131
|
-
files,
|
|
1132
|
-
plugins: { yaml: pluginYaml },
|
|
1133
|
-
languageOptions: { parser: parserYaml },
|
|
1134
|
-
rules: {
|
|
1135
|
-
...pluginYaml.configs.recommended.rules,
|
|
1136
|
-
...pluginYaml.configs.prettier.rules
|
|
1137
|
-
}
|
|
1138
|
-
}];
|
|
1139
|
-
};
|
|
650
|
+
}
|
|
1140
651
|
|
|
1141
652
|
//#endregion
|
|
1142
|
-
//#region src/presets.
|
|
653
|
+
//#region src/presets.ts
|
|
1143
654
|
const defaultPluginRenaming = {
|
|
1144
|
-
"@
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
655
|
+
"@next/next": "next",
|
|
656
|
+
n: "node",
|
|
657
|
+
vitest: "test",
|
|
658
|
+
yml: "yaml",
|
|
659
|
+
"@typescript-eslint": "ts"
|
|
1148
660
|
};
|
|
1149
661
|
function cuiqg(options = {}, ...userConfigs) {
|
|
1150
|
-
const { prettier: enablePrettier = false,
|
|
662
|
+
const { prettier: enablePrettier = false, typescript: enableTypeScript = hasTypeScript(), vue: enableVue = hasVue(), unocss: enableUnocss = hasUnoCss(), nextjs: enableNextjs = hasNextjs() } = options;
|
|
1151
663
|
const configs = [
|
|
1152
|
-
|
|
664
|
+
packageJson(),
|
|
1153
665
|
ignores(),
|
|
1154
|
-
javascript(),
|
|
1155
|
-
comments(),
|
|
1156
666
|
node(),
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
macros(),
|
|
1160
|
-
jsonc(),
|
|
1161
|
-
sortPackageJson(),
|
|
1162
|
-
sortJsconfig(),
|
|
1163
|
-
yaml(),
|
|
1164
|
-
toml(),
|
|
1165
|
-
disables()
|
|
667
|
+
deMorgan(),
|
|
668
|
+
javascript()
|
|
1166
669
|
];
|
|
1167
|
-
if (
|
|
1168
|
-
if (enableStylistic) configs.push(stylistic());
|
|
670
|
+
if (enableTypeScript) configs.push(typescript());
|
|
1169
671
|
if (enableVue) configs.push(vue());
|
|
1170
672
|
if (enableUnocss) configs.push(unocss());
|
|
673
|
+
if (enableNextjs) configs.push(nextjs());
|
|
1171
674
|
if (enablePrettier) configs.push(prettier());
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
if (
|
|
1175
|
-
|
|
1176
|
-
|
|
675
|
+
let composer = new FlatConfigComposer();
|
|
676
|
+
composer = composer.append(...configs, ...userConfigs).renamePlugins(defaultPluginRenaming);
|
|
677
|
+
if (isInEditor()) composer = composer.disableRulesFix([
|
|
678
|
+
"unused-imports/no-unused-imports",
|
|
679
|
+
"test/no-only-tests",
|
|
680
|
+
"prefer-const"
|
|
681
|
+
], { builtinRules: () => import(["eslint", "use-at-your-own-risk"].join("/")).then((r) => r.builtinRules) });
|
|
1177
682
|
return composer;
|
|
1178
683
|
}
|
|
1179
684
|
|
|
1180
685
|
//#endregion
|
|
1181
|
-
//#region src/index.
|
|
686
|
+
//#region src/index.ts
|
|
1182
687
|
var src_default = cuiqg;
|
|
1183
688
|
|
|
1184
689
|
//#endregion
|
|
1185
|
-
export { GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVG, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_XML, GLOB_YAML,
|
|
690
|
+
export { GLOB_ALL_SRC, GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_STYLUS, GLOB_SVG, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_XML, GLOB_YAML, cuiqg, deMorgan, src_default as default, defaultPluginRenaming, hasNextjs, hasTypeScript, hasUnoCss, hasVue, ignores, isInEditor, isInGitHookOrLintStaged, javascript, nextjs, node, packageJson, prettier, typescript, unocss, vue };
|