@lincy/eslint-config 6.5.2 → 7.1.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/README.md +1 -0
- package/dist/index.cjs +178 -275
- package/dist/index.d.cts +1694 -2150
- package/dist/index.d.mts +1693 -2149
- package/dist/index.mjs +153 -249
- package/package.json +46 -42
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import fs$1 from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { getPackageInfoSync, isPackageExists } from "local-pkg";
|
|
8
|
+
import pluginE18e from "@e18e/eslint-plugin";
|
|
8
9
|
import pluginComments from "@eslint-community/eslint-plugin-eslint-comments";
|
|
9
10
|
import pluginAntfu from "eslint-plugin-antfu";
|
|
10
11
|
import pluginImportLite from "eslint-plugin-import-lite";
|
|
@@ -15,7 +16,6 @@ import pluginUnusedImports from "eslint-plugin-unused-imports";
|
|
|
15
16
|
import globals from "globals";
|
|
16
17
|
import { mergeProcessors, processorPassThrough } from "eslint-merge-processors";
|
|
17
18
|
import { configs } from "eslint-plugin-regexp";
|
|
18
|
-
|
|
19
19
|
//#region node_modules/.pnpm/find-up-simple@1.0.1/node_modules/find-up-simple/index.js
|
|
20
20
|
const toPath = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
21
21
|
async function findUp(name, { cwd = process.cwd(), type = "file", stopAt } = {}) {
|
|
@@ -48,7 +48,6 @@ function findUpSync(name, { cwd = process.cwd(), type = "file", stopAt } = {}) {
|
|
|
48
48
|
directory = path.dirname(directory);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
|
|
52
51
|
//#endregion
|
|
53
52
|
//#region src/configs/comments.ts
|
|
54
53
|
async function comments(options = {}) {
|
|
@@ -65,7 +64,6 @@ async function comments(options = {}) {
|
|
|
65
64
|
}
|
|
66
65
|
}];
|
|
67
66
|
}
|
|
68
|
-
|
|
69
67
|
//#endregion
|
|
70
68
|
//#region src/globs.ts
|
|
71
69
|
const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
|
|
@@ -84,7 +82,6 @@ const GLOB_JSON5 = "**/*.json5";
|
|
|
84
82
|
const GLOB_JSONC = "**/*.jsonc";
|
|
85
83
|
const GLOB_MARKDOWN = "**/*.md";
|
|
86
84
|
const GLOB_MARKDOWN_IN_MARKDOWN = "**/*.md/*.md";
|
|
87
|
-
const GLOB_SVELTE = "**/*.svelte";
|
|
88
85
|
const GLOB_VUE = "**/*.vue";
|
|
89
86
|
const GLOB_YAML = "**/*.y?(a)ml";
|
|
90
87
|
const GLOB_TOML = "**/*.toml";
|
|
@@ -96,7 +93,9 @@ const GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
|
|
|
96
93
|
const GLOB_TESTS = [
|
|
97
94
|
`**/__tests__/**/*.${GLOB_SRC_EXT}`,
|
|
98
95
|
`**/*.spec.${GLOB_SRC_EXT}`,
|
|
99
|
-
`**/*.test.${GLOB_SRC_EXT}
|
|
96
|
+
`**/*.test.${GLOB_SRC_EXT}`,
|
|
97
|
+
`**/*.bench.${GLOB_SRC_EXT}`,
|
|
98
|
+
`**/*.benchmark.${GLOB_SRC_EXT}`
|
|
100
99
|
];
|
|
101
100
|
const GLOB_ALL_SRC = [
|
|
102
101
|
GLOB_SRC,
|
|
@@ -104,9 +103,9 @@ const GLOB_ALL_SRC = [
|
|
|
104
103
|
GLOB_JSON,
|
|
105
104
|
GLOB_JSON5,
|
|
106
105
|
GLOB_MARKDOWN,
|
|
107
|
-
GLOB_SVELTE,
|
|
108
106
|
GLOB_VUE,
|
|
109
107
|
GLOB_YAML,
|
|
108
|
+
GLOB_XML,
|
|
110
109
|
GLOB_HTML
|
|
111
110
|
];
|
|
112
111
|
const GLOB_EXCLUDE = [
|
|
@@ -115,12 +114,13 @@ const GLOB_EXCLUDE = [
|
|
|
115
114
|
"**/package-lock.json",
|
|
116
115
|
"**/yarn.lock",
|
|
117
116
|
"**/pnpm-lock.yaml",
|
|
117
|
+
"**/bun.lockb",
|
|
118
118
|
"**/output",
|
|
119
119
|
"**/coverage",
|
|
120
|
-
"**/tmp",
|
|
121
120
|
"**/temp",
|
|
122
|
-
"**/.tmp",
|
|
123
121
|
"**/.temp",
|
|
122
|
+
"**/tmp",
|
|
123
|
+
"**/.tmp",
|
|
124
124
|
"**/.history",
|
|
125
125
|
"**/.vitepress/cache",
|
|
126
126
|
"**/.nuxt",
|
|
@@ -128,18 +128,22 @@ const GLOB_EXCLUDE = [
|
|
|
128
128
|
"**/.vercel",
|
|
129
129
|
"**/.changeset",
|
|
130
130
|
"**/.idea",
|
|
131
|
+
"**/.cache",
|
|
131
132
|
"**/.output",
|
|
132
133
|
"**/.vite-inspect",
|
|
133
134
|
"**/.yarn",
|
|
134
|
-
"**/vite.config.*.timestamp-*",
|
|
135
135
|
"**/CHANGELOG*.md",
|
|
136
|
-
"**/*.min.*",
|
|
137
136
|
"**/LICENSE*",
|
|
137
|
+
"**/*.min.*",
|
|
138
138
|
"**/__snapshots__",
|
|
139
|
+
"**/vite.config.*.timestamp-*",
|
|
139
140
|
"**/auto-import?(s).d.ts",
|
|
140
|
-
"**/components.d.ts"
|
|
141
|
+
"**/components.d.ts",
|
|
142
|
+
"**/.context",
|
|
143
|
+
"**/.claude",
|
|
144
|
+
"**/.agents",
|
|
145
|
+
"**/.*/skills"
|
|
141
146
|
];
|
|
142
|
-
|
|
143
147
|
//#endregion
|
|
144
148
|
//#region src/configs/disables.ts
|
|
145
149
|
async function disables() {
|
|
@@ -195,7 +199,29 @@ async function disables() {
|
|
|
195
199
|
}
|
|
196
200
|
];
|
|
197
201
|
}
|
|
198
|
-
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/configs/e18e.ts
|
|
204
|
+
async function e18e(options = {}) {
|
|
205
|
+
const { isInEditor = false, modernization = true, type = "app", moduleReplacements = type === "lib" && isInEditor, overrides = {}, performanceImprovements = true } = options;
|
|
206
|
+
const configs = pluginE18e.configs;
|
|
207
|
+
return [{
|
|
208
|
+
name: "eslint/e18e/rules",
|
|
209
|
+
plugins: { e18e: pluginE18e },
|
|
210
|
+
rules: {
|
|
211
|
+
...modernization ? { ...configs.modernization.rules } : {},
|
|
212
|
+
...moduleReplacements ? { ...configs.moduleReplacements.rules } : {},
|
|
213
|
+
...performanceImprovements ? { ...configs.performanceImprovements.rules } : {},
|
|
214
|
+
...type === "lib" ? {} : { "e18e/prefer-static-regex": "off" },
|
|
215
|
+
"e18e/prefer-array-at": "off",
|
|
216
|
+
"e18e/prefer-array-from-map": "off",
|
|
217
|
+
"e18e/prefer-array-to-reversed": "off",
|
|
218
|
+
"e18e/prefer-array-to-sorted": "off",
|
|
219
|
+
"e18e/prefer-array-to-spliced": "off",
|
|
220
|
+
"e18e/prefer-spread-syntax": "off",
|
|
221
|
+
...overrides
|
|
222
|
+
}
|
|
223
|
+
}];
|
|
224
|
+
}
|
|
199
225
|
//#endregion
|
|
200
226
|
//#region src/utils.ts
|
|
201
227
|
const scopeUrl = fileURLToPath(new URL(".", import.meta.url));
|
|
@@ -222,8 +248,8 @@ const parserPlain = {
|
|
|
222
248
|
/**
|
|
223
249
|
* Combine array and non-array configs into a single array.
|
|
224
250
|
*/
|
|
225
|
-
async function combine(...configs
|
|
226
|
-
return (await Promise.all(configs
|
|
251
|
+
async function combine(...configs) {
|
|
252
|
+
return (await Promise.all(configs)).flat();
|
|
227
253
|
}
|
|
228
254
|
function renameRules(rules, map) {
|
|
229
255
|
return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
|
|
@@ -231,8 +257,8 @@ function renameRules(rules, map) {
|
|
|
231
257
|
return [key, value];
|
|
232
258
|
}));
|
|
233
259
|
}
|
|
234
|
-
function renamePluginInConfigs(configs
|
|
235
|
-
return configs
|
|
260
|
+
function renamePluginInConfigs(configs, map) {
|
|
261
|
+
return configs.map((i) => {
|
|
236
262
|
const clone = { ...i };
|
|
237
263
|
if (clone.rules) clone.rules = renameRules(clone.rules, map);
|
|
238
264
|
if (clone.plugins) clone.plugins = Object.fromEntries(Object.entries(clone.plugins).map(([key, value]) => {
|
|
@@ -266,26 +292,26 @@ function isInEditorEnv() {
|
|
|
266
292
|
function isInGitHooksOrLintStaged() {
|
|
267
293
|
return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged"));
|
|
268
294
|
}
|
|
269
|
-
|
|
270
295
|
//#endregion
|
|
271
296
|
//#region src/configs/stylistic.ts
|
|
272
297
|
const StylisticConfigDefaults = {
|
|
273
298
|
indent: 4,
|
|
274
299
|
jsx: true,
|
|
275
300
|
lessOpinionated: false,
|
|
301
|
+
other_indent: 2,
|
|
276
302
|
quotes: "single",
|
|
277
303
|
semi: false
|
|
278
304
|
};
|
|
279
305
|
async function stylistic(options = {}) {
|
|
280
|
-
const { overrides = {}, stylistic
|
|
281
|
-
const { indent, jsx
|
|
306
|
+
const { overrides = {}, stylistic = StylisticConfigDefaults } = options;
|
|
307
|
+
const { indent, jsx, lessOpinionated, quotes, semi } = typeof stylistic === "boolean" ? StylisticConfigDefaults : {
|
|
282
308
|
...StylisticConfigDefaults,
|
|
283
|
-
...stylistic
|
|
309
|
+
...stylistic
|
|
284
310
|
};
|
|
285
311
|
const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
|
|
286
312
|
const config = pluginStylistic.configs.customize({
|
|
287
313
|
indent,
|
|
288
|
-
jsx
|
|
314
|
+
jsx,
|
|
289
315
|
pluginName: "style",
|
|
290
316
|
quotes,
|
|
291
317
|
semi
|
|
@@ -319,7 +345,6 @@ async function stylistic(options = {}) {
|
|
|
319
345
|
}
|
|
320
346
|
}];
|
|
321
347
|
}
|
|
322
|
-
|
|
323
348
|
//#endregion
|
|
324
349
|
//#region src/configs/formatters.ts
|
|
325
350
|
function mergePrettierOptions(options, overrides) {
|
|
@@ -329,18 +354,18 @@ function mergePrettierOptions(options, overrides) {
|
|
|
329
354
|
plugins: [...overrides.plugins || [], ...options.plugins || []]
|
|
330
355
|
};
|
|
331
356
|
}
|
|
332
|
-
async function formatters(options = {}, stylistic
|
|
357
|
+
async function formatters(options = {}, stylistic = {}) {
|
|
333
358
|
const defaultIndent = 4;
|
|
334
359
|
const isPrettierPluginXmlInScope = isPackageInScope("@prettier/plugin-xml");
|
|
335
360
|
if (options === true) {
|
|
336
|
-
const isPrettierPluginXmlInScope
|
|
361
|
+
const isPrettierPluginXmlInScope = isPackageInScope("@prettier/plugin-xml");
|
|
337
362
|
options = {
|
|
338
363
|
css: false,
|
|
339
364
|
graphql: true,
|
|
340
365
|
html: true,
|
|
341
366
|
markdown: true,
|
|
342
|
-
svg: isPrettierPluginXmlInScope
|
|
343
|
-
xml: isPrettierPluginXmlInScope
|
|
367
|
+
svg: isPrettierPluginXmlInScope,
|
|
368
|
+
xml: isPrettierPluginXmlInScope
|
|
344
369
|
};
|
|
345
370
|
} else options = {
|
|
346
371
|
css: options.css ?? false,
|
|
@@ -353,7 +378,7 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
353
378
|
await ensurePackages(["eslint-plugin-format", options.xml || options.svg ? "@prettier/plugin-xml" : void 0]);
|
|
354
379
|
const { indent, quotes, semi } = {
|
|
355
380
|
...StylisticConfigDefaults,
|
|
356
|
-
...stylistic
|
|
381
|
+
...stylistic
|
|
357
382
|
};
|
|
358
383
|
const prettierOptions = Object.assign({
|
|
359
384
|
endOfLine: "lf",
|
|
@@ -370,16 +395,17 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
370
395
|
xmlSortAttributesByKey: false,
|
|
371
396
|
xmlWhitespaceSensitivity: "ignore"
|
|
372
397
|
};
|
|
373
|
-
const dprintOptions =
|
|
398
|
+
const dprintOptions = {
|
|
374
399
|
indentWidth: typeof indent === "number" ? indent : defaultIndent,
|
|
375
400
|
quoteStyle: quotes === "single" ? "preferSingle" : "preferDouble",
|
|
376
|
-
useTabs: indent === "tab"
|
|
377
|
-
|
|
378
|
-
|
|
401
|
+
useTabs: indent === "tab",
|
|
402
|
+
...typeof options.dprintOptions === "boolean" ? {} : options.dprintOptions || {}
|
|
403
|
+
};
|
|
404
|
+
const configs = [{
|
|
379
405
|
name: "eslint/formatter/setup",
|
|
380
406
|
plugins: { format: await interopDefault(import("eslint-plugin-format")) }
|
|
381
407
|
}];
|
|
382
|
-
if (options.css) configs
|
|
408
|
+
if (options.css) configs.push({
|
|
383
409
|
files: [GLOB_CSS, GLOB_POSTCSS],
|
|
384
410
|
languageOptions: { parser: parserPlain },
|
|
385
411
|
name: "eslint/formatter/css",
|
|
@@ -395,13 +421,13 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
395
421
|
name: "eslint/formatter/less",
|
|
396
422
|
rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "less" })] }
|
|
397
423
|
});
|
|
398
|
-
if (options.html) configs
|
|
424
|
+
if (options.html) configs.push({
|
|
399
425
|
files: [GLOB_HTML],
|
|
400
426
|
languageOptions: { parser: parserPlain },
|
|
401
427
|
name: "eslint/formatter/html",
|
|
402
428
|
rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "html" })] }
|
|
403
429
|
});
|
|
404
|
-
if (options.xml) configs
|
|
430
|
+
if (options.xml) configs.push({
|
|
405
431
|
files: [GLOB_XML],
|
|
406
432
|
languageOptions: { parser: parserPlain },
|
|
407
433
|
name: "eslint/formatter/xml",
|
|
@@ -413,7 +439,7 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
413
439
|
plugins: ["@prettier/plugin-xml"]
|
|
414
440
|
})] }
|
|
415
441
|
});
|
|
416
|
-
if (options.svg) configs
|
|
442
|
+
if (options.svg) configs.push({
|
|
417
443
|
files: [GLOB_SVG],
|
|
418
444
|
languageOptions: { parser: parserPlain },
|
|
419
445
|
name: "eslint/formatter/svg",
|
|
@@ -427,7 +453,7 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
427
453
|
});
|
|
428
454
|
if (options.markdown) {
|
|
429
455
|
const formater = options.markdown === true ? "prettier" : options.markdown;
|
|
430
|
-
configs
|
|
456
|
+
configs.push({
|
|
431
457
|
files: [GLOB_MARKDOWN],
|
|
432
458
|
ignores: [],
|
|
433
459
|
languageOptions: { parser: parserPlain },
|
|
@@ -441,29 +467,30 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
441
467
|
}] }
|
|
442
468
|
});
|
|
443
469
|
}
|
|
444
|
-
if (options.graphql) configs
|
|
470
|
+
if (options.graphql) configs.push({
|
|
445
471
|
files: [GLOB_GRAPHQL],
|
|
446
472
|
languageOptions: { parser: parserPlain },
|
|
447
473
|
name: "eslint/formatter/graphql",
|
|
448
474
|
rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "graphql" })] }
|
|
449
475
|
});
|
|
450
|
-
return configs
|
|
476
|
+
return configs;
|
|
451
477
|
}
|
|
452
|
-
|
|
453
478
|
//#endregion
|
|
454
479
|
//#region src/configs/ignores.ts
|
|
455
|
-
async function ignores(
|
|
456
|
-
|
|
480
|
+
async function ignores(userIgnores = [], ignoreTypeScript = false) {
|
|
481
|
+
let ignores = [...GLOB_EXCLUDE];
|
|
482
|
+
if (ignoreTypeScript) ignores.push(GLOB_TS, GLOB_TSX);
|
|
483
|
+
if (typeof userIgnores === "function") ignores = userIgnores(ignores);
|
|
484
|
+
else ignores = [...ignores, ...userIgnores];
|
|
457
485
|
return [{
|
|
458
|
-
ignores
|
|
486
|
+
ignores,
|
|
459
487
|
name: "eslint/ignores"
|
|
460
488
|
}];
|
|
461
489
|
}
|
|
462
|
-
|
|
463
490
|
//#endregion
|
|
464
491
|
//#region src/configs/imports.ts
|
|
465
492
|
async function imports(options = {}) {
|
|
466
|
-
const { overrides = {}, stylistic
|
|
493
|
+
const { overrides = {}, stylistic = true } = options;
|
|
467
494
|
return [{
|
|
468
495
|
name: "eslint/imports/rules",
|
|
469
496
|
plugins: {
|
|
@@ -479,12 +506,11 @@ async function imports(options = {}) {
|
|
|
479
506
|
"import/no-duplicates": "error",
|
|
480
507
|
"import/no-mutable-exports": "error",
|
|
481
508
|
"import/no-named-default": "error",
|
|
482
|
-
...stylistic
|
|
509
|
+
...stylistic ? { "import/newline-after-import": ["error", { count: 1 }] } : {},
|
|
483
510
|
...overrides
|
|
484
511
|
}
|
|
485
512
|
}];
|
|
486
513
|
}
|
|
487
|
-
|
|
488
514
|
//#endregion
|
|
489
515
|
//#region src/configs/javascript.ts
|
|
490
516
|
async function javascript(options = {}) {
|
|
@@ -709,11 +735,10 @@ async function javascript(options = {}) {
|
|
|
709
735
|
}
|
|
710
736
|
}];
|
|
711
737
|
}
|
|
712
|
-
|
|
713
738
|
//#endregion
|
|
714
739
|
//#region src/configs/jsdoc.ts
|
|
715
740
|
async function jsdoc(options = {}) {
|
|
716
|
-
const { overrides = {}, stylistic
|
|
741
|
+
const { overrides = {}, stylistic = true } = options;
|
|
717
742
|
return [{
|
|
718
743
|
name: "eslint/jsdoc/setup",
|
|
719
744
|
plugins: { jsdoc: await interopDefault(import("eslint-plugin-jsdoc")) }
|
|
@@ -736,7 +761,7 @@ async function jsdoc(options = {}) {
|
|
|
736
761
|
"jsdoc/require-returns-check": "warn",
|
|
737
762
|
"jsdoc/require-returns-description": "warn",
|
|
738
763
|
"jsdoc/require-yields-check": "warn",
|
|
739
|
-
...stylistic
|
|
764
|
+
...stylistic ? {
|
|
740
765
|
"jsdoc/check-alignment": "warn",
|
|
741
766
|
"jsdoc/multiline-blocks": "warn"
|
|
742
767
|
} : {},
|
|
@@ -744,7 +769,6 @@ async function jsdoc(options = {}) {
|
|
|
744
769
|
}
|
|
745
770
|
}];
|
|
746
771
|
}
|
|
747
|
-
|
|
748
772
|
//#endregion
|
|
749
773
|
//#region src/configs/jsonc.ts
|
|
750
774
|
async function jsonc(options = {}) {
|
|
@@ -752,7 +776,8 @@ async function jsonc(options = {}) {
|
|
|
752
776
|
GLOB_JSON,
|
|
753
777
|
GLOB_JSON5,
|
|
754
778
|
GLOB_JSONC
|
|
755
|
-
], overrides = {}, stylistic
|
|
779
|
+
], overrides = {}, stylistic = true } = options;
|
|
780
|
+
const { other_indent = 2 } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
756
781
|
return [{
|
|
757
782
|
name: "eslint/jsonc/setup",
|
|
758
783
|
plugins: { jsonc: await interopDefault(import("eslint-plugin-jsonc")) }
|
|
@@ -787,11 +812,11 @@ async function jsonc(options = {}) {
|
|
|
787
812
|
"jsonc/space-unary-ops": "error",
|
|
788
813
|
"jsonc/valid-json-number": "error",
|
|
789
814
|
"jsonc/vue-custom-block/no-parsing-error": "error",
|
|
790
|
-
...stylistic
|
|
815
|
+
...stylistic ? {
|
|
791
816
|
"jsonc/array-bracket-spacing": ["error", "never"],
|
|
792
817
|
"jsonc/comma-dangle": ["error", "never"],
|
|
793
818
|
"jsonc/comma-style": ["error", "last"],
|
|
794
|
-
"jsonc/indent": ["error", 2],
|
|
819
|
+
"jsonc/indent": ["error", typeof other_indent === "number" ? other_indent : 2],
|
|
795
820
|
"jsonc/key-spacing": ["error", {
|
|
796
821
|
afterColon: true,
|
|
797
822
|
beforeColon: false
|
|
@@ -809,7 +834,6 @@ async function jsonc(options = {}) {
|
|
|
809
834
|
}
|
|
810
835
|
}];
|
|
811
836
|
}
|
|
812
|
-
|
|
813
837
|
//#endregion
|
|
814
838
|
//#region src/configs/jsx.ts
|
|
815
839
|
async function jsx() {
|
|
@@ -819,22 +843,21 @@ async function jsx() {
|
|
|
819
843
|
name: "eslint/jsx/setup"
|
|
820
844
|
}];
|
|
821
845
|
}
|
|
822
|
-
|
|
823
846
|
//#endregion
|
|
824
847
|
//#region src/configs/markdown.ts
|
|
825
848
|
async function markdown(options = {}) {
|
|
826
849
|
const { componentExts = [], files = [GLOB_MARKDOWN], gfm = true, overrides = {}, overridesMarkdown = {} } = options;
|
|
827
|
-
const markdown
|
|
850
|
+
const markdown = await interopDefault(import("@eslint/markdown"));
|
|
828
851
|
return [
|
|
829
852
|
{
|
|
830
853
|
name: "eslint/markdown/setup",
|
|
831
|
-
plugins: { markdown
|
|
854
|
+
plugins: { markdown }
|
|
832
855
|
},
|
|
833
856
|
{
|
|
834
857
|
files,
|
|
835
858
|
ignores: [GLOB_MARKDOWN_IN_MARKDOWN],
|
|
836
859
|
name: "eslint/markdown/processor",
|
|
837
|
-
processor: mergeProcessors([markdown
|
|
860
|
+
processor: mergeProcessors([markdown.processors.markdown, processorPassThrough])
|
|
838
861
|
},
|
|
839
862
|
{
|
|
840
863
|
files,
|
|
@@ -845,7 +868,8 @@ async function markdown(options = {}) {
|
|
|
845
868
|
files,
|
|
846
869
|
name: "eslint/markdown/rules",
|
|
847
870
|
rules: {
|
|
848
|
-
...markdown
|
|
871
|
+
...markdown.configs.recommended.at(0)?.rules,
|
|
872
|
+
"markdown/fenced-code-language": "off",
|
|
849
873
|
"markdown/no-missing-label-refs": "off",
|
|
850
874
|
...overridesMarkdown
|
|
851
875
|
}
|
|
@@ -871,7 +895,7 @@ async function markdown(options = {}) {
|
|
|
871
895
|
name: "eslint/markdown/disables/code",
|
|
872
896
|
rules: {
|
|
873
897
|
"antfu/no-top-level-await": "off",
|
|
874
|
-
"
|
|
898
|
+
"e18e/prefer-static-regex": "off",
|
|
875
899
|
"no-alert": "off",
|
|
876
900
|
"no-console": "off",
|
|
877
901
|
"no-labels": "off",
|
|
@@ -884,6 +908,7 @@ async function markdown(options = {}) {
|
|
|
884
908
|
"node/prefer-global/process": "off",
|
|
885
909
|
"style/comma-dangle": "off",
|
|
886
910
|
"style/eol-last": "off",
|
|
911
|
+
"style/padding-line-between-statements": "off",
|
|
887
912
|
"ts/consistent-type-imports": "off",
|
|
888
913
|
"ts/explicit-function-return-type": "off",
|
|
889
914
|
"ts/no-namespace": "off",
|
|
@@ -895,27 +920,11 @@ async function markdown(options = {}) {
|
|
|
895
920
|
"unicode-bom": "off",
|
|
896
921
|
"unused-imports/no-unused-imports": "off",
|
|
897
922
|
"unused-imports/no-unused-vars": "off",
|
|
898
|
-
"ts/await-thenable": "off",
|
|
899
|
-
"ts/dot-notation": "off",
|
|
900
|
-
"ts/no-floating-promises": "off",
|
|
901
|
-
"ts/no-for-in-array": "off",
|
|
902
|
-
"ts/no-implied-eval": "off",
|
|
903
|
-
"ts/no-misused-promises": "off",
|
|
904
|
-
"ts/no-unnecessary-type-assertion": "off",
|
|
905
|
-
"ts/no-unsafe-argument": "off",
|
|
906
|
-
"ts/no-unsafe-assignment": "off",
|
|
907
|
-
"ts/no-unsafe-call": "off",
|
|
908
|
-
"ts/no-unsafe-member-access": "off",
|
|
909
|
-
"ts/no-unsafe-return": "off",
|
|
910
|
-
"ts/restrict-plus-operands": "off",
|
|
911
|
-
"ts/restrict-template-expressions": "off",
|
|
912
|
-
"ts/unbound-method": "off",
|
|
913
923
|
...overrides
|
|
914
924
|
}
|
|
915
925
|
}
|
|
916
926
|
];
|
|
917
927
|
}
|
|
918
|
-
|
|
919
928
|
//#endregion
|
|
920
929
|
//#region src/configs/nextjs.ts
|
|
921
930
|
function normalizeRules(rules) {
|
|
@@ -948,7 +957,6 @@ async function nextjs(options = {}) {
|
|
|
948
957
|
settings: { react: { version: "detect" } }
|
|
949
958
|
}];
|
|
950
959
|
}
|
|
951
|
-
|
|
952
960
|
//#endregion
|
|
953
961
|
//#region src/configs/node.ts
|
|
954
962
|
async function node(options = {}) {
|
|
@@ -972,7 +980,6 @@ async function node(options = {}) {
|
|
|
972
980
|
}
|
|
973
981
|
}];
|
|
974
982
|
}
|
|
975
|
-
|
|
976
983
|
//#endregion
|
|
977
984
|
//#region src/configs/perfectionist.ts
|
|
978
985
|
/**
|
|
@@ -1028,14 +1035,13 @@ async function perfectionist(options = {}) {
|
|
|
1028
1035
|
}
|
|
1029
1036
|
}];
|
|
1030
1037
|
}
|
|
1031
|
-
|
|
1032
1038
|
//#endregion
|
|
1033
1039
|
//#region src/configs/pnpm.ts
|
|
1034
1040
|
async function detectCatalogUsage() {
|
|
1035
1041
|
const workspaceFile = await findUp("pnpm-workspace.yaml");
|
|
1036
1042
|
if (!workspaceFile) return false;
|
|
1037
|
-
const yaml
|
|
1038
|
-
return yaml
|
|
1043
|
+
const yaml = await fs.readFile(workspaceFile, "utf-8");
|
|
1044
|
+
return yaml.includes("catalog:") || yaml.includes("catalogs:");
|
|
1039
1045
|
}
|
|
1040
1046
|
async function pnpm(options) {
|
|
1041
1047
|
const [pluginPnpm, pluginYaml, yamlParser] = await Promise.all([
|
|
@@ -1043,9 +1049,9 @@ async function pnpm(options) {
|
|
|
1043
1049
|
interopDefault(import("eslint-plugin-yml")),
|
|
1044
1050
|
interopDefault(import("yaml-eslint-parser"))
|
|
1045
1051
|
]);
|
|
1046
|
-
const { catalogs = await detectCatalogUsage(), isInEditor = false, json = true, sort = true, yaml
|
|
1047
|
-
const configs
|
|
1048
|
-
if (json) configs
|
|
1052
|
+
const { catalogs = await detectCatalogUsage(), isInEditor = false, json = true, sort = true, yaml = true } = options;
|
|
1053
|
+
const configs = [];
|
|
1054
|
+
if (json) configs.push({
|
|
1049
1055
|
files: ["package.json", "**/package.json"],
|
|
1050
1056
|
language: "jsonc/x",
|
|
1051
1057
|
name: "eslint/pnpm/package-json",
|
|
@@ -1059,8 +1065,8 @@ async function pnpm(options) {
|
|
|
1059
1065
|
"pnpm/json-valid-catalog": ["error", { autofix: !isInEditor }]
|
|
1060
1066
|
}
|
|
1061
1067
|
});
|
|
1062
|
-
if (yaml
|
|
1063
|
-
configs
|
|
1068
|
+
if (yaml) {
|
|
1069
|
+
configs.push({
|
|
1064
1070
|
files: ["pnpm-workspace.yaml"],
|
|
1065
1071
|
languageOptions: { parser: yamlParser },
|
|
1066
1072
|
name: "eslint/pnpm/pnpm-workspace-yaml",
|
|
@@ -1074,7 +1080,7 @@ async function pnpm(options) {
|
|
|
1074
1080
|
"pnpm/yaml-no-unused-catalog-item": "error"
|
|
1075
1081
|
}
|
|
1076
1082
|
});
|
|
1077
|
-
if (sort) configs
|
|
1083
|
+
if (sort) configs.push({
|
|
1078
1084
|
files: ["pnpm-workspace.yaml"],
|
|
1079
1085
|
languageOptions: { parser: yamlParser },
|
|
1080
1086
|
name: "eslint/pnpm/pnpm-workspace-yaml-sort",
|
|
@@ -1153,9 +1159,8 @@ async function pnpm(options) {
|
|
|
1153
1159
|
] }
|
|
1154
1160
|
});
|
|
1155
1161
|
}
|
|
1156
|
-
return configs
|
|
1162
|
+
return configs;
|
|
1157
1163
|
}
|
|
1158
|
-
|
|
1159
1164
|
//#endregion
|
|
1160
1165
|
//#region src/configs/react.ts
|
|
1161
1166
|
const ReactRefreshAllowConstantExportPackages = ["vite"];
|
|
@@ -1172,24 +1177,12 @@ const ReactRouterPackages = [
|
|
|
1172
1177
|
"@react-router/dev"
|
|
1173
1178
|
];
|
|
1174
1179
|
const NextJsPackages = ["next"];
|
|
1175
|
-
const ReactCompilerPackages = ["babel-plugin-react-compiler"];
|
|
1176
1180
|
async function react(options = {}) {
|
|
1177
|
-
const { files = [GLOB_SRC], filesTypeAware = [GLOB_TS, GLOB_TSX], ignoresTypeAware = [`${GLOB_MARKDOWN}/**`], overrides = {},
|
|
1178
|
-
await ensurePackages([
|
|
1179
|
-
"@eslint-react/eslint-plugin",
|
|
1180
|
-
"eslint-plugin-react-hooks",
|
|
1181
|
-
"eslint-plugin-react-refresh"
|
|
1182
|
-
]);
|
|
1181
|
+
const { files = [GLOB_SRC], filesTypeAware = [GLOB_TS, GLOB_TSX], ignoresTypeAware = [`${GLOB_MARKDOWN}/**`], overrides = {}, tsconfigPath } = options;
|
|
1182
|
+
await ensurePackages(["@eslint-react/eslint-plugin", "eslint-plugin-react-refresh"]);
|
|
1183
1183
|
const isTypeAware = !!tsconfigPath;
|
|
1184
|
-
const typeAwareRules = {
|
|
1185
|
-
|
|
1186
|
-
"react/no-leaked-conditional-rendering": "warn"
|
|
1187
|
-
};
|
|
1188
|
-
const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all([
|
|
1189
|
-
interopDefault(import("@eslint-react/eslint-plugin")),
|
|
1190
|
-
interopDefault(import("eslint-plugin-react-hooks")),
|
|
1191
|
-
interopDefault(import("eslint-plugin-react-refresh"))
|
|
1192
|
-
]);
|
|
1184
|
+
const typeAwareRules = { "react/no-leaked-conditional-rendering": "error" };
|
|
1185
|
+
const [pluginReact, pluginReactRefresh] = await Promise.all([interopDefault(import("@eslint-react/eslint-plugin")), interopDefault(import("eslint-plugin-react-refresh"))]);
|
|
1193
1186
|
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((i) => isPackageExists(i));
|
|
1194
1187
|
const isUsingRemix = RemixPackages.some((i) => isPackageExists(i));
|
|
1195
1188
|
const isUsingReactRouter = ReactRouterPackages.some((i) => isPackageExists(i));
|
|
@@ -1201,8 +1194,6 @@ async function react(options = {}) {
|
|
|
1201
1194
|
plugins: {
|
|
1202
1195
|
"react": plugins["@eslint-react"],
|
|
1203
1196
|
"react-dom": plugins["@eslint-react/dom"],
|
|
1204
|
-
"react-hooks": pluginReactHooks,
|
|
1205
|
-
"react-hooks-extra": plugins["@eslint-react/hooks-extra"],
|
|
1206
1197
|
"react-naming-convention": plugins["@eslint-react/naming-convention"],
|
|
1207
1198
|
"react-refresh": pluginReactRefresh,
|
|
1208
1199
|
"react-rsc": plugins["@eslint-react/rsc"],
|
|
@@ -1217,85 +1208,7 @@ async function react(options = {}) {
|
|
|
1217
1208
|
},
|
|
1218
1209
|
name: "eslint/react/rules",
|
|
1219
1210
|
rules: {
|
|
1220
|
-
|
|
1221
|
-
"react-dom/no-dangerously-set-innerhtml-with-children": "error",
|
|
1222
|
-
"react-dom/no-find-dom-node": "error",
|
|
1223
|
-
"react-dom/no-flush-sync": "error",
|
|
1224
|
-
"react-dom/no-hydrate": "error",
|
|
1225
|
-
"react-dom/no-namespace": "error",
|
|
1226
|
-
"react-dom/no-render": "error",
|
|
1227
|
-
"react-dom/no-render-return-value": "error",
|
|
1228
|
-
"react-dom/no-script-url": "warn",
|
|
1229
|
-
"react-dom/no-unsafe-iframe-sandbox": "warn",
|
|
1230
|
-
"react-dom/no-use-form-state": "error",
|
|
1231
|
-
"react-dom/no-void-elements-with-children": "error",
|
|
1232
|
-
"react-hooks-extra/no-direct-set-state-in-use-effect": "warn",
|
|
1233
|
-
"react-hooks/exhaustive-deps": "warn",
|
|
1234
|
-
"react-hooks/rules-of-hooks": "error",
|
|
1235
|
-
"react-naming-convention/context-name": "warn",
|
|
1236
|
-
"react-naming-convention/ref-name": "warn",
|
|
1237
|
-
"react-naming-convention/use-state": "warn",
|
|
1238
|
-
"react-rsc/function-definition": "error",
|
|
1239
|
-
"react-web-api/no-leaked-event-listener": "warn",
|
|
1240
|
-
"react-web-api/no-leaked-interval": "warn",
|
|
1241
|
-
"react-web-api/no-leaked-resize-observer": "warn",
|
|
1242
|
-
"react-web-api/no-leaked-timeout": "warn",
|
|
1243
|
-
"react/jsx-key-before-spread": "warn",
|
|
1244
|
-
"react/jsx-no-comment-textnodes": "warn",
|
|
1245
|
-
"react/jsx-no-duplicate-props": "warn",
|
|
1246
|
-
"react/jsx-uses-react": "warn",
|
|
1247
|
-
"react/jsx-uses-vars": "warn",
|
|
1248
|
-
"react/no-access-state-in-setstate": "error",
|
|
1249
|
-
"react/no-array-index-key": "warn",
|
|
1250
|
-
"react/no-children-count": "warn",
|
|
1251
|
-
"react/no-children-for-each": "warn",
|
|
1252
|
-
"react/no-children-map": "warn",
|
|
1253
|
-
"react/no-children-only": "warn",
|
|
1254
|
-
"react/no-children-to-array": "warn",
|
|
1255
|
-
"react/no-clone-element": "warn",
|
|
1256
|
-
"react/no-component-will-mount": "error",
|
|
1257
|
-
"react/no-component-will-receive-props": "error",
|
|
1258
|
-
"react/no-component-will-update": "error",
|
|
1259
|
-
"react/no-context-provider": "warn",
|
|
1260
|
-
"react/no-create-ref": "error",
|
|
1261
|
-
"react/no-default-props": "error",
|
|
1262
|
-
"react/no-direct-mutation-state": "error",
|
|
1263
|
-
"react/no-forward-ref": "warn",
|
|
1264
|
-
"react/no-missing-key": "error",
|
|
1265
|
-
"react/no-nested-component-definitions": "error",
|
|
1266
|
-
"react/no-nested-lazy-component-declarations": "error",
|
|
1267
|
-
"react/no-prop-types": "error",
|
|
1268
|
-
"react/no-redundant-should-component-update": "error",
|
|
1269
|
-
"react/no-set-state-in-component-did-mount": "warn",
|
|
1270
|
-
"react/no-set-state-in-component-did-update": "warn",
|
|
1271
|
-
"react/no-set-state-in-component-will-update": "warn",
|
|
1272
|
-
"react/no-string-refs": "error",
|
|
1273
|
-
"react/no-unnecessary-use-prefix": "warn",
|
|
1274
|
-
"react/no-unsafe-component-will-mount": "warn",
|
|
1275
|
-
"react/no-unsafe-component-will-receive-props": "warn",
|
|
1276
|
-
"react/no-unsafe-component-will-update": "warn",
|
|
1277
|
-
"react/no-unused-class-component-members": "warn",
|
|
1278
|
-
"react/no-use-context": "warn",
|
|
1279
|
-
"react/no-useless-forward-ref": "warn",
|
|
1280
|
-
"react/prefer-namespace-import": "error",
|
|
1281
|
-
"react/prefer-use-state-lazy-initialization": "warn",
|
|
1282
|
-
...reactCompiler ? {
|
|
1283
|
-
"react-hooks/component-hook-factories": "error",
|
|
1284
|
-
"react-hooks/config": "error",
|
|
1285
|
-
"react-hooks/error-boundaries": "error",
|
|
1286
|
-
"react-hooks/gating": "error",
|
|
1287
|
-
"react-hooks/globals": "error",
|
|
1288
|
-
"react-hooks/immutability": "error",
|
|
1289
|
-
"react-hooks/incompatible-library": "warn",
|
|
1290
|
-
"react-hooks/preserve-manual-memoization": "error",
|
|
1291
|
-
"react-hooks/purity": "error",
|
|
1292
|
-
"react-hooks/refs": "error",
|
|
1293
|
-
"react-hooks/set-state-in-effect": "error",
|
|
1294
|
-
"react-hooks/set-state-in-render": "error",
|
|
1295
|
-
"react-hooks/static-components": "error",
|
|
1296
|
-
"react-hooks/unsupported-syntax": "warn",
|
|
1297
|
-
"react-hooks/use-memo": "error"
|
|
1298
|
-
} : {},
|
|
1211
|
+
...pluginReact.configs.recommended.rules,
|
|
1299
1212
|
"react-refresh/only-export-components": ["error", {
|
|
1300
1213
|
allowConstantExport: isAllowConstantExport,
|
|
1301
1214
|
allowExportNames: [...isUsingNext ? [
|
|
@@ -1325,6 +1238,7 @@ async function react(options = {}) {
|
|
|
1325
1238
|
"shouldRevalidate"
|
|
1326
1239
|
] : []]
|
|
1327
1240
|
}],
|
|
1241
|
+
"react/prefer-namespace-import": "error",
|
|
1328
1242
|
...overrides
|
|
1329
1243
|
}
|
|
1330
1244
|
},
|
|
@@ -1333,11 +1247,7 @@ async function react(options = {}) {
|
|
|
1333
1247
|
name: "eslint/react/typescript",
|
|
1334
1248
|
rules: {
|
|
1335
1249
|
"react-dom/no-string-style-prop": "off",
|
|
1336
|
-
"react-dom/no-unknown-property": "off"
|
|
1337
|
-
"react/jsx-no-duplicate-props": "off",
|
|
1338
|
-
"react/jsx-no-undef": "off",
|
|
1339
|
-
"react/jsx-uses-react": "off",
|
|
1340
|
-
"react/jsx-uses-vars": "off"
|
|
1250
|
+
"react-dom/no-unknown-property": "off"
|
|
1341
1251
|
}
|
|
1342
1252
|
},
|
|
1343
1253
|
...isTypeAware ? [{
|
|
@@ -1348,7 +1258,6 @@ async function react(options = {}) {
|
|
|
1348
1258
|
}] : []
|
|
1349
1259
|
];
|
|
1350
1260
|
}
|
|
1351
|
-
|
|
1352
1261
|
//#endregion
|
|
1353
1262
|
//#region src/configs/regexp.ts
|
|
1354
1263
|
async function regexp(options = {}) {
|
|
@@ -1366,7 +1275,6 @@ async function regexp(options = {}) {
|
|
|
1366
1275
|
}
|
|
1367
1276
|
}];
|
|
1368
1277
|
}
|
|
1369
|
-
|
|
1370
1278
|
//#endregion
|
|
1371
1279
|
//#region src/configs/sort.ts
|
|
1372
1280
|
/**
|
|
@@ -1599,7 +1507,6 @@ function sortTsconfig() {
|
|
|
1599
1507
|
] }
|
|
1600
1508
|
}];
|
|
1601
1509
|
}
|
|
1602
|
-
|
|
1603
1510
|
//#endregion
|
|
1604
1511
|
//#region src/configs/test.ts
|
|
1605
1512
|
async function test(options = {}) {
|
|
@@ -1628,6 +1535,7 @@ async function test(options = {}) {
|
|
|
1628
1535
|
"test/prefer-hooks-in-order": "error",
|
|
1629
1536
|
"test/prefer-lowercase-title": "error",
|
|
1630
1537
|
"antfu/no-top-level-await": "off",
|
|
1538
|
+
"e18e/prefer-static-regex": "off",
|
|
1631
1539
|
"no-unused-expressions": "off",
|
|
1632
1540
|
"node/prefer-global/process": "off",
|
|
1633
1541
|
"ts/explicit-function-return-type": "off",
|
|
@@ -1635,12 +1543,11 @@ async function test(options = {}) {
|
|
|
1635
1543
|
}
|
|
1636
1544
|
}];
|
|
1637
1545
|
}
|
|
1638
|
-
|
|
1639
1546
|
//#endregion
|
|
1640
1547
|
//#region src/configs/toml.ts
|
|
1641
1548
|
async function toml(options = {}) {
|
|
1642
|
-
const { files = [GLOB_TOML], overrides = {}, stylistic
|
|
1643
|
-
const {
|
|
1549
|
+
const { files = [GLOB_TOML], overrides = {}, stylistic = true } = options;
|
|
1550
|
+
const { other_indent = 2 } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
1644
1551
|
const [pluginToml, parserToml] = await Promise.all([interopDefault(import("eslint-plugin-toml")), interopDefault(import("toml-eslint-parser"))]);
|
|
1645
1552
|
return [{
|
|
1646
1553
|
name: "eslint/toml/setup",
|
|
@@ -1659,11 +1566,11 @@ async function toml(options = {}) {
|
|
|
1659
1566
|
"toml/precision-of-integer": "error",
|
|
1660
1567
|
"toml/tables-order": "error",
|
|
1661
1568
|
"toml/vue-custom-block/no-parsing-error": "error",
|
|
1662
|
-
...stylistic
|
|
1569
|
+
...stylistic ? {
|
|
1663
1570
|
"toml/array-bracket-newline": "error",
|
|
1664
1571
|
"toml/array-bracket-spacing": "error",
|
|
1665
1572
|
"toml/array-element-newline": "error",
|
|
1666
|
-
"toml/indent": ["error", typeof
|
|
1573
|
+
"toml/indent": ["error", typeof other_indent === "number" ? other_indent : other_indent === "tab" ? "tab" : 4],
|
|
1667
1574
|
"toml/inline-table-curly-spacing": "error",
|
|
1668
1575
|
"toml/key-spacing": "error",
|
|
1669
1576
|
"toml/padding-line-between-pairs": "error",
|
|
@@ -1676,14 +1583,13 @@ async function toml(options = {}) {
|
|
|
1676
1583
|
}
|
|
1677
1584
|
}];
|
|
1678
1585
|
}
|
|
1679
|
-
|
|
1680
1586
|
//#endregion
|
|
1681
1587
|
//#region src/configs/typescript.ts
|
|
1682
1588
|
async function typescript(options = {}) {
|
|
1683
1589
|
const { componentExts = [], erasableOnly = false, overrides = {}, parserOptions = {}, type = "app" } = options;
|
|
1684
|
-
const files = options.files ?? [
|
|
1685
|
-
const ignoresTypeAware = options.ignoresTypeAware ?? [
|
|
1686
|
-
const filesTypeAware = options.filesTypeAware ?? [
|
|
1590
|
+
const files = options.files ?? ["**/*.?([cm])[jt]s?(x)", ...componentExts.map((ext) => `**/*.${ext}`)];
|
|
1591
|
+
const ignoresTypeAware = options.ignoresTypeAware ?? [`**/*.md/**`];
|
|
1592
|
+
const filesTypeAware = options.filesTypeAware ?? ["**/*.?([cm])ts", "**/*.?([cm])tsx"];
|
|
1687
1593
|
const tsconfigPath = options?.tsconfigPath ? options.tsconfigPath : void 0;
|
|
1688
1594
|
const isTypeAware = !!tsconfigPath;
|
|
1689
1595
|
const typeAwareRules = {
|
|
@@ -1713,10 +1619,10 @@ async function typescript(options = {}) {
|
|
|
1713
1619
|
"ts/unbound-method": "error"
|
|
1714
1620
|
};
|
|
1715
1621
|
const [pluginTs, parserTs] = await Promise.all([interopDefault(import("@typescript-eslint/eslint-plugin")), interopDefault(import("@typescript-eslint/parser"))]);
|
|
1716
|
-
function makeParser(typeAware, files
|
|
1622
|
+
function makeParser(typeAware, files, ignores) {
|
|
1717
1623
|
return {
|
|
1718
|
-
files
|
|
1719
|
-
...ignores
|
|
1624
|
+
files,
|
|
1625
|
+
...ignores ? { ignores } : {},
|
|
1720
1626
|
languageOptions: {
|
|
1721
1627
|
parser: parserTs,
|
|
1722
1628
|
parserOptions: {
|
|
@@ -1826,7 +1732,6 @@ async function typescript(options = {}) {
|
|
|
1826
1732
|
}] : []
|
|
1827
1733
|
];
|
|
1828
1734
|
}
|
|
1829
|
-
|
|
1830
1735
|
//#endregion
|
|
1831
1736
|
//#region src/configs/unicorn.ts
|
|
1832
1737
|
async function unicorn(options = {}) {
|
|
@@ -1856,7 +1761,6 @@ async function unicorn(options = {}) {
|
|
|
1856
1761
|
}
|
|
1857
1762
|
}];
|
|
1858
1763
|
}
|
|
1859
|
-
|
|
1860
1764
|
//#endregion
|
|
1861
1765
|
//#region src/configs/unocss.ts
|
|
1862
1766
|
async function unocss(options = {}) {
|
|
@@ -1874,7 +1778,6 @@ async function unocss(options = {}) {
|
|
|
1874
1778
|
}
|
|
1875
1779
|
}];
|
|
1876
1780
|
}
|
|
1877
|
-
|
|
1878
1781
|
//#endregion
|
|
1879
1782
|
//#region src/configs/vue.ts
|
|
1880
1783
|
const pkg = getPackageInfoSync("vue");
|
|
@@ -1882,9 +1785,9 @@ let vueVersion = pkg && pkg.version;
|
|
|
1882
1785
|
vueVersion = vueVersion && vueVersion[0];
|
|
1883
1786
|
vueVersion = Number.isNaN(vueVersion) ? "3" : vueVersion;
|
|
1884
1787
|
async function vue(options = {}) {
|
|
1885
|
-
const { files = [GLOB_VUE], overrides = {}, stylistic
|
|
1788
|
+
const { files = [GLOB_VUE], overrides = {}, stylistic = true } = options;
|
|
1886
1789
|
const sfcBlocks = options.sfcBlocks === true ? {} : options.sfcBlocks ?? {};
|
|
1887
|
-
const { indent = 4 } = typeof stylistic
|
|
1790
|
+
const { indent = 4 } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
1888
1791
|
const [pluginVue, parserVue, processorVueBlocks] = await Promise.all([
|
|
1889
1792
|
interopDefault(import("eslint-plugin-vue")),
|
|
1890
1793
|
interopDefault(import("vue-eslint-parser")),
|
|
@@ -2037,7 +1940,7 @@ async function vue(options = {}) {
|
|
|
2037
1940
|
nonwords: false,
|
|
2038
1941
|
words: true
|
|
2039
1942
|
}],
|
|
2040
|
-
...stylistic
|
|
1943
|
+
...stylistic ? {
|
|
2041
1944
|
"vue/array-bracket-spacing": ["error", "never"],
|
|
2042
1945
|
"vue/arrow-spacing": ["error", {
|
|
2043
1946
|
after: true,
|
|
@@ -2085,12 +1988,11 @@ async function vue(options = {}) {
|
|
|
2085
1988
|
}
|
|
2086
1989
|
}];
|
|
2087
1990
|
}
|
|
2088
|
-
|
|
2089
1991
|
//#endregion
|
|
2090
1992
|
//#region src/configs/yaml.ts
|
|
2091
1993
|
async function yaml(options = {}) {
|
|
2092
|
-
const { files = [GLOB_YAML], overrides = {}, stylistic
|
|
2093
|
-
const { quotes = "single" } = typeof stylistic
|
|
1994
|
+
const { files = [GLOB_YAML], overrides = {}, stylistic = true } = options;
|
|
1995
|
+
const { other_indent = 2, quotes = "single" } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
2094
1996
|
const [pluginYaml, parserYaml] = await Promise.all([interopDefault(import("eslint-plugin-yml")), interopDefault(import("yaml-eslint-parser"))]);
|
|
2095
1997
|
return [{
|
|
2096
1998
|
name: "eslint/yaml/setup",
|
|
@@ -2108,14 +2010,14 @@ async function yaml(options = {}) {
|
|
|
2108
2010
|
"yaml/no-irregular-whitespace": "error",
|
|
2109
2011
|
"yaml/plain-scalar": "error",
|
|
2110
2012
|
"yaml/vue-custom-block/no-parsing-error": "error",
|
|
2111
|
-
...stylistic
|
|
2013
|
+
...stylistic ? {
|
|
2112
2014
|
"yaml/block-mapping-question-indicator-newline": "error",
|
|
2113
2015
|
"yaml/block-sequence-hyphen-indicator-newline": "error",
|
|
2114
2016
|
"yaml/flow-mapping-curly-newline": "error",
|
|
2115
2017
|
"yaml/flow-mapping-curly-spacing": "error",
|
|
2116
2018
|
"yaml/flow-sequence-bracket-newline": "error",
|
|
2117
2019
|
"yaml/flow-sequence-bracket-spacing": "error",
|
|
2118
|
-
"yaml/indent": ["error", 2],
|
|
2020
|
+
"yaml/indent": ["error", typeof other_indent === "number" ? other_indent : 2],
|
|
2119
2021
|
"yaml/key-spacing": "error",
|
|
2120
2022
|
"yaml/no-tab-indent": "error",
|
|
2121
2023
|
"yaml/quotes": ["error", {
|
|
@@ -2128,7 +2030,6 @@ async function yaml(options = {}) {
|
|
|
2128
2030
|
}
|
|
2129
2031
|
}];
|
|
2130
2032
|
}
|
|
2131
|
-
|
|
2132
2033
|
//#endregion
|
|
2133
2034
|
//#region src/factory.ts
|
|
2134
2035
|
const flatConfigProps = [
|
|
@@ -2149,8 +2050,9 @@ const VuePackages = [
|
|
|
2149
2050
|
const defaultPluginRenaming = {
|
|
2150
2051
|
"@eslint-react": "react",
|
|
2151
2052
|
"@eslint-react/dom": "react-dom",
|
|
2152
|
-
"@eslint-react/hooks-extra": "react-hooks-extra",
|
|
2153
2053
|
"@eslint-react/naming-convention": "react-naming-convention",
|
|
2054
|
+
"@eslint-react/rsc": "react-rsc",
|
|
2055
|
+
"@eslint-react/web-api": "react-web-api",
|
|
2154
2056
|
"@next/next": "next",
|
|
2155
2057
|
"@stylistic": "style",
|
|
2156
2058
|
"@typescript-eslint": "ts",
|
|
@@ -2170,7 +2072,7 @@ const defaultPluginRenaming = {
|
|
|
2170
2072
|
* 合并的 ESLint 配置
|
|
2171
2073
|
*/
|
|
2172
2074
|
function lincy(options = {}, ...userConfigs) {
|
|
2173
|
-
const { autoRenamePlugins = true, componentExts = [], gitignore: enableGitignore = true, ignores:
|
|
2075
|
+
const { autoRenamePlugins = true, componentExts = [], e18e: enableE18e = true, gitignore: enableGitignore = true, ignores: userIgnores = [], imports: enableImports = true, jsx: enableJsx = true, nextjs: enableNextjs = false, overrides = {}, pnpm: enableCatalogs = !!findUpSync("pnpm-workspace.yaml"), react: enableReact = false, regexp: enableRegexp = true, type: appType = "app", typescript: enableTypeScript = isPackageExists("typescript") || isPackageExists("@typescript/native-preview"), unicorn: enableUnicorn = true, unocss: enableUnoCSS = false, vue: enableVue = VuePackages.some((i) => isPackageExists(i)) } = options;
|
|
2174
2076
|
let isInEditor = options.isInEditor;
|
|
2175
2077
|
if (isInEditor == null) {
|
|
2176
2078
|
isInEditor = isInEditorEnv();
|
|
@@ -2178,104 +2080,108 @@ function lincy(options = {}, ...userConfigs) {
|
|
|
2178
2080
|
}
|
|
2179
2081
|
const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
|
|
2180
2082
|
if (stylisticOptions && !("jsx" in stylisticOptions)) stylisticOptions.jsx = enableJsx;
|
|
2181
|
-
const configs
|
|
2182
|
-
if (enableGitignore) if (typeof enableGitignore !== "boolean") configs
|
|
2083
|
+
const configs = [];
|
|
2084
|
+
if (enableGitignore) if (typeof enableGitignore !== "boolean") configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
|
|
2183
2085
|
name: "eslint/gitignore",
|
|
2184
2086
|
...enableGitignore
|
|
2185
2087
|
})]));
|
|
2186
|
-
else configs
|
|
2088
|
+
else configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
|
|
2187
2089
|
name: "eslint/gitignore",
|
|
2188
2090
|
strict: false
|
|
2189
2091
|
})]));
|
|
2190
2092
|
const typescriptOptions = resolveSubOptions(options, "typescript");
|
|
2191
2093
|
const tsconfigPath = "tsconfigPath" in typescriptOptions ? typescriptOptions.tsconfigPath : void 0;
|
|
2192
|
-
configs
|
|
2094
|
+
configs.push(ignores([...overrides.ignores || [], ...userIgnores], !enableTypeScript), javascript({
|
|
2193
2095
|
isInEditor,
|
|
2194
2096
|
overrides: getOverrides(options, "javascript")
|
|
2195
2097
|
}), comments({ overrides: getOverrides(options, "comments") }), node({ overrides: getOverrides(options, "node") }), jsdoc({
|
|
2196
2098
|
overrides: getOverrides(options, "jsdoc"),
|
|
2197
2099
|
stylistic: stylisticOptions
|
|
2198
2100
|
}), perfectionist({ overrides: getOverrides(options, "perfectionist") }));
|
|
2199
|
-
if (
|
|
2101
|
+
if (enableE18e) configs.push(e18e({
|
|
2102
|
+
isInEditor,
|
|
2103
|
+
...enableE18e === true ? {} : enableE18e
|
|
2104
|
+
}));
|
|
2105
|
+
if (enableUnicorn) configs.push(unicorn({
|
|
2200
2106
|
...enableUnicorn === true ? {} : enableUnicorn,
|
|
2201
2107
|
overrides: getOverrides(options, "unicorn")
|
|
2202
2108
|
}));
|
|
2203
|
-
if (enableImports) configs
|
|
2109
|
+
if (enableImports) configs.push(imports({
|
|
2204
2110
|
overrides: getOverrides(options, "imports"),
|
|
2205
2111
|
stylistic: stylisticOptions
|
|
2206
2112
|
}));
|
|
2207
2113
|
if (enableVue) componentExts.push("vue");
|
|
2208
|
-
if (enableJsx) configs
|
|
2209
|
-
if (enableTypeScript) configs
|
|
2114
|
+
if (enableJsx) configs.push(jsx());
|
|
2115
|
+
if (enableTypeScript) configs.push(typescript({
|
|
2210
2116
|
...typescriptOptions,
|
|
2211
2117
|
componentExts,
|
|
2212
2118
|
overrides: getOverrides(options, "typescript"),
|
|
2213
2119
|
tsconfigPath,
|
|
2214
|
-
type:
|
|
2120
|
+
type: appType
|
|
2215
2121
|
}));
|
|
2216
|
-
if (stylisticOptions) configs
|
|
2122
|
+
if (stylisticOptions) configs.push(stylistic({
|
|
2217
2123
|
overrides: getOverrides(options, "stylistic"),
|
|
2218
2124
|
stylistic: stylisticOptions
|
|
2219
2125
|
}));
|
|
2220
|
-
if (enableRegexp) configs
|
|
2126
|
+
if (enableRegexp) configs.push(regexp({
|
|
2221
2127
|
...resolveSubOptions(options, "regexp"),
|
|
2222
2128
|
...getOverrides(options, "regexp")
|
|
2223
2129
|
}));
|
|
2224
|
-
if (options.test ?? true) configs
|
|
2130
|
+
if (options.test ?? true) configs.push(test({
|
|
2225
2131
|
...resolveSubOptions(options, "test"),
|
|
2226
2132
|
isInEditor,
|
|
2227
2133
|
overrides: getOverrides(options, "test")
|
|
2228
2134
|
}));
|
|
2229
|
-
if (enableVue) configs
|
|
2135
|
+
if (enableVue) configs.push(vue({
|
|
2230
2136
|
...resolveSubOptions(options, "vue"),
|
|
2231
2137
|
overrides: getOverrides(options, "vue"),
|
|
2232
2138
|
stylistic: stylisticOptions,
|
|
2233
2139
|
typescript: !!enableTypeScript
|
|
2234
2140
|
}));
|
|
2235
|
-
if (enableReact) configs
|
|
2141
|
+
if (enableReact) configs.push(react({
|
|
2236
2142
|
...typescriptOptions,
|
|
2237
2143
|
...resolveSubOptions(options, "react"),
|
|
2238
2144
|
overrides: getOverrides(options, "react"),
|
|
2239
2145
|
tsconfigPath
|
|
2240
2146
|
}));
|
|
2241
|
-
if (enableNextjs) configs
|
|
2242
|
-
if (enableUnoCSS) configs
|
|
2147
|
+
if (enableNextjs) configs.push(nextjs({ overrides: getOverrides(options, "nextjs") }));
|
|
2148
|
+
if (enableUnoCSS) configs.push(unocss({
|
|
2243
2149
|
...resolveSubOptions(options, "unocss"),
|
|
2244
2150
|
overrides: getOverrides(options, "unocss")
|
|
2245
2151
|
}));
|
|
2246
|
-
if (options.jsonc ?? true) configs
|
|
2152
|
+
if (options.jsonc ?? true) configs.push(jsonc({
|
|
2247
2153
|
...resolveSubOptions(options, "jsonc"),
|
|
2248
2154
|
overrides: getOverrides(options, "jsonc"),
|
|
2249
2155
|
stylistic: stylisticOptions
|
|
2250
2156
|
}), sortPackageJson(), sortTsconfig());
|
|
2251
|
-
if (enableCatalogs) configs
|
|
2157
|
+
if (enableCatalogs) configs.push(pnpm({
|
|
2252
2158
|
isInEditor,
|
|
2253
2159
|
...resolveSubOptions(options, "pnpm")
|
|
2254
2160
|
}));
|
|
2255
|
-
if (options.yaml ?? true) configs
|
|
2161
|
+
if (options.yaml ?? true) configs.push(yaml({
|
|
2256
2162
|
...resolveSubOptions(options, "yaml"),
|
|
2257
2163
|
overrides: getOverrides(options, "yaml"),
|
|
2258
2164
|
stylistic: stylisticOptions
|
|
2259
2165
|
}));
|
|
2260
|
-
if (options.toml ?? true) configs
|
|
2166
|
+
if (options.toml ?? true) configs.push(toml({
|
|
2261
2167
|
overrides: getOverrides(options, "toml"),
|
|
2262
2168
|
stylistic: stylisticOptions
|
|
2263
2169
|
}));
|
|
2264
|
-
if (options.markdown ?? true) configs
|
|
2170
|
+
if (options.markdown ?? true) configs.push(markdown({
|
|
2265
2171
|
...resolveSubOptions(options, "markdown"),
|
|
2266
2172
|
componentExts,
|
|
2267
2173
|
overrides: getOverrides(options, "markdown")
|
|
2268
2174
|
}));
|
|
2269
|
-
if (options.formatters) configs
|
|
2270
|
-
configs
|
|
2175
|
+
if (options.formatters) configs.push(formatters(options.formatters, typeof stylisticOptions === "boolean" ? {} : stylisticOptions));
|
|
2176
|
+
configs.push(disables());
|
|
2271
2177
|
if ("files" in options) throw new Error("[@lincy/eslint-config] 第一个参数不应包含“files”属性,因为选项应该是全局的。请将其放在第二个或更后面的配置中。");
|
|
2272
2178
|
const fusedConfig = flatConfigProps.reduce((acc, key) => {
|
|
2273
2179
|
if (key in options) acc[key] = options[key];
|
|
2274
2180
|
return acc;
|
|
2275
2181
|
}, {});
|
|
2276
|
-
if (Object.keys(fusedConfig).length) configs
|
|
2182
|
+
if (Object.keys(fusedConfig).length) configs.push([fusedConfig]);
|
|
2277
2183
|
let composer = new FlatConfigComposer();
|
|
2278
|
-
composer = composer.append(...configs
|
|
2184
|
+
composer = composer.append(...configs, ...userConfigs);
|
|
2279
2185
|
if (autoRenamePlugins) composer = composer.renamePlugins(defaultPluginRenaming);
|
|
2280
2186
|
if (isInEditor) composer = composer.disableRulesFix([
|
|
2281
2187
|
"unused-imports/no-unused-imports",
|
|
@@ -2294,10 +2200,8 @@ function getOverrides(options, key) {
|
|
|
2294
2200
|
..."overrides" in sub ? sub.overrides : {}
|
|
2295
2201
|
};
|
|
2296
2202
|
}
|
|
2297
|
-
|
|
2298
2203
|
//#endregion
|
|
2299
2204
|
//#region src/index.ts
|
|
2300
2205
|
var src_default = lincy;
|
|
2301
|
-
|
|
2302
2206
|
//#endregion
|
|
2303
|
-
export { GLOB_ALL_SRC, GLOB_CSS, GLOB_EXCLUDE, GLOB_GRAPHQL, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE,
|
|
2207
|
+
export { GLOB_ALL_SRC, GLOB_CSS, GLOB_EXCLUDE, GLOB_GRAPHQL, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVG, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_XML, GLOB_YAML, StylisticConfigDefaults, combine, comments, src_default as default, defaultPluginRenaming, disables, e18e, ensurePackages, formatters, getOverrides, ignores, imports, interopDefault, isInEditorEnv, isInGitHooksOrLintStaged, isPackageInScope, javascript, jsdoc, jsonc, jsx, lincy, markdown, nextjs, node, parserPlain, perfectionist, pnpm, react, regexp, renamePluginInConfigs, renameRules, resolveSubOptions, sortPackageJson, sortTsconfig, stylistic, test, toArray, toml, typescript, unicorn, unocss, vue, yaml };
|