@liwo/eslint-config 0.2.0 → 0.2.2
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/dist/index.d.ts +2648 -2290
- package/dist/index.js +84 -111
- package/package.json +51 -54
package/dist/index.js
CHANGED
|
@@ -13,7 +13,6 @@ import { fileURLToPath } from "node:url";
|
|
|
13
13
|
import globals from "globals";
|
|
14
14
|
import { mergeProcessors, processorPassThrough } from "eslint-merge-processors";
|
|
15
15
|
import { configs } from "eslint-plugin-regexp";
|
|
16
|
-
|
|
17
16
|
//#region src/configs/command.ts
|
|
18
17
|
async function command() {
|
|
19
18
|
return [{
|
|
@@ -21,7 +20,6 @@ async function command() {
|
|
|
21
20
|
name: "liwo/command/rules"
|
|
22
21
|
}];
|
|
23
22
|
}
|
|
24
|
-
|
|
25
23
|
//#endregion
|
|
26
24
|
//#region src/configs/comments.ts
|
|
27
25
|
async function comments() {
|
|
@@ -36,7 +34,6 @@ async function comments() {
|
|
|
36
34
|
}
|
|
37
35
|
}];
|
|
38
36
|
}
|
|
39
|
-
|
|
40
37
|
//#endregion
|
|
41
38
|
//#region src/globs.ts
|
|
42
39
|
const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
|
|
@@ -114,7 +111,6 @@ const GLOB_EXCLUDE = [
|
|
|
114
111
|
"**/auto-import?(s).d.ts",
|
|
115
112
|
"**/components.d.ts"
|
|
116
113
|
];
|
|
117
|
-
|
|
118
114
|
//#endregion
|
|
119
115
|
//#region src/configs/disables.ts
|
|
120
116
|
async function disables() {
|
|
@@ -169,7 +165,6 @@ async function disables() {
|
|
|
169
165
|
}
|
|
170
166
|
];
|
|
171
167
|
}
|
|
172
|
-
|
|
173
168
|
//#endregion
|
|
174
169
|
//#region src/utils.ts
|
|
175
170
|
const scopeUrl = fileURLToPath(new URL(".", import.meta.url));
|
|
@@ -196,8 +191,8 @@ const parserPlain = {
|
|
|
196
191
|
/**
|
|
197
192
|
* Combine array and non-array configs into a single array.
|
|
198
193
|
*/
|
|
199
|
-
async function combine(...configs
|
|
200
|
-
return (await Promise.all(configs
|
|
194
|
+
async function combine(...configs) {
|
|
195
|
+
return (await Promise.all(configs)).flat();
|
|
201
196
|
}
|
|
202
197
|
/**
|
|
203
198
|
* Rename plugin prefixes in a rule object.
|
|
@@ -237,8 +232,8 @@ function renameRules(rules, map) {
|
|
|
237
232
|
* })
|
|
238
233
|
* ```
|
|
239
234
|
*/
|
|
240
|
-
function renamePluginInConfigs(configs
|
|
241
|
-
return configs
|
|
235
|
+
function renamePluginInConfigs(configs, map) {
|
|
236
|
+
return configs.map((i) => {
|
|
242
237
|
const clone = { ...i };
|
|
243
238
|
if (clone.rules) clone.rules = renameRules(clone.rules, map);
|
|
244
239
|
if (clone.plugins) clone.plugins = Object.fromEntries(Object.entries(clone.plugins).map(([key, value]) => {
|
|
@@ -272,7 +267,6 @@ function isInEditorEnv() {
|
|
|
272
267
|
function isInGitHooksOrLintStaged() {
|
|
273
268
|
return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged"));
|
|
274
269
|
}
|
|
275
|
-
|
|
276
270
|
//#endregion
|
|
277
271
|
//#region src/configs/stylistic.ts
|
|
278
272
|
const StylisticConfigDefaults = {
|
|
@@ -282,14 +276,14 @@ const StylisticConfigDefaults = {
|
|
|
282
276
|
semi: false
|
|
283
277
|
};
|
|
284
278
|
async function stylistic(options = {}) {
|
|
285
|
-
const { indent, jsx
|
|
279
|
+
const { indent, jsx, lessOpinionated = false, overrides = {}, quotes, semi } = {
|
|
286
280
|
...StylisticConfigDefaults,
|
|
287
281
|
...options
|
|
288
282
|
};
|
|
289
283
|
const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
|
|
290
284
|
const config = pluginStylistic.configs.customize({
|
|
291
285
|
indent,
|
|
292
|
-
jsx
|
|
286
|
+
jsx,
|
|
293
287
|
pluginName: "style",
|
|
294
288
|
quotes,
|
|
295
289
|
semi
|
|
@@ -322,7 +316,6 @@ async function stylistic(options = {}) {
|
|
|
322
316
|
}
|
|
323
317
|
}];
|
|
324
318
|
}
|
|
325
|
-
|
|
326
319
|
//#endregion
|
|
327
320
|
//#region src/configs/formatters.ts
|
|
328
321
|
function mergePrettierOptions(options, overrides = {}) {
|
|
@@ -332,7 +325,7 @@ function mergePrettierOptions(options, overrides = {}) {
|
|
|
332
325
|
plugins: [...overrides.plugins || [], ...options.plugins || []]
|
|
333
326
|
};
|
|
334
327
|
}
|
|
335
|
-
async function formatters(options = {}, stylistic
|
|
328
|
+
async function formatters(options = {}, stylistic = {}) {
|
|
336
329
|
if (options === true) {
|
|
337
330
|
const isPrettierPluginXmlInScope = isPackageInScope("@prettier/plugin-xml");
|
|
338
331
|
options = {
|
|
@@ -353,7 +346,7 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
353
346
|
if (options.slidev && options.markdown !== true && options.markdown !== "prettier") throw new Error("`slidev` option only works when `markdown` is enabled with `prettier`");
|
|
354
347
|
const { indent, quotes, semi } = {
|
|
355
348
|
...StylisticConfigDefaults,
|
|
356
|
-
...stylistic
|
|
349
|
+
...stylistic
|
|
357
350
|
};
|
|
358
351
|
const prettierOptions = Object.assign({
|
|
359
352
|
endOfLine: "auto",
|
|
@@ -375,11 +368,11 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
375
368
|
quoteStyle: quotes === "single" ? "preferSingle" : "preferDouble",
|
|
376
369
|
useTabs: indent === "tab"
|
|
377
370
|
}, options.dprintOptions || {});
|
|
378
|
-
const configs
|
|
371
|
+
const configs = [{
|
|
379
372
|
name: "liwo/formatter/setup",
|
|
380
373
|
plugins: { format: await interopDefault(import("eslint-plugin-format")) }
|
|
381
374
|
}];
|
|
382
|
-
if (options.css) configs
|
|
375
|
+
if (options.css) configs.push({
|
|
383
376
|
files: [GLOB_CSS, GLOB_POSTCSS],
|
|
384
377
|
languageOptions: { parser: parserPlain },
|
|
385
378
|
name: "liwo/formatter/css",
|
|
@@ -395,13 +388,13 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
395
388
|
name: "liwo/formatter/less",
|
|
396
389
|
rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "less" })] }
|
|
397
390
|
});
|
|
398
|
-
if (options.html) configs
|
|
391
|
+
if (options.html) configs.push({
|
|
399
392
|
files: [GLOB_HTML],
|
|
400
393
|
languageOptions: { parser: parserPlain },
|
|
401
394
|
name: "liwo/formatter/html",
|
|
402
395
|
rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "html" })] }
|
|
403
396
|
});
|
|
404
|
-
if (options.xml) configs
|
|
397
|
+
if (options.xml) configs.push({
|
|
405
398
|
files: [GLOB_XML],
|
|
406
399
|
languageOptions: { parser: parserPlain },
|
|
407
400
|
name: "liwo/formatter/xml",
|
|
@@ -413,7 +406,7 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
413
406
|
plugins: ["@prettier/plugin-xml"]
|
|
414
407
|
})] }
|
|
415
408
|
});
|
|
416
|
-
if (options.svg) configs
|
|
409
|
+
if (options.svg) configs.push({
|
|
417
410
|
files: [GLOB_SVG],
|
|
418
411
|
languageOptions: { parser: parserPlain },
|
|
419
412
|
name: "liwo/formatter/svg",
|
|
@@ -428,7 +421,7 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
428
421
|
if (options.markdown) {
|
|
429
422
|
const formater = options.markdown === true ? "prettier" : options.markdown;
|
|
430
423
|
const GLOB_SLIDEV = !options.slidev ? [] : options.slidev === true ? ["**/slides.md"] : options.slidev.files;
|
|
431
|
-
configs
|
|
424
|
+
configs.push({
|
|
432
425
|
files: [GLOB_MARKDOWN],
|
|
433
426
|
ignores: GLOB_SLIDEV,
|
|
434
427
|
languageOptions: { parser: parserPlain },
|
|
@@ -441,7 +434,7 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
441
434
|
language: "markdown"
|
|
442
435
|
}] }
|
|
443
436
|
});
|
|
444
|
-
if (options.slidev) configs
|
|
437
|
+
if (options.slidev) configs.push({
|
|
445
438
|
files: GLOB_SLIDEV,
|
|
446
439
|
languageOptions: { parser: parserPlain },
|
|
447
440
|
name: "liwo/formatter/slidev",
|
|
@@ -452,15 +445,14 @@ async function formatters(options = {}, stylistic$1 = {}) {
|
|
|
452
445
|
})] }
|
|
453
446
|
});
|
|
454
447
|
}
|
|
455
|
-
if (options.graphql) configs
|
|
448
|
+
if (options.graphql) configs.push({
|
|
456
449
|
files: [GLOB_GRAPHQL],
|
|
457
450
|
languageOptions: { parser: parserPlain },
|
|
458
451
|
name: "liwo/formatter/graphql",
|
|
459
452
|
rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "graphql" })] }
|
|
460
453
|
});
|
|
461
|
-
return configs
|
|
454
|
+
return configs;
|
|
462
455
|
}
|
|
463
|
-
|
|
464
456
|
//#endregion
|
|
465
457
|
//#region src/configs/ignores.ts
|
|
466
458
|
async function ignores(userIgnores = []) {
|
|
@@ -469,11 +461,10 @@ async function ignores(userIgnores = []) {
|
|
|
469
461
|
name: "liwo/ignores"
|
|
470
462
|
}];
|
|
471
463
|
}
|
|
472
|
-
|
|
473
464
|
//#endregion
|
|
474
465
|
//#region src/configs/imports.ts
|
|
475
466
|
async function imports(options = {}) {
|
|
476
|
-
const { overrides = {}, stylistic
|
|
467
|
+
const { overrides = {}, stylistic = true } = options;
|
|
477
468
|
return [{
|
|
478
469
|
name: "liwo/imports/rules",
|
|
479
470
|
plugins: {
|
|
@@ -489,12 +480,11 @@ async function imports(options = {}) {
|
|
|
489
480
|
"import/no-duplicates": "error",
|
|
490
481
|
"import/no-mutable-exports": "error",
|
|
491
482
|
"import/no-named-default": "error",
|
|
492
|
-
...stylistic
|
|
483
|
+
...stylistic ? { "import/newline-after-import": ["error", { count: 1 }] } : {},
|
|
493
484
|
...overrides
|
|
494
485
|
}
|
|
495
486
|
}];
|
|
496
487
|
}
|
|
497
|
-
|
|
498
488
|
//#endregion
|
|
499
489
|
//#region src/configs/javascript.ts
|
|
500
490
|
async function javascript(options = {}) {
|
|
@@ -719,11 +709,10 @@ async function javascript(options = {}) {
|
|
|
719
709
|
}
|
|
720
710
|
}];
|
|
721
711
|
}
|
|
722
|
-
|
|
723
712
|
//#endregion
|
|
724
713
|
//#region src/configs/jsdoc.ts
|
|
725
714
|
async function jsdoc(options = {}) {
|
|
726
|
-
const { stylistic
|
|
715
|
+
const { stylistic = true } = options;
|
|
727
716
|
return [{
|
|
728
717
|
name: "liwo/jsdoc/rules",
|
|
729
718
|
plugins: { jsdoc: await interopDefault(import("eslint-plugin-jsdoc")) },
|
|
@@ -743,14 +732,13 @@ async function jsdoc(options = {}) {
|
|
|
743
732
|
"jsdoc/require-returns-check": "warn",
|
|
744
733
|
"jsdoc/require-returns-description": "warn",
|
|
745
734
|
"jsdoc/require-yields-check": "warn",
|
|
746
|
-
...stylistic
|
|
735
|
+
...stylistic ? {
|
|
747
736
|
"jsdoc/check-alignment": "warn",
|
|
748
737
|
"jsdoc/multiline-blocks": "warn"
|
|
749
738
|
} : {}
|
|
750
739
|
}
|
|
751
740
|
}];
|
|
752
741
|
}
|
|
753
|
-
|
|
754
742
|
//#endregion
|
|
755
743
|
//#region src/configs/jsonc.ts
|
|
756
744
|
async function jsonc(options = {}) {
|
|
@@ -758,8 +746,8 @@ async function jsonc(options = {}) {
|
|
|
758
746
|
GLOB_JSON,
|
|
759
747
|
GLOB_JSON5,
|
|
760
748
|
GLOB_JSONC
|
|
761
|
-
], overrides = {}, stylistic
|
|
762
|
-
const { indent = 2 } = typeof stylistic
|
|
749
|
+
], overrides = {}, stylistic = true } = options;
|
|
750
|
+
const { indent = 2 } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
763
751
|
const [pluginJsonc, parserJsonc] = await Promise.all([interopDefault(import("eslint-plugin-jsonc")), interopDefault(import("jsonc-eslint-parser"))]);
|
|
764
752
|
return [{
|
|
765
753
|
name: "liwo/jsonc/setup",
|
|
@@ -795,7 +783,7 @@ async function jsonc(options = {}) {
|
|
|
795
783
|
"jsonc/space-unary-ops": "error",
|
|
796
784
|
"jsonc/valid-json-number": "error",
|
|
797
785
|
"jsonc/vue-custom-block/no-parsing-error": "error",
|
|
798
|
-
...stylistic
|
|
786
|
+
...stylistic ? {
|
|
799
787
|
"jsonc/array-bracket-spacing": ["error", "never"],
|
|
800
788
|
"jsonc/comma-dangle": ["error", "never"],
|
|
801
789
|
"jsonc/comma-style": ["error", "last"],
|
|
@@ -817,7 +805,6 @@ async function jsonc(options = {}) {
|
|
|
817
805
|
}
|
|
818
806
|
}];
|
|
819
807
|
}
|
|
820
|
-
|
|
821
808
|
//#endregion
|
|
822
809
|
//#region src/configs/jsx.ts
|
|
823
810
|
async function jsx() {
|
|
@@ -827,22 +814,21 @@ async function jsx() {
|
|
|
827
814
|
name: "liwo/jsx/setup"
|
|
828
815
|
}];
|
|
829
816
|
}
|
|
830
|
-
|
|
831
817
|
//#endregion
|
|
832
818
|
//#region src/configs/markdown.ts
|
|
833
819
|
async function markdown(options = {}) {
|
|
834
820
|
const { componentExts = [], files = [GLOB_MARKDOWN], overrides = {} } = options;
|
|
835
|
-
const markdown
|
|
821
|
+
const markdown = await interopDefault(import("@eslint/markdown"));
|
|
836
822
|
return [
|
|
837
823
|
{
|
|
838
824
|
name: "liwo/markdown/setup",
|
|
839
|
-
plugins: { markdown
|
|
825
|
+
plugins: { markdown }
|
|
840
826
|
},
|
|
841
827
|
{
|
|
842
828
|
files,
|
|
843
829
|
ignores: [GLOB_MARKDOWN_IN_MARKDOWN],
|
|
844
830
|
name: "liwo/markdown/processor",
|
|
845
|
-
processor: mergeProcessors([markdown
|
|
831
|
+
processor: mergeProcessors([markdown.processors.markdown, processorPassThrough])
|
|
846
832
|
},
|
|
847
833
|
{
|
|
848
834
|
files,
|
|
@@ -884,7 +870,6 @@ async function markdown(options = {}) {
|
|
|
884
870
|
}
|
|
885
871
|
];
|
|
886
872
|
}
|
|
887
|
-
|
|
888
873
|
//#endregion
|
|
889
874
|
//#region src/configs/node.ts
|
|
890
875
|
async function node() {
|
|
@@ -903,7 +888,6 @@ async function node() {
|
|
|
903
888
|
}
|
|
904
889
|
}];
|
|
905
890
|
}
|
|
906
|
-
|
|
907
891
|
//#endregion
|
|
908
892
|
//#region src/configs/perfectionist.ts
|
|
909
893
|
/**
|
|
@@ -922,26 +906,27 @@ async function perfectionist() {
|
|
|
922
906
|
}],
|
|
923
907
|
"perfectionist/sort-imports": ["error", {
|
|
924
908
|
groups: [
|
|
925
|
-
"type",
|
|
909
|
+
"type-import",
|
|
926
910
|
[
|
|
927
|
-
"parent
|
|
928
|
-
"sibling
|
|
929
|
-
"index
|
|
930
|
-
"internal
|
|
911
|
+
"type-parent",
|
|
912
|
+
"type-sibling",
|
|
913
|
+
"type-index",
|
|
914
|
+
"type-internal"
|
|
931
915
|
],
|
|
932
|
-
"builtin",
|
|
933
|
-
"external",
|
|
934
|
-
"internal",
|
|
916
|
+
"value-builtin",
|
|
917
|
+
"value-external",
|
|
918
|
+
"value-internal",
|
|
935
919
|
[
|
|
936
|
-
"parent",
|
|
937
|
-
"sibling",
|
|
938
|
-
"index"
|
|
920
|
+
"value-parent",
|
|
921
|
+
"value-sibling",
|
|
922
|
+
"value-index"
|
|
939
923
|
],
|
|
940
924
|
"side-effect",
|
|
941
|
-
"
|
|
925
|
+
"ts-equals-import",
|
|
942
926
|
"unknown"
|
|
943
927
|
],
|
|
944
928
|
newlinesBetween: "ignore",
|
|
929
|
+
newlinesInside: "ignore",
|
|
945
930
|
order: "asc",
|
|
946
931
|
type: "natural"
|
|
947
932
|
}],
|
|
@@ -956,7 +941,6 @@ async function perfectionist() {
|
|
|
956
941
|
}
|
|
957
942
|
}];
|
|
958
943
|
}
|
|
959
|
-
|
|
960
944
|
//#endregion
|
|
961
945
|
//#region src/configs/pnpm.ts
|
|
962
946
|
async function pnpm() {
|
|
@@ -986,7 +970,6 @@ async function pnpm() {
|
|
|
986
970
|
}
|
|
987
971
|
}];
|
|
988
972
|
}
|
|
989
|
-
|
|
990
973
|
//#endregion
|
|
991
974
|
//#region src/configs/react.ts
|
|
992
975
|
const ReactRefreshAllowConstantExportPackages = ["vite"];
|
|
@@ -1011,7 +994,10 @@ async function react(options = {}) {
|
|
|
1011
994
|
"eslint-plugin-react-refresh"
|
|
1012
995
|
]);
|
|
1013
996
|
const isTypeAware = !!tsconfigPath;
|
|
1014
|
-
const typeAwareRules = {
|
|
997
|
+
const typeAwareRules = {
|
|
998
|
+
"react/no-leaked-conditional-rendering": "warn",
|
|
999
|
+
"react/no-implicit-key": "error"
|
|
1000
|
+
};
|
|
1015
1001
|
const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all([
|
|
1016
1002
|
interopDefault(import("@eslint-react/eslint-plugin")),
|
|
1017
1003
|
interopDefault(import("eslint-plugin-react-hooks")),
|
|
@@ -1063,7 +1049,6 @@ async function react(options = {}) {
|
|
|
1063
1049
|
"react/no-direct-mutation-state": "error",
|
|
1064
1050
|
"react/no-duplicate-key": "warn",
|
|
1065
1051
|
"react/no-forward-ref": "warn",
|
|
1066
|
-
"react/no-implicit-key": "warn",
|
|
1067
1052
|
"react/no-missing-key": "error",
|
|
1068
1053
|
"react/no-nested-component-definitions": "error",
|
|
1069
1054
|
"react/no-prop-types": "error",
|
|
@@ -1143,7 +1128,6 @@ async function react(options = {}) {
|
|
|
1143
1128
|
}] : []
|
|
1144
1129
|
];
|
|
1145
1130
|
}
|
|
1146
|
-
|
|
1147
1131
|
//#endregion
|
|
1148
1132
|
//#region src/configs/regexp.ts
|
|
1149
1133
|
async function regexp(options = {}) {
|
|
@@ -1161,7 +1145,6 @@ async function regexp(options = {}) {
|
|
|
1161
1145
|
}
|
|
1162
1146
|
}];
|
|
1163
1147
|
}
|
|
1164
|
-
|
|
1165
1148
|
//#endregion
|
|
1166
1149
|
//#region src/configs/sort.ts
|
|
1167
1150
|
/**
|
|
@@ -1387,7 +1370,6 @@ function sortTsconfig() {
|
|
|
1387
1370
|
] }
|
|
1388
1371
|
}];
|
|
1389
1372
|
}
|
|
1390
|
-
|
|
1391
1373
|
//#endregion
|
|
1392
1374
|
//#region src/configs/test.ts
|
|
1393
1375
|
let _pluginTest;
|
|
@@ -1425,12 +1407,11 @@ async function test(options = {}) {
|
|
|
1425
1407
|
}
|
|
1426
1408
|
}];
|
|
1427
1409
|
}
|
|
1428
|
-
|
|
1429
1410
|
//#endregion
|
|
1430
1411
|
//#region src/configs/toml.ts
|
|
1431
1412
|
async function toml(options = {}) {
|
|
1432
|
-
const { files = [GLOB_TOML], overrides = {}, stylistic
|
|
1433
|
-
const { indent = 2 } = typeof stylistic
|
|
1413
|
+
const { files = [GLOB_TOML], overrides = {}, stylistic = true } = options;
|
|
1414
|
+
const { indent = 2 } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
1434
1415
|
const [pluginToml, parserToml] = await Promise.all([interopDefault(import("eslint-plugin-toml")), interopDefault(import("toml-eslint-parser"))]);
|
|
1435
1416
|
return [{
|
|
1436
1417
|
name: "liwo/toml/setup",
|
|
@@ -1449,7 +1430,7 @@ async function toml(options = {}) {
|
|
|
1449
1430
|
"toml/precision-of-integer": "error",
|
|
1450
1431
|
"toml/tables-order": "error",
|
|
1451
1432
|
"toml/vue-custom-block/no-parsing-error": "error",
|
|
1452
|
-
...stylistic
|
|
1433
|
+
...stylistic ? {
|
|
1453
1434
|
"toml/array-bracket-newline": "error",
|
|
1454
1435
|
"toml/array-bracket-spacing": "error",
|
|
1455
1436
|
"toml/array-element-newline": "error",
|
|
@@ -1466,18 +1447,17 @@ async function toml(options = {}) {
|
|
|
1466
1447
|
}
|
|
1467
1448
|
}];
|
|
1468
1449
|
}
|
|
1469
|
-
|
|
1470
1450
|
//#endregion
|
|
1471
1451
|
//#region src/configs/typescript.ts
|
|
1472
1452
|
async function typescript(options = {}) {
|
|
1473
1453
|
const { componentExts = [], overrides = {}, overridesTypeAware = {}, parserOptions = {}, type = "app" } = options;
|
|
1474
1454
|
const files = options.files ?? [
|
|
1475
|
-
|
|
1476
|
-
|
|
1455
|
+
"**/*.?([cm])ts",
|
|
1456
|
+
"**/*.?([cm])tsx",
|
|
1477
1457
|
...componentExts.map((ext) => `**/*.${ext}`)
|
|
1478
1458
|
];
|
|
1479
|
-
const filesTypeAware = options.filesTypeAware ?? [
|
|
1480
|
-
const ignoresTypeAware = options.ignoresTypeAware ?? [
|
|
1459
|
+
const filesTypeAware = options.filesTypeAware ?? ["**/*.?([cm])ts", "**/*.?([cm])tsx"];
|
|
1460
|
+
const ignoresTypeAware = options.ignoresTypeAware ?? [`**/*.md/**`];
|
|
1481
1461
|
const tsconfigPath = options?.tsconfigPath ? options.tsconfigPath : void 0;
|
|
1482
1462
|
const isTypeAware = !!tsconfigPath;
|
|
1483
1463
|
const typeAwareRules = {
|
|
@@ -1507,10 +1487,10 @@ async function typescript(options = {}) {
|
|
|
1507
1487
|
"ts/unbound-method": "error"
|
|
1508
1488
|
};
|
|
1509
1489
|
const [pluginTs, parserTs] = await Promise.all([interopDefault(import("@typescript-eslint/eslint-plugin")), interopDefault(import("@typescript-eslint/parser"))]);
|
|
1510
|
-
function makeParser(typeAware, files
|
|
1490
|
+
function makeParser(typeAware, files, ignores) {
|
|
1511
1491
|
return {
|
|
1512
|
-
files
|
|
1513
|
-
...ignores
|
|
1492
|
+
files,
|
|
1493
|
+
...ignores ? { ignores } : {},
|
|
1514
1494
|
languageOptions: {
|
|
1515
1495
|
parser: parserTs,
|
|
1516
1496
|
parserOptions: {
|
|
@@ -1600,7 +1580,6 @@ async function typescript(options = {}) {
|
|
|
1600
1580
|
}] : []
|
|
1601
1581
|
];
|
|
1602
1582
|
}
|
|
1603
|
-
|
|
1604
1583
|
//#endregion
|
|
1605
1584
|
//#region src/configs/unicorn.ts
|
|
1606
1585
|
async function unicorn(options = {}) {
|
|
@@ -1630,7 +1609,6 @@ async function unicorn(options = {}) {
|
|
|
1630
1609
|
}
|
|
1631
1610
|
}];
|
|
1632
1611
|
}
|
|
1633
|
-
|
|
1634
1612
|
//#endregion
|
|
1635
1613
|
//#region src/configs/unocss.ts
|
|
1636
1614
|
async function unocss(options = {}) {
|
|
@@ -1647,13 +1625,12 @@ async function unocss(options = {}) {
|
|
|
1647
1625
|
}
|
|
1648
1626
|
}];
|
|
1649
1627
|
}
|
|
1650
|
-
|
|
1651
1628
|
//#endregion
|
|
1652
1629
|
//#region src/configs/vue.ts
|
|
1653
1630
|
async function vue(options = {}) {
|
|
1654
|
-
const { a11y = false, files = [GLOB_VUE], overrides = {}, stylistic
|
|
1631
|
+
const { a11y = false, files = [GLOB_VUE], overrides = {}, stylistic = true, vueVersion = 3 } = options;
|
|
1655
1632
|
const sfcBlocks = options.sfcBlocks === true ? {} : options.sfcBlocks ?? {};
|
|
1656
|
-
const { indent = 2 } = typeof stylistic
|
|
1633
|
+
const { indent = 2 } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
1657
1634
|
if (a11y) await ensurePackages(["eslint-plugin-vuejs-accessibility"]);
|
|
1658
1635
|
const [pluginVue, parserVue, processorVueBlocks, pluginVueA11y] = await Promise.all([
|
|
1659
1636
|
interopDefault(import("eslint-plugin-vue")),
|
|
@@ -1781,7 +1758,7 @@ async function vue(options = {}) {
|
|
|
1781
1758
|
nonwords: false,
|
|
1782
1759
|
words: true
|
|
1783
1760
|
}],
|
|
1784
|
-
...stylistic
|
|
1761
|
+
...stylistic ? {
|
|
1785
1762
|
"vue/array-bracket-spacing": ["error", "never"],
|
|
1786
1763
|
"vue/arrow-spacing": ["error", {
|
|
1787
1764
|
after: true,
|
|
@@ -1853,12 +1830,11 @@ async function vue(options = {}) {
|
|
|
1853
1830
|
}
|
|
1854
1831
|
}];
|
|
1855
1832
|
}
|
|
1856
|
-
|
|
1857
1833
|
//#endregion
|
|
1858
1834
|
//#region src/configs/yaml.ts
|
|
1859
1835
|
async function yaml(options = {}) {
|
|
1860
|
-
const { files = [GLOB_YAML], overrides = {}, stylistic
|
|
1861
|
-
const { indent = 2, quotes = "single" } = typeof stylistic
|
|
1836
|
+
const { files = [GLOB_YAML], overrides = {}, stylistic = true } = options;
|
|
1837
|
+
const { indent = 2, quotes = "single" } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
1862
1838
|
const [pluginYaml, parserYaml] = await Promise.all([interopDefault(import("eslint-plugin-yml")), interopDefault(import("yaml-eslint-parser"))]);
|
|
1863
1839
|
return [
|
|
1864
1840
|
{
|
|
@@ -1878,7 +1854,7 @@ async function yaml(options = {}) {
|
|
|
1878
1854
|
"yaml/no-irregular-whitespace": "error",
|
|
1879
1855
|
"yaml/plain-scalar": "error",
|
|
1880
1856
|
"yaml/vue-custom-block/no-parsing-error": "error",
|
|
1881
|
-
...stylistic
|
|
1857
|
+
...stylistic ? {
|
|
1882
1858
|
"yaml/block-mapping-question-indicator-newline": "error",
|
|
1883
1859
|
"yaml/block-sequence-hyphen-indicator-newline": "error",
|
|
1884
1860
|
"yaml/flow-mapping-curly-newline": "error",
|
|
@@ -1932,7 +1908,6 @@ async function yaml(options = {}) {
|
|
|
1932
1908
|
}
|
|
1933
1909
|
];
|
|
1934
1910
|
}
|
|
1935
|
-
|
|
1936
1911
|
//#endregion
|
|
1937
1912
|
//#region src/factory.ts
|
|
1938
1913
|
const flatConfigProps = [
|
|
@@ -1981,86 +1956,86 @@ function eslintConfig(options = {}, ...userConfigs) {
|
|
|
1981
1956
|
}
|
|
1982
1957
|
const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
|
|
1983
1958
|
if (stylisticOptions && !("jsx" in stylisticOptions)) stylisticOptions.jsx = enableJsx;
|
|
1984
|
-
const configs
|
|
1985
|
-
if (enableGitignore) if (typeof enableGitignore !== "boolean") configs
|
|
1959
|
+
const configs = [];
|
|
1960
|
+
if (enableGitignore) if (typeof enableGitignore !== "boolean") configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
|
|
1986
1961
|
name: "liwo/gitignore",
|
|
1987
1962
|
...enableGitignore
|
|
1988
1963
|
})]));
|
|
1989
|
-
else configs
|
|
1964
|
+
else configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
|
|
1990
1965
|
name: "liwo/gitignore",
|
|
1991
1966
|
strict: false
|
|
1992
1967
|
})]));
|
|
1993
1968
|
const typescriptOptions = resolveSubOptions(options, "typescript");
|
|
1994
1969
|
const tsconfigPath = "tsconfigPath" in typescriptOptions ? typescriptOptions.tsconfigPath : void 0;
|
|
1995
|
-
configs
|
|
1970
|
+
configs.push(ignores(options.ignores), javascript({
|
|
1996
1971
|
isInEditor,
|
|
1997
1972
|
overrides: getOverrides(options, "javascript")
|
|
1998
1973
|
}), comments(), node(), jsdoc({ stylistic: stylisticOptions }), imports({ stylistic: stylisticOptions }), command(), perfectionist());
|
|
1999
|
-
if (enableImports) configs
|
|
1974
|
+
if (enableImports) configs.push(imports(enableImports === true ? { stylistic: stylisticOptions } : {
|
|
2000
1975
|
stylistic: stylisticOptions,
|
|
2001
1976
|
...enableImports
|
|
2002
1977
|
}));
|
|
2003
|
-
if (enableUnicorn) configs
|
|
1978
|
+
if (enableUnicorn) configs.push(unicorn(enableUnicorn === true ? {} : enableUnicorn));
|
|
2004
1979
|
if (enableVue) componentExts.push("vue");
|
|
2005
|
-
if (enableJsx) configs
|
|
2006
|
-
if (enableTypeScript) configs
|
|
1980
|
+
if (enableJsx) configs.push(jsx());
|
|
1981
|
+
if (enableTypeScript) configs.push(typescript({
|
|
2007
1982
|
...typescriptOptions,
|
|
2008
1983
|
componentExts,
|
|
2009
1984
|
overrides: getOverrides(options, "typescript"),
|
|
2010
1985
|
type: options.type
|
|
2011
1986
|
}));
|
|
2012
|
-
if (stylisticOptions) configs
|
|
1987
|
+
if (stylisticOptions) configs.push(stylistic({
|
|
2013
1988
|
...stylisticOptions,
|
|
2014
1989
|
lessOpinionated: options.lessOpinionated,
|
|
2015
1990
|
overrides: getOverrides(options, "stylistic")
|
|
2016
1991
|
}));
|
|
2017
|
-
if (enableRegexp) configs
|
|
2018
|
-
if (options.test ?? true) configs
|
|
1992
|
+
if (enableRegexp) configs.push(regexp(typeof enableRegexp === "boolean" ? {} : enableRegexp));
|
|
1993
|
+
if (options.test ?? true) configs.push(test({
|
|
2019
1994
|
isInEditor,
|
|
2020
1995
|
overrides: getOverrides(options, "test")
|
|
2021
1996
|
}));
|
|
2022
|
-
if (enableVue) configs
|
|
1997
|
+
if (enableVue) configs.push(vue({
|
|
2023
1998
|
...resolveSubOptions(options, "vue"),
|
|
2024
1999
|
overrides: getOverrides(options, "vue"),
|
|
2025
2000
|
stylistic: stylisticOptions,
|
|
2026
2001
|
typescript: !!enableTypeScript
|
|
2027
2002
|
}));
|
|
2028
|
-
if (enableReact) configs
|
|
2003
|
+
if (enableReact) configs.push(react({
|
|
2029
2004
|
...typescriptOptions,
|
|
2030
2005
|
overrides: getOverrides(options, "react"),
|
|
2031
2006
|
tsconfigPath
|
|
2032
2007
|
}));
|
|
2033
|
-
if (enableUnoCSS) configs
|
|
2008
|
+
if (enableUnoCSS) configs.push(unocss({
|
|
2034
2009
|
...resolveSubOptions(options, "unocss"),
|
|
2035
2010
|
overrides: getOverrides(options, "unocss")
|
|
2036
2011
|
}));
|
|
2037
|
-
if (options.jsonc ?? true) configs
|
|
2012
|
+
if (options.jsonc ?? true) configs.push(jsonc({
|
|
2038
2013
|
overrides: getOverrides(options, "jsonc"),
|
|
2039
2014
|
stylistic: stylisticOptions
|
|
2040
2015
|
}), sortPackageJson(), sortTsconfig());
|
|
2041
|
-
if (enableCatalogs) configs
|
|
2042
|
-
if (options.yaml ?? true) configs
|
|
2016
|
+
if (enableCatalogs) configs.push(pnpm());
|
|
2017
|
+
if (options.yaml ?? true) configs.push(yaml({
|
|
2043
2018
|
overrides: getOverrides(options, "yaml"),
|
|
2044
2019
|
stylistic: stylisticOptions
|
|
2045
2020
|
}));
|
|
2046
|
-
if (options.toml ?? true) configs
|
|
2021
|
+
if (options.toml ?? true) configs.push(toml({
|
|
2047
2022
|
overrides: getOverrides(options, "toml"),
|
|
2048
2023
|
stylistic: stylisticOptions
|
|
2049
2024
|
}));
|
|
2050
|
-
if (options.markdown ?? true) configs
|
|
2025
|
+
if (options.markdown ?? true) configs.push(markdown({
|
|
2051
2026
|
componentExts,
|
|
2052
2027
|
overrides: getOverrides(options, "markdown")
|
|
2053
2028
|
}));
|
|
2054
|
-
if (options.formatters || options.formatters === void 0) configs
|
|
2055
|
-
configs
|
|
2029
|
+
if (options.formatters || options.formatters === void 0) configs.push(formatters(options.formatters, typeof stylisticOptions === "boolean" ? {} : stylisticOptions));
|
|
2030
|
+
configs.push(disables());
|
|
2056
2031
|
if ("files" in options) throw new Error("[@liwo/eslint-config] The first argument should not contain the \"files\" property as the options are supposed to be global. Place it in the second or later config instead.");
|
|
2057
2032
|
const fusedConfig = flatConfigProps.reduce((acc, key) => {
|
|
2058
2033
|
if (key in options) acc[key] = options[key];
|
|
2059
2034
|
return acc;
|
|
2060
2035
|
}, {});
|
|
2061
|
-
if (Object.keys(fusedConfig).length) configs
|
|
2036
|
+
if (Object.keys(fusedConfig).length) configs.push([fusedConfig]);
|
|
2062
2037
|
let composer = new FlatConfigComposer();
|
|
2063
|
-
composer = composer.append(...configs
|
|
2038
|
+
composer = composer.append(...configs, ...userConfigs);
|
|
2064
2039
|
if (autoRenamePlugins) composer = composer.renamePlugins(defaultPluginRenaming);
|
|
2065
2040
|
if (isInEditor) composer = composer.disableRulesFix([
|
|
2066
2041
|
"unused-imports/no-unused-imports",
|
|
@@ -2076,10 +2051,8 @@ function getOverrides(options, key) {
|
|
|
2076
2051
|
const sub = resolveSubOptions(options, key);
|
|
2077
2052
|
return { ..."overrides" in sub ? sub.overrides : {} };
|
|
2078
2053
|
}
|
|
2079
|
-
|
|
2080
2054
|
//#endregion
|
|
2081
2055
|
//#region src/index.ts
|
|
2082
2056
|
var src_default = eslintConfig;
|
|
2083
|
-
|
|
2084
2057
|
//#endregion
|
|
2085
|
-
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, command, comments, src_default as default, defaultPluginRenaming, disables, ensurePackages, eslintConfig, formatters, getOverrides, ignores, imports, interopDefault, isInEditorEnv, isInGitHooksOrLintStaged, isPackageInScope, javascript, jsdoc, jsonc, jsx, markdown, node, parserPlain, perfectionist, pnpm, react, regexp, renamePluginInConfigs, renameRules, resolveSubOptions, sortPackageJson, sortTsconfig, stylistic, test, toArray, toml, typescript, unicorn, unocss, vue, yaml };
|
|
2058
|
+
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, command, comments, src_default as default, defaultPluginRenaming, disables, ensurePackages, eslintConfig, formatters, getOverrides, ignores, imports, interopDefault, isInEditorEnv, isInGitHooksOrLintStaged, isPackageInScope, javascript, jsdoc, jsonc, jsx, markdown, node, parserPlain, perfectionist, pnpm, react, regexp, renamePluginInConfigs, renameRules, resolveSubOptions, sortPackageJson, sortTsconfig, stylistic, test, toArray, toml, typescript, unicorn, unocss, vue, yaml };
|