@lincy/eslint-config 6.5.1 → 7.0.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 +155 -255
- package/dist/index.d.cts +1683 -2153
- package/dist/index.d.mts +1682 -2152
- package/dist/index.mjs +142 -242
- package/package.json +40 -36
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)";
|
|
@@ -139,7 +137,6 @@ const GLOB_EXCLUDE = [
|
|
|
139
137
|
"**/auto-import?(s).d.ts",
|
|
140
138
|
"**/components.d.ts"
|
|
141
139
|
];
|
|
142
|
-
|
|
143
140
|
//#endregion
|
|
144
141
|
//#region src/configs/disables.ts
|
|
145
142
|
async function disables() {
|
|
@@ -195,7 +192,26 @@ async function disables() {
|
|
|
195
192
|
}
|
|
196
193
|
];
|
|
197
194
|
}
|
|
198
|
-
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/configs/e18e.ts
|
|
197
|
+
async function e18e(options = {}) {
|
|
198
|
+
const { isInEditor = false, modernization = true, type = "app", moduleReplacements = type === "lib" && isInEditor, overrides = {}, performanceImprovements = true } = options;
|
|
199
|
+
const configs = pluginE18e.configs;
|
|
200
|
+
return [{
|
|
201
|
+
name: "eslint/e18e/rules",
|
|
202
|
+
plugins: { e18e: pluginE18e },
|
|
203
|
+
rules: {
|
|
204
|
+
...modernization ? { ...configs.modernization.rules } : {},
|
|
205
|
+
...moduleReplacements ? { ...configs.moduleReplacements.rules } : {},
|
|
206
|
+
...performanceImprovements ? { ...configs.performanceImprovements.rules } : {},
|
|
207
|
+
"e18e/prefer-array-to-reversed": "off",
|
|
208
|
+
"e18e/prefer-array-to-sorted": "off",
|
|
209
|
+
"e18e/prefer-array-to-spliced": "off",
|
|
210
|
+
"e18e/prefer-spread-syntax": "off",
|
|
211
|
+
...overrides
|
|
212
|
+
}
|
|
213
|
+
}];
|
|
214
|
+
}
|
|
199
215
|
//#endregion
|
|
200
216
|
//#region src/utils.ts
|
|
201
217
|
const scopeUrl = fileURLToPath(new URL(".", import.meta.url));
|
|
@@ -222,8 +238,8 @@ const parserPlain = {
|
|
|
222
238
|
/**
|
|
223
239
|
* Combine array and non-array configs into a single array.
|
|
224
240
|
*/
|
|
225
|
-
async function combine(...configs
|
|
226
|
-
return (await Promise.all(configs
|
|
241
|
+
async function combine(...configs) {
|
|
242
|
+
return (await Promise.all(configs)).flat();
|
|
227
243
|
}
|
|
228
244
|
function renameRules(rules, map) {
|
|
229
245
|
return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
|
|
@@ -231,8 +247,8 @@ function renameRules(rules, map) {
|
|
|
231
247
|
return [key, value];
|
|
232
248
|
}));
|
|
233
249
|
}
|
|
234
|
-
function renamePluginInConfigs(configs
|
|
235
|
-
return configs
|
|
250
|
+
function renamePluginInConfigs(configs, map) {
|
|
251
|
+
return configs.map((i) => {
|
|
236
252
|
const clone = { ...i };
|
|
237
253
|
if (clone.rules) clone.rules = renameRules(clone.rules, map);
|
|
238
254
|
if (clone.plugins) clone.plugins = Object.fromEntries(Object.entries(clone.plugins).map(([key, value]) => {
|
|
@@ -266,26 +282,26 @@ function isInEditorEnv() {
|
|
|
266
282
|
function isInGitHooksOrLintStaged() {
|
|
267
283
|
return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged"));
|
|
268
284
|
}
|
|
269
|
-
|
|
270
285
|
//#endregion
|
|
271
286
|
//#region src/configs/stylistic.ts
|
|
272
287
|
const StylisticConfigDefaults = {
|
|
273
288
|
indent: 4,
|
|
274
289
|
jsx: true,
|
|
275
290
|
lessOpinionated: false,
|
|
291
|
+
other_indent: 2,
|
|
276
292
|
quotes: "single",
|
|
277
293
|
semi: false
|
|
278
294
|
};
|
|
279
295
|
async function stylistic(options = {}) {
|
|
280
|
-
const { overrides = {}, stylistic
|
|
281
|
-
const { indent, jsx
|
|
296
|
+
const { overrides = {}, stylistic = StylisticConfigDefaults } = options;
|
|
297
|
+
const { indent, jsx, lessOpinionated, quotes, semi } = typeof stylistic === "boolean" ? StylisticConfigDefaults : {
|
|
282
298
|
...StylisticConfigDefaults,
|
|
283
|
-
...stylistic
|
|
299
|
+
...stylistic
|
|
284
300
|
};
|
|
285
301
|
const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
|
|
286
302
|
const config = pluginStylistic.configs.customize({
|
|
287
303
|
indent,
|
|
288
|
-
jsx
|
|
304
|
+
jsx,
|
|
289
305
|
pluginName: "style",
|
|
290
306
|
quotes,
|
|
291
307
|
semi
|
|
@@ -319,7 +335,6 @@ async function stylistic(options = {}) {
|
|
|
319
335
|
}
|
|
320
336
|
}];
|
|
321
337
|
}
|
|
322
|
-
|
|
323
338
|
//#endregion
|
|
324
339
|
//#region src/configs/formatters.ts
|
|
325
340
|
function mergePrettierOptions(options, overrides) {
|
|
@@ -329,18 +344,18 @@ function mergePrettierOptions(options, overrides) {
|
|
|
329
344
|
plugins: [...overrides.plugins || [], ...options.plugins || []]
|
|
330
345
|
};
|
|
331
346
|
}
|
|
332
|
-
async function formatters(options = {}, stylistic
|
|
347
|
+
async function formatters(options = {}, stylistic = {}) {
|
|
333
348
|
const defaultIndent = 4;
|
|
334
349
|
const isPrettierPluginXmlInScope = isPackageInScope("@prettier/plugin-xml");
|
|
335
350
|
if (options === true) {
|
|
336
|
-
const isPrettierPluginXmlInScope
|
|
351
|
+
const isPrettierPluginXmlInScope = isPackageInScope("@prettier/plugin-xml");
|
|
337
352
|
options = {
|
|
338
353
|
css: false,
|
|
339
354
|
graphql: true,
|
|
340
355
|
html: true,
|
|
341
356
|
markdown: true,
|
|
342
|
-
svg: isPrettierPluginXmlInScope
|
|
343
|
-
xml: isPrettierPluginXmlInScope
|
|
357
|
+
svg: isPrettierPluginXmlInScope,
|
|
358
|
+
xml: isPrettierPluginXmlInScope
|
|
344
359
|
};
|
|
345
360
|
} else options = {
|
|
346
361
|
css: options.css ?? false,
|
|
@@ -353,7 +368,7 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
353
368
|
await ensurePackages(["eslint-plugin-format", options.xml || options.svg ? "@prettier/plugin-xml" : void 0]);
|
|
354
369
|
const { indent, quotes, semi } = {
|
|
355
370
|
...StylisticConfigDefaults,
|
|
356
|
-
...stylistic
|
|
371
|
+
...stylistic
|
|
357
372
|
};
|
|
358
373
|
const prettierOptions = Object.assign({
|
|
359
374
|
endOfLine: "lf",
|
|
@@ -370,16 +385,17 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
370
385
|
xmlSortAttributesByKey: false,
|
|
371
386
|
xmlWhitespaceSensitivity: "ignore"
|
|
372
387
|
};
|
|
373
|
-
const dprintOptions =
|
|
388
|
+
const dprintOptions = {
|
|
374
389
|
indentWidth: typeof indent === "number" ? indent : defaultIndent,
|
|
375
390
|
quoteStyle: quotes === "single" ? "preferSingle" : "preferDouble",
|
|
376
|
-
useTabs: indent === "tab"
|
|
377
|
-
|
|
378
|
-
|
|
391
|
+
useTabs: indent === "tab",
|
|
392
|
+
...typeof options.dprintOptions === "boolean" ? {} : options.dprintOptions || {}
|
|
393
|
+
};
|
|
394
|
+
const configs = [{
|
|
379
395
|
name: "eslint/formatter/setup",
|
|
380
396
|
plugins: { format: await interopDefault(import("eslint-plugin-format")) }
|
|
381
397
|
}];
|
|
382
|
-
if (options.css) configs
|
|
398
|
+
if (options.css) configs.push({
|
|
383
399
|
files: [GLOB_CSS, GLOB_POSTCSS],
|
|
384
400
|
languageOptions: { parser: parserPlain },
|
|
385
401
|
name: "eslint/formatter/css",
|
|
@@ -395,13 +411,13 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
395
411
|
name: "eslint/formatter/less",
|
|
396
412
|
rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "less" })] }
|
|
397
413
|
});
|
|
398
|
-
if (options.html) configs
|
|
414
|
+
if (options.html) configs.push({
|
|
399
415
|
files: [GLOB_HTML],
|
|
400
416
|
languageOptions: { parser: parserPlain },
|
|
401
417
|
name: "eslint/formatter/html",
|
|
402
418
|
rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "html" })] }
|
|
403
419
|
});
|
|
404
|
-
if (options.xml) configs
|
|
420
|
+
if (options.xml) configs.push({
|
|
405
421
|
files: [GLOB_XML],
|
|
406
422
|
languageOptions: { parser: parserPlain },
|
|
407
423
|
name: "eslint/formatter/xml",
|
|
@@ -413,7 +429,7 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
413
429
|
plugins: ["@prettier/plugin-xml"]
|
|
414
430
|
})] }
|
|
415
431
|
});
|
|
416
|
-
if (options.svg) configs
|
|
432
|
+
if (options.svg) configs.push({
|
|
417
433
|
files: [GLOB_SVG],
|
|
418
434
|
languageOptions: { parser: parserPlain },
|
|
419
435
|
name: "eslint/formatter/svg",
|
|
@@ -427,7 +443,7 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
427
443
|
});
|
|
428
444
|
if (options.markdown) {
|
|
429
445
|
const formater = options.markdown === true ? "prettier" : options.markdown;
|
|
430
|
-
configs
|
|
446
|
+
configs.push({
|
|
431
447
|
files: [GLOB_MARKDOWN],
|
|
432
448
|
ignores: [],
|
|
433
449
|
languageOptions: { parser: parserPlain },
|
|
@@ -441,29 +457,30 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
441
457
|
}] }
|
|
442
458
|
});
|
|
443
459
|
}
|
|
444
|
-
if (options.graphql) configs
|
|
460
|
+
if (options.graphql) configs.push({
|
|
445
461
|
files: [GLOB_GRAPHQL],
|
|
446
462
|
languageOptions: { parser: parserPlain },
|
|
447
463
|
name: "eslint/formatter/graphql",
|
|
448
464
|
rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "graphql" })] }
|
|
449
465
|
});
|
|
450
|
-
return configs
|
|
466
|
+
return configs;
|
|
451
467
|
}
|
|
452
|
-
|
|
453
468
|
//#endregion
|
|
454
469
|
//#region src/configs/ignores.ts
|
|
455
|
-
async function ignores(
|
|
456
|
-
|
|
470
|
+
async function ignores(userIgnores = [], ignoreTypeScript = false) {
|
|
471
|
+
let ignores = [...GLOB_EXCLUDE];
|
|
472
|
+
if (ignoreTypeScript) ignores.push(GLOB_TS, GLOB_TSX);
|
|
473
|
+
if (typeof userIgnores === "function") ignores = userIgnores(ignores);
|
|
474
|
+
else ignores = [...ignores, ...userIgnores];
|
|
457
475
|
return [{
|
|
458
|
-
ignores
|
|
476
|
+
ignores,
|
|
459
477
|
name: "eslint/ignores"
|
|
460
478
|
}];
|
|
461
479
|
}
|
|
462
|
-
|
|
463
480
|
//#endregion
|
|
464
481
|
//#region src/configs/imports.ts
|
|
465
482
|
async function imports(options = {}) {
|
|
466
|
-
const { overrides = {}, stylistic
|
|
483
|
+
const { overrides = {}, stylistic = true } = options;
|
|
467
484
|
return [{
|
|
468
485
|
name: "eslint/imports/rules",
|
|
469
486
|
plugins: {
|
|
@@ -479,12 +496,11 @@ async function imports(options = {}) {
|
|
|
479
496
|
"import/no-duplicates": "error",
|
|
480
497
|
"import/no-mutable-exports": "error",
|
|
481
498
|
"import/no-named-default": "error",
|
|
482
|
-
...stylistic
|
|
499
|
+
...stylistic ? { "import/newline-after-import": ["error", { count: 1 }] } : {},
|
|
483
500
|
...overrides
|
|
484
501
|
}
|
|
485
502
|
}];
|
|
486
503
|
}
|
|
487
|
-
|
|
488
504
|
//#endregion
|
|
489
505
|
//#region src/configs/javascript.ts
|
|
490
506
|
async function javascript(options = {}) {
|
|
@@ -709,11 +725,10 @@ async function javascript(options = {}) {
|
|
|
709
725
|
}
|
|
710
726
|
}];
|
|
711
727
|
}
|
|
712
|
-
|
|
713
728
|
//#endregion
|
|
714
729
|
//#region src/configs/jsdoc.ts
|
|
715
730
|
async function jsdoc(options = {}) {
|
|
716
|
-
const { overrides = {}, stylistic
|
|
731
|
+
const { overrides = {}, stylistic = true } = options;
|
|
717
732
|
return [{
|
|
718
733
|
name: "eslint/jsdoc/setup",
|
|
719
734
|
plugins: { jsdoc: await interopDefault(import("eslint-plugin-jsdoc")) }
|
|
@@ -736,7 +751,7 @@ async function jsdoc(options = {}) {
|
|
|
736
751
|
"jsdoc/require-returns-check": "warn",
|
|
737
752
|
"jsdoc/require-returns-description": "warn",
|
|
738
753
|
"jsdoc/require-yields-check": "warn",
|
|
739
|
-
...stylistic
|
|
754
|
+
...stylistic ? {
|
|
740
755
|
"jsdoc/check-alignment": "warn",
|
|
741
756
|
"jsdoc/multiline-blocks": "warn"
|
|
742
757
|
} : {},
|
|
@@ -744,7 +759,6 @@ async function jsdoc(options = {}) {
|
|
|
744
759
|
}
|
|
745
760
|
}];
|
|
746
761
|
}
|
|
747
|
-
|
|
748
762
|
//#endregion
|
|
749
763
|
//#region src/configs/jsonc.ts
|
|
750
764
|
async function jsonc(options = {}) {
|
|
@@ -752,7 +766,8 @@ async function jsonc(options = {}) {
|
|
|
752
766
|
GLOB_JSON,
|
|
753
767
|
GLOB_JSON5,
|
|
754
768
|
GLOB_JSONC
|
|
755
|
-
], overrides = {}, stylistic
|
|
769
|
+
], overrides = {}, stylistic = true } = options;
|
|
770
|
+
const { other_indent = 2 } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
756
771
|
return [{
|
|
757
772
|
name: "eslint/jsonc/setup",
|
|
758
773
|
plugins: { jsonc: await interopDefault(import("eslint-plugin-jsonc")) }
|
|
@@ -787,11 +802,11 @@ async function jsonc(options = {}) {
|
|
|
787
802
|
"jsonc/space-unary-ops": "error",
|
|
788
803
|
"jsonc/valid-json-number": "error",
|
|
789
804
|
"jsonc/vue-custom-block/no-parsing-error": "error",
|
|
790
|
-
...stylistic
|
|
805
|
+
...stylistic ? {
|
|
791
806
|
"jsonc/array-bracket-spacing": ["error", "never"],
|
|
792
807
|
"jsonc/comma-dangle": ["error", "never"],
|
|
793
808
|
"jsonc/comma-style": ["error", "last"],
|
|
794
|
-
"jsonc/indent": ["error", 2],
|
|
809
|
+
"jsonc/indent": ["error", typeof other_indent === "number" ? other_indent : 2],
|
|
795
810
|
"jsonc/key-spacing": ["error", {
|
|
796
811
|
afterColon: true,
|
|
797
812
|
beforeColon: false
|
|
@@ -809,7 +824,6 @@ async function jsonc(options = {}) {
|
|
|
809
824
|
}
|
|
810
825
|
}];
|
|
811
826
|
}
|
|
812
|
-
|
|
813
827
|
//#endregion
|
|
814
828
|
//#region src/configs/jsx.ts
|
|
815
829
|
async function jsx() {
|
|
@@ -819,22 +833,21 @@ async function jsx() {
|
|
|
819
833
|
name: "eslint/jsx/setup"
|
|
820
834
|
}];
|
|
821
835
|
}
|
|
822
|
-
|
|
823
836
|
//#endregion
|
|
824
837
|
//#region src/configs/markdown.ts
|
|
825
838
|
async function markdown(options = {}) {
|
|
826
839
|
const { componentExts = [], files = [GLOB_MARKDOWN], gfm = true, overrides = {}, overridesMarkdown = {} } = options;
|
|
827
|
-
const markdown
|
|
840
|
+
const markdown = await interopDefault(import("@eslint/markdown"));
|
|
828
841
|
return [
|
|
829
842
|
{
|
|
830
843
|
name: "eslint/markdown/setup",
|
|
831
|
-
plugins: { markdown
|
|
844
|
+
plugins: { markdown }
|
|
832
845
|
},
|
|
833
846
|
{
|
|
834
847
|
files,
|
|
835
848
|
ignores: [GLOB_MARKDOWN_IN_MARKDOWN],
|
|
836
849
|
name: "eslint/markdown/processor",
|
|
837
|
-
processor: mergeProcessors([markdown
|
|
850
|
+
processor: mergeProcessors([markdown.processors.markdown, processorPassThrough])
|
|
838
851
|
},
|
|
839
852
|
{
|
|
840
853
|
files,
|
|
@@ -845,7 +858,8 @@ async function markdown(options = {}) {
|
|
|
845
858
|
files,
|
|
846
859
|
name: "eslint/markdown/rules",
|
|
847
860
|
rules: {
|
|
848
|
-
...markdown
|
|
861
|
+
...markdown.configs.recommended.at(0)?.rules,
|
|
862
|
+
"markdown/fenced-code-language": "off",
|
|
849
863
|
"markdown/no-missing-label-refs": "off",
|
|
850
864
|
...overridesMarkdown
|
|
851
865
|
}
|
|
@@ -871,7 +885,7 @@ async function markdown(options = {}) {
|
|
|
871
885
|
name: "eslint/markdown/disables/code",
|
|
872
886
|
rules: {
|
|
873
887
|
"antfu/no-top-level-await": "off",
|
|
874
|
-
"
|
|
888
|
+
"e18e/prefer-static-regex": "off",
|
|
875
889
|
"no-alert": "off",
|
|
876
890
|
"no-console": "off",
|
|
877
891
|
"no-labels": "off",
|
|
@@ -884,6 +898,7 @@ async function markdown(options = {}) {
|
|
|
884
898
|
"node/prefer-global/process": "off",
|
|
885
899
|
"style/comma-dangle": "off",
|
|
886
900
|
"style/eol-last": "off",
|
|
901
|
+
"style/padding-line-between-statements": "off",
|
|
887
902
|
"ts/consistent-type-imports": "off",
|
|
888
903
|
"ts/explicit-function-return-type": "off",
|
|
889
904
|
"ts/no-namespace": "off",
|
|
@@ -895,27 +910,11 @@ async function markdown(options = {}) {
|
|
|
895
910
|
"unicode-bom": "off",
|
|
896
911
|
"unused-imports/no-unused-imports": "off",
|
|
897
912
|
"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
913
|
...overrides
|
|
914
914
|
}
|
|
915
915
|
}
|
|
916
916
|
];
|
|
917
917
|
}
|
|
918
|
-
|
|
919
918
|
//#endregion
|
|
920
919
|
//#region src/configs/nextjs.ts
|
|
921
920
|
function normalizeRules(rules) {
|
|
@@ -948,14 +947,16 @@ async function nextjs(options = {}) {
|
|
|
948
947
|
settings: { react: { version: "detect" } }
|
|
949
948
|
}];
|
|
950
949
|
}
|
|
951
|
-
|
|
952
950
|
//#endregion
|
|
953
951
|
//#region src/configs/node.ts
|
|
954
952
|
async function node(options = {}) {
|
|
955
953
|
const { overrides = {} } = options;
|
|
956
954
|
return [{
|
|
955
|
+
name: "eslint/node/setup",
|
|
956
|
+
plugins: { node: pluginNode }
|
|
957
|
+
}, {
|
|
958
|
+
files: [GLOB_SRC],
|
|
957
959
|
name: "eslint/node/rules",
|
|
958
|
-
plugins: { node: pluginNode },
|
|
959
960
|
rules: {
|
|
960
961
|
"node/handle-callback-err": ["error", "^(err|error)$"],
|
|
961
962
|
"node/no-deprecated-api": "error",
|
|
@@ -969,7 +970,6 @@ async function node(options = {}) {
|
|
|
969
970
|
}
|
|
970
971
|
}];
|
|
971
972
|
}
|
|
972
|
-
|
|
973
973
|
//#endregion
|
|
974
974
|
//#region src/configs/perfectionist.ts
|
|
975
975
|
/**
|
|
@@ -1025,14 +1025,13 @@ async function perfectionist(options = {}) {
|
|
|
1025
1025
|
}
|
|
1026
1026
|
}];
|
|
1027
1027
|
}
|
|
1028
|
-
|
|
1029
1028
|
//#endregion
|
|
1030
1029
|
//#region src/configs/pnpm.ts
|
|
1031
1030
|
async function detectCatalogUsage() {
|
|
1032
1031
|
const workspaceFile = await findUp("pnpm-workspace.yaml");
|
|
1033
1032
|
if (!workspaceFile) return false;
|
|
1034
|
-
const yaml
|
|
1035
|
-
return yaml
|
|
1033
|
+
const yaml = await fs.readFile(workspaceFile, "utf-8");
|
|
1034
|
+
return yaml.includes("catalog:") || yaml.includes("catalogs:");
|
|
1036
1035
|
}
|
|
1037
1036
|
async function pnpm(options) {
|
|
1038
1037
|
const [pluginPnpm, pluginYaml, yamlParser] = await Promise.all([
|
|
@@ -1040,9 +1039,9 @@ async function pnpm(options) {
|
|
|
1040
1039
|
interopDefault(import("eslint-plugin-yml")),
|
|
1041
1040
|
interopDefault(import("yaml-eslint-parser"))
|
|
1042
1041
|
]);
|
|
1043
|
-
const { catalogs = await detectCatalogUsage(), isInEditor = false, json = true, sort = true, yaml
|
|
1044
|
-
const configs
|
|
1045
|
-
if (json) configs
|
|
1042
|
+
const { catalogs = await detectCatalogUsage(), isInEditor = false, json = true, sort = true, yaml = true } = options;
|
|
1043
|
+
const configs = [];
|
|
1044
|
+
if (json) configs.push({
|
|
1046
1045
|
files: ["package.json", "**/package.json"],
|
|
1047
1046
|
language: "jsonc/x",
|
|
1048
1047
|
name: "eslint/pnpm/package-json",
|
|
@@ -1056,8 +1055,8 @@ async function pnpm(options) {
|
|
|
1056
1055
|
"pnpm/json-valid-catalog": ["error", { autofix: !isInEditor }]
|
|
1057
1056
|
}
|
|
1058
1057
|
});
|
|
1059
|
-
if (yaml
|
|
1060
|
-
configs
|
|
1058
|
+
if (yaml) {
|
|
1059
|
+
configs.push({
|
|
1061
1060
|
files: ["pnpm-workspace.yaml"],
|
|
1062
1061
|
languageOptions: { parser: yamlParser },
|
|
1063
1062
|
name: "eslint/pnpm/pnpm-workspace-yaml",
|
|
@@ -1071,7 +1070,7 @@ async function pnpm(options) {
|
|
|
1071
1070
|
"pnpm/yaml-no-unused-catalog-item": "error"
|
|
1072
1071
|
}
|
|
1073
1072
|
});
|
|
1074
|
-
if (sort) configs
|
|
1073
|
+
if (sort) configs.push({
|
|
1075
1074
|
files: ["pnpm-workspace.yaml"],
|
|
1076
1075
|
languageOptions: { parser: yamlParser },
|
|
1077
1076
|
name: "eslint/pnpm/pnpm-workspace-yaml-sort",
|
|
@@ -1150,9 +1149,8 @@ async function pnpm(options) {
|
|
|
1150
1149
|
] }
|
|
1151
1150
|
});
|
|
1152
1151
|
}
|
|
1153
|
-
return configs
|
|
1152
|
+
return configs;
|
|
1154
1153
|
}
|
|
1155
|
-
|
|
1156
1154
|
//#endregion
|
|
1157
1155
|
//#region src/configs/react.ts
|
|
1158
1156
|
const ReactRefreshAllowConstantExportPackages = ["vite"];
|
|
@@ -1169,24 +1167,12 @@ const ReactRouterPackages = [
|
|
|
1169
1167
|
"@react-router/dev"
|
|
1170
1168
|
];
|
|
1171
1169
|
const NextJsPackages = ["next"];
|
|
1172
|
-
const ReactCompilerPackages = ["babel-plugin-react-compiler"];
|
|
1173
1170
|
async function react(options = {}) {
|
|
1174
|
-
const { files = [GLOB_SRC], filesTypeAware = [GLOB_TS, GLOB_TSX], ignoresTypeAware = [`${GLOB_MARKDOWN}/**`], overrides = {},
|
|
1175
|
-
await ensurePackages([
|
|
1176
|
-
"@eslint-react/eslint-plugin",
|
|
1177
|
-
"eslint-plugin-react-hooks",
|
|
1178
|
-
"eslint-plugin-react-refresh"
|
|
1179
|
-
]);
|
|
1171
|
+
const { files = [GLOB_SRC], filesTypeAware = [GLOB_TS, GLOB_TSX], ignoresTypeAware = [`${GLOB_MARKDOWN}/**`], overrides = {}, tsconfigPath } = options;
|
|
1172
|
+
await ensurePackages(["@eslint-react/eslint-plugin", "eslint-plugin-react-refresh"]);
|
|
1180
1173
|
const isTypeAware = !!tsconfigPath;
|
|
1181
|
-
const typeAwareRules = {
|
|
1182
|
-
|
|
1183
|
-
"react/no-leaked-conditional-rendering": "warn"
|
|
1184
|
-
};
|
|
1185
|
-
const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all([
|
|
1186
|
-
interopDefault(import("@eslint-react/eslint-plugin")),
|
|
1187
|
-
interopDefault(import("eslint-plugin-react-hooks")),
|
|
1188
|
-
interopDefault(import("eslint-plugin-react-refresh"))
|
|
1189
|
-
]);
|
|
1174
|
+
const typeAwareRules = { "react/no-leaked-conditional-rendering": "error" };
|
|
1175
|
+
const [pluginReact, pluginReactRefresh] = await Promise.all([interopDefault(import("@eslint-react/eslint-plugin")), interopDefault(import("eslint-plugin-react-refresh"))]);
|
|
1190
1176
|
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((i) => isPackageExists(i));
|
|
1191
1177
|
const isUsingRemix = RemixPackages.some((i) => isPackageExists(i));
|
|
1192
1178
|
const isUsingReactRouter = ReactRouterPackages.some((i) => isPackageExists(i));
|
|
@@ -1198,8 +1184,6 @@ async function react(options = {}) {
|
|
|
1198
1184
|
plugins: {
|
|
1199
1185
|
"react": plugins["@eslint-react"],
|
|
1200
1186
|
"react-dom": plugins["@eslint-react/dom"],
|
|
1201
|
-
"react-hooks": pluginReactHooks,
|
|
1202
|
-
"react-hooks-extra": plugins["@eslint-react/hooks-extra"],
|
|
1203
1187
|
"react-naming-convention": plugins["@eslint-react/naming-convention"],
|
|
1204
1188
|
"react-refresh": pluginReactRefresh,
|
|
1205
1189
|
"react-rsc": plugins["@eslint-react/rsc"],
|
|
@@ -1214,85 +1198,7 @@ async function react(options = {}) {
|
|
|
1214
1198
|
},
|
|
1215
1199
|
name: "eslint/react/rules",
|
|
1216
1200
|
rules: {
|
|
1217
|
-
|
|
1218
|
-
"react-dom/no-dangerously-set-innerhtml-with-children": "error",
|
|
1219
|
-
"react-dom/no-find-dom-node": "error",
|
|
1220
|
-
"react-dom/no-flush-sync": "error",
|
|
1221
|
-
"react-dom/no-hydrate": "error",
|
|
1222
|
-
"react-dom/no-namespace": "error",
|
|
1223
|
-
"react-dom/no-render": "error",
|
|
1224
|
-
"react-dom/no-render-return-value": "error",
|
|
1225
|
-
"react-dom/no-script-url": "warn",
|
|
1226
|
-
"react-dom/no-unsafe-iframe-sandbox": "warn",
|
|
1227
|
-
"react-dom/no-use-form-state": "error",
|
|
1228
|
-
"react-dom/no-void-elements-with-children": "error",
|
|
1229
|
-
"react-hooks-extra/no-direct-set-state-in-use-effect": "warn",
|
|
1230
|
-
"react-hooks/exhaustive-deps": "warn",
|
|
1231
|
-
"react-hooks/rules-of-hooks": "error",
|
|
1232
|
-
"react-naming-convention/context-name": "warn",
|
|
1233
|
-
"react-naming-convention/ref-name": "warn",
|
|
1234
|
-
"react-naming-convention/use-state": "warn",
|
|
1235
|
-
"react-rsc/function-definition": "error",
|
|
1236
|
-
"react-web-api/no-leaked-event-listener": "warn",
|
|
1237
|
-
"react-web-api/no-leaked-interval": "warn",
|
|
1238
|
-
"react-web-api/no-leaked-resize-observer": "warn",
|
|
1239
|
-
"react-web-api/no-leaked-timeout": "warn",
|
|
1240
|
-
"react/jsx-key-before-spread": "warn",
|
|
1241
|
-
"react/jsx-no-comment-textnodes": "warn",
|
|
1242
|
-
"react/jsx-no-duplicate-props": "warn",
|
|
1243
|
-
"react/jsx-uses-react": "warn",
|
|
1244
|
-
"react/jsx-uses-vars": "warn",
|
|
1245
|
-
"react/no-access-state-in-setstate": "error",
|
|
1246
|
-
"react/no-array-index-key": "warn",
|
|
1247
|
-
"react/no-children-count": "warn",
|
|
1248
|
-
"react/no-children-for-each": "warn",
|
|
1249
|
-
"react/no-children-map": "warn",
|
|
1250
|
-
"react/no-children-only": "warn",
|
|
1251
|
-
"react/no-children-to-array": "warn",
|
|
1252
|
-
"react/no-clone-element": "warn",
|
|
1253
|
-
"react/no-component-will-mount": "error",
|
|
1254
|
-
"react/no-component-will-receive-props": "error",
|
|
1255
|
-
"react/no-component-will-update": "error",
|
|
1256
|
-
"react/no-context-provider": "warn",
|
|
1257
|
-
"react/no-create-ref": "error",
|
|
1258
|
-
"react/no-default-props": "error",
|
|
1259
|
-
"react/no-direct-mutation-state": "error",
|
|
1260
|
-
"react/no-forward-ref": "warn",
|
|
1261
|
-
"react/no-missing-key": "error",
|
|
1262
|
-
"react/no-nested-component-definitions": "error",
|
|
1263
|
-
"react/no-nested-lazy-component-declarations": "error",
|
|
1264
|
-
"react/no-prop-types": "error",
|
|
1265
|
-
"react/no-redundant-should-component-update": "error",
|
|
1266
|
-
"react/no-set-state-in-component-did-mount": "warn",
|
|
1267
|
-
"react/no-set-state-in-component-did-update": "warn",
|
|
1268
|
-
"react/no-set-state-in-component-will-update": "warn",
|
|
1269
|
-
"react/no-string-refs": "error",
|
|
1270
|
-
"react/no-unnecessary-use-prefix": "warn",
|
|
1271
|
-
"react/no-unsafe-component-will-mount": "warn",
|
|
1272
|
-
"react/no-unsafe-component-will-receive-props": "warn",
|
|
1273
|
-
"react/no-unsafe-component-will-update": "warn",
|
|
1274
|
-
"react/no-unused-class-component-members": "warn",
|
|
1275
|
-
"react/no-use-context": "warn",
|
|
1276
|
-
"react/no-useless-forward-ref": "warn",
|
|
1277
|
-
"react/prefer-namespace-import": "error",
|
|
1278
|
-
"react/prefer-use-state-lazy-initialization": "warn",
|
|
1279
|
-
...reactCompiler ? {
|
|
1280
|
-
"react-hooks/component-hook-factories": "error",
|
|
1281
|
-
"react-hooks/config": "error",
|
|
1282
|
-
"react-hooks/error-boundaries": "error",
|
|
1283
|
-
"react-hooks/gating": "error",
|
|
1284
|
-
"react-hooks/globals": "error",
|
|
1285
|
-
"react-hooks/immutability": "error",
|
|
1286
|
-
"react-hooks/incompatible-library": "warn",
|
|
1287
|
-
"react-hooks/preserve-manual-memoization": "error",
|
|
1288
|
-
"react-hooks/purity": "error",
|
|
1289
|
-
"react-hooks/refs": "error",
|
|
1290
|
-
"react-hooks/set-state-in-effect": "error",
|
|
1291
|
-
"react-hooks/set-state-in-render": "error",
|
|
1292
|
-
"react-hooks/static-components": "error",
|
|
1293
|
-
"react-hooks/unsupported-syntax": "warn",
|
|
1294
|
-
"react-hooks/use-memo": "error"
|
|
1295
|
-
} : {},
|
|
1201
|
+
...pluginReact.configs.recommended.rules,
|
|
1296
1202
|
"react-refresh/only-export-components": ["error", {
|
|
1297
1203
|
allowConstantExport: isAllowConstantExport,
|
|
1298
1204
|
allowExportNames: [...isUsingNext ? [
|
|
@@ -1322,6 +1228,7 @@ async function react(options = {}) {
|
|
|
1322
1228
|
"shouldRevalidate"
|
|
1323
1229
|
] : []]
|
|
1324
1230
|
}],
|
|
1231
|
+
"react/prefer-namespace-import": "error",
|
|
1325
1232
|
...overrides
|
|
1326
1233
|
}
|
|
1327
1234
|
},
|
|
@@ -1330,11 +1237,7 @@ async function react(options = {}) {
|
|
|
1330
1237
|
name: "eslint/react/typescript",
|
|
1331
1238
|
rules: {
|
|
1332
1239
|
"react-dom/no-string-style-prop": "off",
|
|
1333
|
-
"react-dom/no-unknown-property": "off"
|
|
1334
|
-
"react/jsx-no-duplicate-props": "off",
|
|
1335
|
-
"react/jsx-no-undef": "off",
|
|
1336
|
-
"react/jsx-uses-react": "off",
|
|
1337
|
-
"react/jsx-uses-vars": "off"
|
|
1240
|
+
"react-dom/no-unknown-property": "off"
|
|
1338
1241
|
}
|
|
1339
1242
|
},
|
|
1340
1243
|
...isTypeAware ? [{
|
|
@@ -1345,7 +1248,6 @@ async function react(options = {}) {
|
|
|
1345
1248
|
}] : []
|
|
1346
1249
|
];
|
|
1347
1250
|
}
|
|
1348
|
-
|
|
1349
1251
|
//#endregion
|
|
1350
1252
|
//#region src/configs/regexp.ts
|
|
1351
1253
|
async function regexp(options = {}) {
|
|
@@ -1363,7 +1265,6 @@ async function regexp(options = {}) {
|
|
|
1363
1265
|
}
|
|
1364
1266
|
}];
|
|
1365
1267
|
}
|
|
1366
|
-
|
|
1367
1268
|
//#endregion
|
|
1368
1269
|
//#region src/configs/sort.ts
|
|
1369
1270
|
/**
|
|
@@ -1596,7 +1497,6 @@ function sortTsconfig() {
|
|
|
1596
1497
|
] }
|
|
1597
1498
|
}];
|
|
1598
1499
|
}
|
|
1599
|
-
|
|
1600
1500
|
//#endregion
|
|
1601
1501
|
//#region src/configs/test.ts
|
|
1602
1502
|
async function test(options = {}) {
|
|
@@ -1625,6 +1525,7 @@ async function test(options = {}) {
|
|
|
1625
1525
|
"test/prefer-hooks-in-order": "error",
|
|
1626
1526
|
"test/prefer-lowercase-title": "error",
|
|
1627
1527
|
"antfu/no-top-level-await": "off",
|
|
1528
|
+
"e18e/prefer-static-regex": "off",
|
|
1628
1529
|
"no-unused-expressions": "off",
|
|
1629
1530
|
"node/prefer-global/process": "off",
|
|
1630
1531
|
"ts/explicit-function-return-type": "off",
|
|
@@ -1632,12 +1533,11 @@ async function test(options = {}) {
|
|
|
1632
1533
|
}
|
|
1633
1534
|
}];
|
|
1634
1535
|
}
|
|
1635
|
-
|
|
1636
1536
|
//#endregion
|
|
1637
1537
|
//#region src/configs/toml.ts
|
|
1638
1538
|
async function toml(options = {}) {
|
|
1639
|
-
const { files = [GLOB_TOML], overrides = {}, stylistic
|
|
1640
|
-
const {
|
|
1539
|
+
const { files = [GLOB_TOML], overrides = {}, stylistic = true } = options;
|
|
1540
|
+
const { other_indent = 2 } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
1641
1541
|
const [pluginToml, parserToml] = await Promise.all([interopDefault(import("eslint-plugin-toml")), interopDefault(import("toml-eslint-parser"))]);
|
|
1642
1542
|
return [{
|
|
1643
1543
|
name: "eslint/toml/setup",
|
|
@@ -1656,11 +1556,11 @@ async function toml(options = {}) {
|
|
|
1656
1556
|
"toml/precision-of-integer": "error",
|
|
1657
1557
|
"toml/tables-order": "error",
|
|
1658
1558
|
"toml/vue-custom-block/no-parsing-error": "error",
|
|
1659
|
-
...stylistic
|
|
1559
|
+
...stylistic ? {
|
|
1660
1560
|
"toml/array-bracket-newline": "error",
|
|
1661
1561
|
"toml/array-bracket-spacing": "error",
|
|
1662
1562
|
"toml/array-element-newline": "error",
|
|
1663
|
-
"toml/indent": ["error", typeof
|
|
1563
|
+
"toml/indent": ["error", typeof other_indent === "number" ? other_indent : other_indent === "tab" ? "tab" : 4],
|
|
1664
1564
|
"toml/inline-table-curly-spacing": "error",
|
|
1665
1565
|
"toml/key-spacing": "error",
|
|
1666
1566
|
"toml/padding-line-between-pairs": "error",
|
|
@@ -1673,14 +1573,13 @@ async function toml(options = {}) {
|
|
|
1673
1573
|
}
|
|
1674
1574
|
}];
|
|
1675
1575
|
}
|
|
1676
|
-
|
|
1677
1576
|
//#endregion
|
|
1678
1577
|
//#region src/configs/typescript.ts
|
|
1679
1578
|
async function typescript(options = {}) {
|
|
1680
1579
|
const { componentExts = [], erasableOnly = false, overrides = {}, parserOptions = {}, type = "app" } = options;
|
|
1681
|
-
const files = options.files ?? [
|
|
1682
|
-
const ignoresTypeAware = options.ignoresTypeAware ?? [
|
|
1683
|
-
const filesTypeAware = options.filesTypeAware ?? [
|
|
1580
|
+
const files = options.files ?? ["**/*.?([cm])[jt]s?(x)", ...componentExts.map((ext) => `**/*.${ext}`)];
|
|
1581
|
+
const ignoresTypeAware = options.ignoresTypeAware ?? [`**/*.md/**`];
|
|
1582
|
+
const filesTypeAware = options.filesTypeAware ?? ["**/*.?([cm])ts", "**/*.?([cm])tsx"];
|
|
1684
1583
|
const tsconfigPath = options?.tsconfigPath ? options.tsconfigPath : void 0;
|
|
1685
1584
|
const isTypeAware = !!tsconfigPath;
|
|
1686
1585
|
const typeAwareRules = {
|
|
@@ -1710,10 +1609,10 @@ async function typescript(options = {}) {
|
|
|
1710
1609
|
"ts/unbound-method": "error"
|
|
1711
1610
|
};
|
|
1712
1611
|
const [pluginTs, parserTs] = await Promise.all([interopDefault(import("@typescript-eslint/eslint-plugin")), interopDefault(import("@typescript-eslint/parser"))]);
|
|
1713
|
-
function makeParser(typeAware, files
|
|
1612
|
+
function makeParser(typeAware, files, ignores) {
|
|
1714
1613
|
return {
|
|
1715
|
-
files
|
|
1716
|
-
...ignores
|
|
1614
|
+
files,
|
|
1615
|
+
...ignores ? { ignores } : {},
|
|
1717
1616
|
languageOptions: {
|
|
1718
1617
|
parser: parserTs,
|
|
1719
1618
|
parserOptions: {
|
|
@@ -1823,7 +1722,6 @@ async function typescript(options = {}) {
|
|
|
1823
1722
|
}] : []
|
|
1824
1723
|
];
|
|
1825
1724
|
}
|
|
1826
|
-
|
|
1827
1725
|
//#endregion
|
|
1828
1726
|
//#region src/configs/unicorn.ts
|
|
1829
1727
|
async function unicorn(options = {}) {
|
|
@@ -1853,7 +1751,6 @@ async function unicorn(options = {}) {
|
|
|
1853
1751
|
}
|
|
1854
1752
|
}];
|
|
1855
1753
|
}
|
|
1856
|
-
|
|
1857
1754
|
//#endregion
|
|
1858
1755
|
//#region src/configs/unocss.ts
|
|
1859
1756
|
async function unocss(options = {}) {
|
|
@@ -1871,7 +1768,6 @@ async function unocss(options = {}) {
|
|
|
1871
1768
|
}
|
|
1872
1769
|
}];
|
|
1873
1770
|
}
|
|
1874
|
-
|
|
1875
1771
|
//#endregion
|
|
1876
1772
|
//#region src/configs/vue.ts
|
|
1877
1773
|
const pkg = getPackageInfoSync("vue");
|
|
@@ -1879,9 +1775,9 @@ let vueVersion = pkg && pkg.version;
|
|
|
1879
1775
|
vueVersion = vueVersion && vueVersion[0];
|
|
1880
1776
|
vueVersion = Number.isNaN(vueVersion) ? "3" : vueVersion;
|
|
1881
1777
|
async function vue(options = {}) {
|
|
1882
|
-
const { files = [GLOB_VUE], overrides = {}, stylistic
|
|
1778
|
+
const { files = [GLOB_VUE], overrides = {}, stylistic = true } = options;
|
|
1883
1779
|
const sfcBlocks = options.sfcBlocks === true ? {} : options.sfcBlocks ?? {};
|
|
1884
|
-
const { indent = 4 } = typeof stylistic
|
|
1780
|
+
const { indent = 4 } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
1885
1781
|
const [pluginVue, parserVue, processorVueBlocks] = await Promise.all([
|
|
1886
1782
|
interopDefault(import("eslint-plugin-vue")),
|
|
1887
1783
|
interopDefault(import("vue-eslint-parser")),
|
|
@@ -2034,7 +1930,7 @@ async function vue(options = {}) {
|
|
|
2034
1930
|
nonwords: false,
|
|
2035
1931
|
words: true
|
|
2036
1932
|
}],
|
|
2037
|
-
...stylistic
|
|
1933
|
+
...stylistic ? {
|
|
2038
1934
|
"vue/array-bracket-spacing": ["error", "never"],
|
|
2039
1935
|
"vue/arrow-spacing": ["error", {
|
|
2040
1936
|
after: true,
|
|
@@ -2082,12 +1978,11 @@ async function vue(options = {}) {
|
|
|
2082
1978
|
}
|
|
2083
1979
|
}];
|
|
2084
1980
|
}
|
|
2085
|
-
|
|
2086
1981
|
//#endregion
|
|
2087
1982
|
//#region src/configs/yaml.ts
|
|
2088
1983
|
async function yaml(options = {}) {
|
|
2089
|
-
const { files = [GLOB_YAML], overrides = {}, stylistic
|
|
2090
|
-
const { quotes = "single" } = typeof stylistic
|
|
1984
|
+
const { files = [GLOB_YAML], overrides = {}, stylistic = true } = options;
|
|
1985
|
+
const { other_indent = 2, quotes = "single" } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
2091
1986
|
const [pluginYaml, parserYaml] = await Promise.all([interopDefault(import("eslint-plugin-yml")), interopDefault(import("yaml-eslint-parser"))]);
|
|
2092
1987
|
return [{
|
|
2093
1988
|
name: "eslint/yaml/setup",
|
|
@@ -2105,14 +2000,14 @@ async function yaml(options = {}) {
|
|
|
2105
2000
|
"yaml/no-irregular-whitespace": "error",
|
|
2106
2001
|
"yaml/plain-scalar": "error",
|
|
2107
2002
|
"yaml/vue-custom-block/no-parsing-error": "error",
|
|
2108
|
-
...stylistic
|
|
2003
|
+
...stylistic ? {
|
|
2109
2004
|
"yaml/block-mapping-question-indicator-newline": "error",
|
|
2110
2005
|
"yaml/block-sequence-hyphen-indicator-newline": "error",
|
|
2111
2006
|
"yaml/flow-mapping-curly-newline": "error",
|
|
2112
2007
|
"yaml/flow-mapping-curly-spacing": "error",
|
|
2113
2008
|
"yaml/flow-sequence-bracket-newline": "error",
|
|
2114
2009
|
"yaml/flow-sequence-bracket-spacing": "error",
|
|
2115
|
-
"yaml/indent": ["error", 2],
|
|
2010
|
+
"yaml/indent": ["error", typeof other_indent === "number" ? other_indent : 2],
|
|
2116
2011
|
"yaml/key-spacing": "error",
|
|
2117
2012
|
"yaml/no-tab-indent": "error",
|
|
2118
2013
|
"yaml/quotes": ["error", {
|
|
@@ -2125,7 +2020,6 @@ async function yaml(options = {}) {
|
|
|
2125
2020
|
}
|
|
2126
2021
|
}];
|
|
2127
2022
|
}
|
|
2128
|
-
|
|
2129
2023
|
//#endregion
|
|
2130
2024
|
//#region src/factory.ts
|
|
2131
2025
|
const flatConfigProps = [
|
|
@@ -2146,8 +2040,9 @@ const VuePackages = [
|
|
|
2146
2040
|
const defaultPluginRenaming = {
|
|
2147
2041
|
"@eslint-react": "react",
|
|
2148
2042
|
"@eslint-react/dom": "react-dom",
|
|
2149
|
-
"@eslint-react/hooks-extra": "react-hooks-extra",
|
|
2150
2043
|
"@eslint-react/naming-convention": "react-naming-convention",
|
|
2044
|
+
"@eslint-react/rsc": "react-rsc",
|
|
2045
|
+
"@eslint-react/web-api": "react-web-api",
|
|
2151
2046
|
"@next/next": "next",
|
|
2152
2047
|
"@stylistic": "style",
|
|
2153
2048
|
"@typescript-eslint": "ts",
|
|
@@ -2167,7 +2062,7 @@ const defaultPluginRenaming = {
|
|
|
2167
2062
|
* 合并的 ESLint 配置
|
|
2168
2063
|
*/
|
|
2169
2064
|
function lincy(options = {}, ...userConfigs) {
|
|
2170
|
-
const { autoRenamePlugins = true, componentExts = [], gitignore: enableGitignore = true, ignores:
|
|
2065
|
+
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;
|
|
2171
2066
|
let isInEditor = options.isInEditor;
|
|
2172
2067
|
if (isInEditor == null) {
|
|
2173
2068
|
isInEditor = isInEditorEnv();
|
|
@@ -2175,101 +2070,108 @@ function lincy(options = {}, ...userConfigs) {
|
|
|
2175
2070
|
}
|
|
2176
2071
|
const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
|
|
2177
2072
|
if (stylisticOptions && !("jsx" in stylisticOptions)) stylisticOptions.jsx = enableJsx;
|
|
2178
|
-
const configs
|
|
2179
|
-
if (enableGitignore) if (typeof enableGitignore !== "boolean") configs
|
|
2073
|
+
const configs = [];
|
|
2074
|
+
if (enableGitignore) if (typeof enableGitignore !== "boolean") configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
|
|
2180
2075
|
name: "eslint/gitignore",
|
|
2181
2076
|
...enableGitignore
|
|
2182
2077
|
})]));
|
|
2183
|
-
else configs
|
|
2078
|
+
else configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
|
|
2184
2079
|
name: "eslint/gitignore",
|
|
2185
2080
|
strict: false
|
|
2186
2081
|
})]));
|
|
2187
2082
|
const typescriptOptions = resolveSubOptions(options, "typescript");
|
|
2188
2083
|
const tsconfigPath = "tsconfigPath" in typescriptOptions ? typescriptOptions.tsconfigPath : void 0;
|
|
2189
|
-
configs
|
|
2084
|
+
configs.push(ignores([...overrides.ignores || [], ...userIgnores], !enableTypeScript), javascript({
|
|
2190
2085
|
isInEditor,
|
|
2191
2086
|
overrides: getOverrides(options, "javascript")
|
|
2192
2087
|
}), comments({ overrides: getOverrides(options, "comments") }), node({ overrides: getOverrides(options, "node") }), jsdoc({
|
|
2193
2088
|
overrides: getOverrides(options, "jsdoc"),
|
|
2194
2089
|
stylistic: stylisticOptions
|
|
2195
2090
|
}), perfectionist({ overrides: getOverrides(options, "perfectionist") }));
|
|
2196
|
-
if (
|
|
2091
|
+
if (enableE18e) configs.push(e18e({
|
|
2092
|
+
isInEditor,
|
|
2093
|
+
...enableE18e === true ? {} : enableE18e
|
|
2094
|
+
}));
|
|
2095
|
+
if (enableUnicorn) configs.push(unicorn({
|
|
2197
2096
|
...enableUnicorn === true ? {} : enableUnicorn,
|
|
2198
2097
|
overrides: getOverrides(options, "unicorn")
|
|
2199
2098
|
}));
|
|
2200
|
-
if (enableImports) configs
|
|
2099
|
+
if (enableImports) configs.push(imports({
|
|
2201
2100
|
overrides: getOverrides(options, "imports"),
|
|
2202
2101
|
stylistic: stylisticOptions
|
|
2203
2102
|
}));
|
|
2204
2103
|
if (enableVue) componentExts.push("vue");
|
|
2205
|
-
if (enableJsx) configs
|
|
2206
|
-
if (enableTypeScript) configs
|
|
2104
|
+
if (enableJsx) configs.push(jsx());
|
|
2105
|
+
if (enableTypeScript) configs.push(typescript({
|
|
2207
2106
|
...typescriptOptions,
|
|
2208
2107
|
componentExts,
|
|
2209
2108
|
overrides: getOverrides(options, "typescript"),
|
|
2210
2109
|
tsconfigPath,
|
|
2211
|
-
type:
|
|
2110
|
+
type: appType
|
|
2212
2111
|
}));
|
|
2213
|
-
if (stylisticOptions) configs
|
|
2112
|
+
if (stylisticOptions) configs.push(stylistic({
|
|
2214
2113
|
overrides: getOverrides(options, "stylistic"),
|
|
2215
2114
|
stylistic: stylisticOptions
|
|
2216
2115
|
}));
|
|
2217
|
-
if (enableRegexp) configs
|
|
2116
|
+
if (enableRegexp) configs.push(regexp({
|
|
2218
2117
|
...resolveSubOptions(options, "regexp"),
|
|
2219
2118
|
...getOverrides(options, "regexp")
|
|
2220
2119
|
}));
|
|
2221
|
-
if (options.test ?? true) configs
|
|
2120
|
+
if (options.test ?? true) configs.push(test({
|
|
2222
2121
|
...resolveSubOptions(options, "test"),
|
|
2223
2122
|
isInEditor,
|
|
2224
2123
|
overrides: getOverrides(options, "test")
|
|
2225
2124
|
}));
|
|
2226
|
-
if (enableVue) configs
|
|
2125
|
+
if (enableVue) configs.push(vue({
|
|
2227
2126
|
...resolveSubOptions(options, "vue"),
|
|
2228
2127
|
overrides: getOverrides(options, "vue"),
|
|
2229
2128
|
stylistic: stylisticOptions,
|
|
2230
2129
|
typescript: !!enableTypeScript
|
|
2231
2130
|
}));
|
|
2232
|
-
if (enableReact) configs
|
|
2131
|
+
if (enableReact) configs.push(react({
|
|
2233
2132
|
...typescriptOptions,
|
|
2234
2133
|
...resolveSubOptions(options, "react"),
|
|
2235
2134
|
overrides: getOverrides(options, "react"),
|
|
2236
2135
|
tsconfigPath
|
|
2237
2136
|
}));
|
|
2238
|
-
if (enableNextjs) configs
|
|
2239
|
-
if (enableUnoCSS) configs
|
|
2137
|
+
if (enableNextjs) configs.push(nextjs({ overrides: getOverrides(options, "nextjs") }));
|
|
2138
|
+
if (enableUnoCSS) configs.push(unocss({
|
|
2240
2139
|
...resolveSubOptions(options, "unocss"),
|
|
2241
2140
|
overrides: getOverrides(options, "unocss")
|
|
2242
2141
|
}));
|
|
2243
|
-
if (options.jsonc ?? true) configs
|
|
2142
|
+
if (options.jsonc ?? true) configs.push(jsonc({
|
|
2244
2143
|
...resolveSubOptions(options, "jsonc"),
|
|
2245
2144
|
overrides: getOverrides(options, "jsonc"),
|
|
2246
2145
|
stylistic: stylisticOptions
|
|
2247
2146
|
}), sortPackageJson(), sortTsconfig());
|
|
2248
|
-
if (enableCatalogs) configs
|
|
2249
|
-
|
|
2147
|
+
if (enableCatalogs) configs.push(pnpm({
|
|
2148
|
+
isInEditor,
|
|
2149
|
+
...resolveSubOptions(options, "pnpm")
|
|
2150
|
+
}));
|
|
2151
|
+
if (options.yaml ?? true) configs.push(yaml({
|
|
2250
2152
|
...resolveSubOptions(options, "yaml"),
|
|
2251
2153
|
overrides: getOverrides(options, "yaml"),
|
|
2252
2154
|
stylistic: stylisticOptions
|
|
2253
2155
|
}));
|
|
2254
|
-
if (options.toml ?? true) configs
|
|
2156
|
+
if (options.toml ?? true) configs.push(toml({
|
|
2255
2157
|
overrides: getOverrides(options, "toml"),
|
|
2256
2158
|
stylistic: stylisticOptions
|
|
2257
2159
|
}));
|
|
2258
|
-
if (options.markdown ?? true) configs
|
|
2160
|
+
if (options.markdown ?? true) configs.push(markdown({
|
|
2259
2161
|
...resolveSubOptions(options, "markdown"),
|
|
2260
2162
|
componentExts,
|
|
2261
2163
|
overrides: getOverrides(options, "markdown")
|
|
2262
2164
|
}));
|
|
2263
|
-
if (options.formatters) configs
|
|
2264
|
-
configs
|
|
2165
|
+
if (options.formatters) configs.push(formatters(options.formatters, typeof stylisticOptions === "boolean" ? {} : stylisticOptions));
|
|
2166
|
+
configs.push(disables());
|
|
2265
2167
|
if ("files" in options) throw new Error("[@lincy/eslint-config] 第一个参数不应包含“files”属性,因为选项应该是全局的。请将其放在第二个或更后面的配置中。");
|
|
2266
2168
|
const fusedConfig = flatConfigProps.reduce((acc, key) => {
|
|
2267
2169
|
if (key in options) acc[key] = options[key];
|
|
2268
2170
|
return acc;
|
|
2269
2171
|
}, {});
|
|
2270
|
-
if (Object.keys(fusedConfig).length) configs
|
|
2172
|
+
if (Object.keys(fusedConfig).length) configs.push([fusedConfig]);
|
|
2271
2173
|
let composer = new FlatConfigComposer();
|
|
2272
|
-
composer = composer.append(...configs
|
|
2174
|
+
composer = composer.append(...configs, ...userConfigs);
|
|
2273
2175
|
if (autoRenamePlugins) composer = composer.renamePlugins(defaultPluginRenaming);
|
|
2274
2176
|
if (isInEditor) composer = composer.disableRulesFix([
|
|
2275
2177
|
"unused-imports/no-unused-imports",
|
|
@@ -2288,10 +2190,8 @@ function getOverrides(options, key) {
|
|
|
2288
2190
|
..."overrides" in sub ? sub.overrides : {}
|
|
2289
2191
|
};
|
|
2290
2192
|
}
|
|
2291
|
-
|
|
2292
2193
|
//#endregion
|
|
2293
2194
|
//#region src/index.ts
|
|
2294
2195
|
var src_default = lincy;
|
|
2295
|
-
|
|
2296
2196
|
//#endregion
|
|
2297
|
-
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_SVELTE, 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, 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 };
|
|
2197
|
+
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_SVELTE, 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 };
|