@dhzh/eslint-config 0.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/dist/index.js ADDED
@@ -0,0 +1,2233 @@
1
+ // src/factory.ts
2
+ import process3 from "process";
3
+ import fs from "fs";
4
+ import { isPackageExists as isPackageExists4 } from "local-pkg";
5
+
6
+ // src/plugins.ts
7
+ import { default as default2 } from "eslint-plugin-antfu";
8
+ import { default as default3 } from "eslint-plugin-eslint-comments";
9
+ import * as pluginImport from "eslint-plugin-import-x";
10
+ import { default as default4 } from "eslint-plugin-n";
11
+ import { default as default5 } from "eslint-plugin-unicorn";
12
+ import { default as default6 } from "eslint-plugin-unused-imports";
13
+ import { default as default7 } from "eslint-plugin-perfectionist";
14
+
15
+ // src/configs/comments.ts
16
+ async function comments() {
17
+ return [
18
+ {
19
+ name: "antfu:eslint-comments",
20
+ plugins: {
21
+ "eslint-comments": default3
22
+ },
23
+ rules: {
24
+ "eslint-comments/no-aggregating-enable": "error",
25
+ "eslint-comments/no-duplicate-disable": "error",
26
+ "eslint-comments/no-unlimited-disable": "error",
27
+ "eslint-comments/no-unused-enable": "error"
28
+ }
29
+ }
30
+ ];
31
+ }
32
+
33
+ // src/globs.ts
34
+ var GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
35
+ var GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
36
+ var GLOB_JS = "**/*.?([cm])js";
37
+ var GLOB_JSX = "**/*.?([cm])jsx";
38
+ var GLOB_TS = "**/*.?([cm])ts";
39
+ var GLOB_TSX = "**/*.?([cm])tsx";
40
+ var GLOB_STYLE = "**/*.{c,le,sc}ss";
41
+ var GLOB_CSS = "**/*.css";
42
+ var GLOB_POSTCSS = "**/*.{p,post}css";
43
+ var GLOB_LESS = "**/*.less";
44
+ var GLOB_SCSS = "**/*.scss";
45
+ var GLOB_JSON = "**/*.json";
46
+ var GLOB_JSON5 = "**/*.json5";
47
+ var GLOB_JSONC = "**/*.jsonc";
48
+ var GLOB_MARKDOWN = "**/*.md";
49
+ var GLOB_MARKDOWN_IN_MARKDOWN = "**/*.md/*.md";
50
+ var GLOB_SVELTE = "**/*.svelte";
51
+ var GLOB_VUE = "**/*.vue";
52
+ var GLOB_YAML = "**/*.y?(a)ml";
53
+ var GLOB_TOML = "**/*.toml";
54
+ var GLOB_HTML = "**/*.htm?(l)";
55
+ var GLOB_ASTRO = "**/*.astro";
56
+ var GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
57
+ var GLOB_TESTS = [
58
+ `**/__tests__/**/*.${GLOB_SRC_EXT}`,
59
+ `**/*.spec.${GLOB_SRC_EXT}`,
60
+ `**/*.test.${GLOB_SRC_EXT}`,
61
+ `**/*.bench.${GLOB_SRC_EXT}`,
62
+ `**/*.benchmark.${GLOB_SRC_EXT}`
63
+ ];
64
+ var GLOB_ALL_SRC = [
65
+ GLOB_SRC,
66
+ GLOB_STYLE,
67
+ GLOB_JSON,
68
+ GLOB_JSON5,
69
+ GLOB_MARKDOWN,
70
+ GLOB_SVELTE,
71
+ GLOB_VUE,
72
+ GLOB_YAML,
73
+ GLOB_HTML
74
+ ];
75
+ var GLOB_EXCLUDE = [
76
+ "**/node_modules",
77
+ "**/dist",
78
+ "**/package-lock.json",
79
+ "**/yarn.lock",
80
+ "**/pnpm-lock.yaml",
81
+ "**/bun.lockb",
82
+ "**/output",
83
+ "**/coverage",
84
+ "**/temp",
85
+ "**/.temp",
86
+ "**/tmp",
87
+ "**/.tmp",
88
+ "**/.history",
89
+ "**/.vitepress/cache",
90
+ "**/.nuxt",
91
+ "**/.next",
92
+ "**/.vercel",
93
+ "**/.changeset",
94
+ "**/.idea",
95
+ "**/.cache",
96
+ "**/.output",
97
+ "**/.vite-inspect",
98
+ "**/.yarn",
99
+ "**/CHANGELOG*.md",
100
+ "**/*.min.*",
101
+ "**/LICENSE*",
102
+ "**/__snapshots__",
103
+ "**/auto-import?(s).d.ts",
104
+ "**/components.d.ts"
105
+ ];
106
+
107
+ // src/configs/ignores.ts
108
+ async function ignores() {
109
+ return [
110
+ {
111
+ ignores: GLOB_EXCLUDE
112
+ }
113
+ ];
114
+ }
115
+
116
+ // src/configs/imports.ts
117
+ async function imports(options = {}) {
118
+ const {
119
+ stylistic: stylistic2 = true
120
+ } = options;
121
+ return [
122
+ {
123
+ name: "antfu:imports",
124
+ plugins: {
125
+ antfu: default2,
126
+ import: pluginImport
127
+ },
128
+ rules: {
129
+ "antfu/import-dedupe": "error",
130
+ "antfu/no-import-dist": "error",
131
+ "antfu/no-import-node-modules-by-path": "error",
132
+ "import/first": "error",
133
+ "import/no-duplicates": "error",
134
+ "import/no-mutable-exports": "error",
135
+ "import/no-named-default": "error",
136
+ "import/no-self-import": "error",
137
+ "import/no-webpack-loader-syntax": "error",
138
+ "import/order": "error",
139
+ ...stylistic2 ? {
140
+ "import/newline-after-import": ["error", { count: 1 }]
141
+ } : {}
142
+ }
143
+ },
144
+ {
145
+ files: ["**/bin/**/*", `**/bin.${GLOB_SRC_EXT}`],
146
+ name: "antfu:imports:bin",
147
+ rules: {
148
+ "antfu/no-import-dist": "off",
149
+ "antfu/no-import-node-modules-by-path": "off"
150
+ }
151
+ }
152
+ ];
153
+ }
154
+
155
+ // src/configs/javascript.ts
156
+ import globals from "globals";
157
+ async function javascript(options = {}) {
158
+ const {
159
+ isInEditor = false,
160
+ overrides = {}
161
+ } = options;
162
+ return [
163
+ {
164
+ languageOptions: {
165
+ ecmaVersion: 2022,
166
+ globals: {
167
+ ...globals.browser,
168
+ ...globals.es2021,
169
+ ...globals.node,
170
+ document: "readonly",
171
+ navigator: "readonly",
172
+ window: "readonly"
173
+ },
174
+ parserOptions: {
175
+ ecmaFeatures: {
176
+ jsx: true
177
+ },
178
+ ecmaVersion: 2022,
179
+ sourceType: "module"
180
+ },
181
+ sourceType: "module"
182
+ },
183
+ linterOptions: {
184
+ reportUnusedDisableDirectives: true
185
+ },
186
+ name: "antfu:javascript",
187
+ plugins: {
188
+ "antfu": default2,
189
+ "unused-imports": default6
190
+ },
191
+ rules: {
192
+ "accessor-pairs": ["error", { enforceForClassMembers: true, setWithoutGet: true }],
193
+ "array-callback-return": "error",
194
+ "block-scoped-var": "error",
195
+ "constructor-super": "error",
196
+ "default-case-last": "error",
197
+ "dot-notation": ["error", { allowKeywords: true }],
198
+ "eqeqeq": ["error", "smart"],
199
+ "new-cap": ["error", { capIsNew: false, newIsCap: true, properties: true }],
200
+ "no-alert": "error",
201
+ "no-array-constructor": "error",
202
+ "no-async-promise-executor": "error",
203
+ "no-caller": "error",
204
+ "no-case-declarations": "error",
205
+ "no-class-assign": "error",
206
+ "no-compare-neg-zero": "error",
207
+ "no-cond-assign": ["error", "always"],
208
+ "no-console": ["error", { allow: ["warn", "error"] }],
209
+ "no-const-assign": "error",
210
+ "no-control-regex": "error",
211
+ "no-debugger": "error",
212
+ "no-delete-var": "error",
213
+ "no-dupe-args": "error",
214
+ "no-dupe-class-members": "error",
215
+ "no-dupe-keys": "error",
216
+ "no-duplicate-case": "error",
217
+ "no-empty": ["error", { allowEmptyCatch: true }],
218
+ "no-empty-character-class": "error",
219
+ "no-empty-pattern": "error",
220
+ "no-eval": "error",
221
+ "no-ex-assign": "error",
222
+ "no-extend-native": "error",
223
+ "no-extra-bind": "error",
224
+ "no-extra-boolean-cast": "error",
225
+ "no-fallthrough": "error",
226
+ "no-func-assign": "error",
227
+ "no-global-assign": "error",
228
+ "no-implied-eval": "error",
229
+ "no-import-assign": "error",
230
+ "no-invalid-regexp": "error",
231
+ "no-irregular-whitespace": "error",
232
+ "no-iterator": "error",
233
+ "no-labels": ["error", { allowLoop: false, allowSwitch: false }],
234
+ "no-lone-blocks": "error",
235
+ "no-loss-of-precision": "error",
236
+ "no-misleading-character-class": "error",
237
+ "no-multi-str": "error",
238
+ "no-new": "error",
239
+ "no-new-func": "error",
240
+ "no-new-symbol": "error",
241
+ "no-new-wrappers": "error",
242
+ "no-obj-calls": "error",
243
+ "no-octal": "error",
244
+ "no-octal-escape": "error",
245
+ "no-proto": "error",
246
+ "no-prototype-builtins": "error",
247
+ "no-redeclare": ["error", { builtinGlobals: false }],
248
+ "no-regex-spaces": "error",
249
+ "no-restricted-globals": [
250
+ "error",
251
+ { message: "Use `globalThis` instead.", name: "global" },
252
+ { message: "Use `globalThis` instead.", name: "self" }
253
+ ],
254
+ "no-restricted-properties": [
255
+ "error",
256
+ { message: "Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.", property: "__proto__" },
257
+ { message: "Use `Object.defineProperty` instead.", property: "__defineGetter__" },
258
+ { message: "Use `Object.defineProperty` instead.", property: "__defineSetter__" },
259
+ { message: "Use `Object.getOwnPropertyDescriptor` instead.", property: "__lookupGetter__" },
260
+ { message: "Use `Object.getOwnPropertyDescriptor` instead.", property: "__lookupSetter__" }
261
+ ],
262
+ "no-restricted-syntax": [
263
+ "error",
264
+ "DebuggerStatement",
265
+ "LabeledStatement",
266
+ "WithStatement",
267
+ "TSEnumDeclaration[const=true]",
268
+ "TSExportAssignment"
269
+ ],
270
+ "no-self-assign": ["error", { props: true }],
271
+ "no-self-compare": "error",
272
+ "no-sequences": "error",
273
+ "no-shadow-restricted-names": "error",
274
+ "no-sparse-arrays": "error",
275
+ "no-template-curly-in-string": "error",
276
+ "no-this-before-super": "error",
277
+ "no-throw-literal": "error",
278
+ "no-undef": "error",
279
+ "no-undef-init": "error",
280
+ "no-unexpected-multiline": "error",
281
+ "no-unmodified-loop-condition": "error",
282
+ "no-unneeded-ternary": ["error", { defaultAssignment: false }],
283
+ "no-unreachable": "error",
284
+ "no-unreachable-loop": "error",
285
+ "no-unsafe-finally": "error",
286
+ "no-unsafe-negation": "error",
287
+ "no-unused-expressions": ["error", {
288
+ allowShortCircuit: true,
289
+ allowTaggedTemplates: true,
290
+ allowTernary: true
291
+ }],
292
+ "no-unused-vars": ["error", {
293
+ args: "none",
294
+ caughtErrors: "none",
295
+ ignoreRestSiblings: true,
296
+ vars: "all"
297
+ }],
298
+ "no-use-before-define": ["error", { classes: false, functions: false, variables: true }],
299
+ "no-useless-backreference": "error",
300
+ "no-useless-call": "error",
301
+ "no-useless-catch": "error",
302
+ "no-useless-computed-key": "error",
303
+ "no-useless-constructor": "error",
304
+ "no-useless-rename": "error",
305
+ "no-useless-return": "error",
306
+ "no-var": "error",
307
+ "no-with": "error",
308
+ "object-shorthand": [
309
+ "error",
310
+ "always",
311
+ {
312
+ avoidQuotes: true,
313
+ ignoreConstructors: false
314
+ }
315
+ ],
316
+ "one-var": ["error", { initialized: "never" }],
317
+ "prefer-arrow-callback": [
318
+ "error",
319
+ {
320
+ allowNamedFunctions: false,
321
+ allowUnboundThis: true
322
+ }
323
+ ],
324
+ "prefer-const": [
325
+ "error",
326
+ {
327
+ destructuring: "all",
328
+ ignoreReadBeforeAssign: true
329
+ }
330
+ ],
331
+ "prefer-exponentiation-operator": "error",
332
+ "prefer-promise-reject-errors": "error",
333
+ "prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
334
+ "prefer-rest-params": "error",
335
+ "prefer-spread": "error",
336
+ "prefer-template": "error",
337
+ "sort-imports": [
338
+ "error",
339
+ {
340
+ allowSeparatedGroups: false,
341
+ ignoreCase: false,
342
+ ignoreDeclarationSort: true,
343
+ ignoreMemberSort: false,
344
+ memberSyntaxSortOrder: ["none", "all", "multiple", "single"]
345
+ }
346
+ ],
347
+ "symbol-description": "error",
348
+ "unicode-bom": ["error", "never"],
349
+ "unused-imports/no-unused-imports": isInEditor ? "off" : "error",
350
+ "unused-imports/no-unused-vars": [
351
+ "error",
352
+ { args: "after-used", argsIgnorePattern: "^_", vars: "all", varsIgnorePattern: "^_" }
353
+ ],
354
+ "use-isnan": ["error", { enforceForIndexOf: true, enforceForSwitchCase: true }],
355
+ "valid-typeof": ["error", { requireStringLiterals: true }],
356
+ "vars-on-top": "error",
357
+ "yoda": ["error", "never"],
358
+ ...overrides
359
+ }
360
+ },
361
+ {
362
+ files: [`scripts/${GLOB_SRC}`, `cli.${GLOB_SRC_EXT}`],
363
+ name: "antfu:scripts-overrides",
364
+ rules: {
365
+ "no-console": "off"
366
+ }
367
+ }
368
+ ];
369
+ }
370
+
371
+ // src/utils.ts
372
+ import process from "process";
373
+ import { isPackageExists } from "local-pkg";
374
+ var parserPlain = {
375
+ meta: {
376
+ name: "parser-plain"
377
+ },
378
+ parseForESLint: (code) => ({
379
+ ast: {
380
+ body: [],
381
+ comments: [],
382
+ loc: { end: code.length, start: 0 },
383
+ range: [0, code.length],
384
+ tokens: [],
385
+ type: "Program"
386
+ },
387
+ scopeManager: null,
388
+ services: { isPlain: true },
389
+ visitorKeys: {
390
+ Program: []
391
+ }
392
+ })
393
+ };
394
+ async function combine(...configs) {
395
+ const resolved = await Promise.all(configs);
396
+ return resolved.flat();
397
+ }
398
+ function renameRules(rules, map) {
399
+ return Object.fromEntries(
400
+ Object.entries(rules).map(([key, value]) => {
401
+ for (const [from, to] of Object.entries(map)) {
402
+ if (key.startsWith(`${from}/`))
403
+ return [to + key.slice(from.length), value];
404
+ }
405
+ return [key, value];
406
+ })
407
+ );
408
+ }
409
+ function renamePluginInConfigs(configs, map) {
410
+ return configs.map((i) => {
411
+ const clone = { ...i };
412
+ if (clone.rules)
413
+ clone.rules = renameRules(clone.rules, map);
414
+ if (clone.plugins) {
415
+ clone.plugins = Object.fromEntries(
416
+ Object.entries(clone.plugins).map(([key, value]) => {
417
+ if (key in map)
418
+ return [map[key], value];
419
+ return [key, value];
420
+ })
421
+ );
422
+ }
423
+ return clone;
424
+ });
425
+ }
426
+ function toArray(value) {
427
+ return Array.isArray(value) ? value : [value];
428
+ }
429
+ async function interopDefault(m) {
430
+ const resolved = await m;
431
+ return resolved.default || resolved;
432
+ }
433
+ async function ensurePackages(packages) {
434
+ if (process.env.CI || process.stdout.isTTY === false)
435
+ return;
436
+ const nonExistingPackages = packages.filter((i) => i && !isPackageExists(i));
437
+ if (nonExistingPackages.length === 0)
438
+ return;
439
+ const p = await import("@clack/prompts");
440
+ const result = await p.confirm({
441
+ message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(", ")}. Do you want to install them?`
442
+ });
443
+ if (result)
444
+ await import("@antfu/install-pkg").then((i) => i.installPackage(nonExistingPackages, { dev: true }));
445
+ }
446
+
447
+ // src/configs/jsdoc.ts
448
+ async function jsdoc(options = {}) {
449
+ const {
450
+ stylistic: stylistic2 = true
451
+ } = options;
452
+ return [
453
+ {
454
+ name: "antfu:jsdoc",
455
+ plugins: {
456
+ jsdoc: await interopDefault(import("eslint-plugin-jsdoc"))
457
+ },
458
+ rules: {
459
+ "jsdoc/check-access": "warn",
460
+ "jsdoc/check-param-names": "warn",
461
+ "jsdoc/check-property-names": "warn",
462
+ "jsdoc/check-types": "warn",
463
+ "jsdoc/empty-tags": "warn",
464
+ "jsdoc/implements-on-classes": "warn",
465
+ "jsdoc/no-defaults": "warn",
466
+ "jsdoc/no-multi-asterisks": "warn",
467
+ "jsdoc/require-param-name": "warn",
468
+ "jsdoc/require-property": "warn",
469
+ "jsdoc/require-property-description": "warn",
470
+ "jsdoc/require-property-name": "warn",
471
+ "jsdoc/require-returns-check": "warn",
472
+ "jsdoc/require-returns-description": "warn",
473
+ "jsdoc/require-yields-check": "warn",
474
+ ...stylistic2 ? {
475
+ "jsdoc/check-alignment": "warn",
476
+ "jsdoc/multiline-blocks": "warn"
477
+ } : {}
478
+ }
479
+ }
480
+ ];
481
+ }
482
+
483
+ // src/configs/jsonc.ts
484
+ async function jsonc(options = {}) {
485
+ const {
486
+ files = [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
487
+ overrides = {},
488
+ stylistic: stylistic2 = true
489
+ } = options;
490
+ const {
491
+ indent = 2
492
+ } = typeof stylistic2 === "boolean" ? {} : stylistic2;
493
+ const [
494
+ pluginJsonc,
495
+ parserJsonc
496
+ ] = await Promise.all([
497
+ interopDefault(import("eslint-plugin-jsonc")),
498
+ interopDefault(import("jsonc-eslint-parser"))
499
+ ]);
500
+ return [
501
+ {
502
+ name: "antfu:jsonc:setup",
503
+ plugins: {
504
+ jsonc: pluginJsonc
505
+ }
506
+ },
507
+ {
508
+ files,
509
+ languageOptions: {
510
+ parser: parserJsonc
511
+ },
512
+ name: "antfu:jsonc:rules",
513
+ rules: {
514
+ "jsonc/no-bigint-literals": "error",
515
+ "jsonc/no-binary-expression": "error",
516
+ "jsonc/no-binary-numeric-literals": "error",
517
+ "jsonc/no-dupe-keys": "error",
518
+ "jsonc/no-escape-sequence-in-identifier": "error",
519
+ "jsonc/no-floating-decimal": "error",
520
+ "jsonc/no-hexadecimal-numeric-literals": "error",
521
+ "jsonc/no-infinity": "error",
522
+ "jsonc/no-multi-str": "error",
523
+ "jsonc/no-nan": "error",
524
+ "jsonc/no-number-props": "error",
525
+ "jsonc/no-numeric-separators": "error",
526
+ "jsonc/no-octal": "error",
527
+ "jsonc/no-octal-escape": "error",
528
+ "jsonc/no-octal-numeric-literals": "error",
529
+ "jsonc/no-parenthesized": "error",
530
+ "jsonc/no-plus-sign": "error",
531
+ "jsonc/no-regexp-literals": "error",
532
+ "jsonc/no-sparse-arrays": "error",
533
+ "jsonc/no-template-literals": "error",
534
+ "jsonc/no-undefined-value": "error",
535
+ "jsonc/no-unicode-codepoint-escapes": "error",
536
+ "jsonc/no-useless-escape": "error",
537
+ "jsonc/space-unary-ops": "error",
538
+ "jsonc/valid-json-number": "error",
539
+ "jsonc/vue-custom-block/no-parsing-error": "error",
540
+ ...stylistic2 ? {
541
+ "jsonc/array-bracket-spacing": ["error", "never"],
542
+ "jsonc/comma-dangle": ["error", "never"],
543
+ "jsonc/comma-style": ["error", "last"],
544
+ "jsonc/indent": ["error", indent],
545
+ "jsonc/key-spacing": ["error", { afterColon: true, beforeColon: false }],
546
+ "jsonc/object-curly-newline": ["error", { consistent: true, multiline: true }],
547
+ "jsonc/object-curly-spacing": ["error", "always"],
548
+ "jsonc/object-property-newline": ["error", { allowMultiplePropertiesPerLine: true }],
549
+ "jsonc/quote-props": "error",
550
+ "jsonc/quotes": "error"
551
+ } : {},
552
+ ...overrides
553
+ }
554
+ }
555
+ ];
556
+ }
557
+
558
+ // src/configs/markdown.ts
559
+ import { mergeProcessors, processorPassThrough } from "eslint-merge-processors";
560
+ async function markdown(options = {}) {
561
+ const {
562
+ componentExts = [],
563
+ files = [GLOB_MARKDOWN],
564
+ overrides = {}
565
+ } = options;
566
+ const markdown2 = await interopDefault(import("eslint-plugin-markdown"));
567
+ return [
568
+ {
569
+ name: "antfu:markdown:setup",
570
+ plugins: {
571
+ markdown: markdown2
572
+ }
573
+ },
574
+ {
575
+ files,
576
+ ignores: [GLOB_MARKDOWN_IN_MARKDOWN],
577
+ name: "antfu:markdown:processor",
578
+ // `eslint-plugin-markdown` only creates virtual files for code blocks,
579
+ // but not the markdown file itself. We use `eslint-merge-processors` to
580
+ // add a pass-through processor for the markdown file itself.
581
+ processor: mergeProcessors([
582
+ markdown2.processors.markdown,
583
+ processorPassThrough
584
+ ])
585
+ },
586
+ {
587
+ files,
588
+ languageOptions: {
589
+ parser: parserPlain
590
+ },
591
+ name: "antfu:markdown:parser"
592
+ },
593
+ {
594
+ files: [
595
+ GLOB_MARKDOWN_CODE,
596
+ ...componentExts.map((ext) => `${GLOB_MARKDOWN}/**/*.${ext}`)
597
+ ],
598
+ languageOptions: {
599
+ parserOptions: {
600
+ ecmaFeatures: {
601
+ impliedStrict: true
602
+ }
603
+ }
604
+ },
605
+ name: "antfu:markdown:disables",
606
+ rules: {
607
+ "import/newline-after-import": "off",
608
+ "no-alert": "off",
609
+ "no-console": "off",
610
+ "no-labels": "off",
611
+ "no-lone-blocks": "off",
612
+ "no-restricted-syntax": "off",
613
+ "no-undef": "off",
614
+ "no-unused-expressions": "off",
615
+ "no-unused-labels": "off",
616
+ "no-unused-vars": "off",
617
+ "node/prefer-global/process": "off",
618
+ "style/comma-dangle": "off",
619
+ "style/eol-last": "off",
620
+ "ts/consistent-type-imports": "off",
621
+ "ts/no-namespace": "off",
622
+ "ts/no-redeclare": "off",
623
+ "ts/no-require-imports": "off",
624
+ "ts/no-unused-vars": "off",
625
+ "ts/no-use-before-define": "off",
626
+ "ts/no-var-requires": "off",
627
+ "unicode-bom": "off",
628
+ "unused-imports/no-unused-imports": "off",
629
+ "unused-imports/no-unused-vars": "off",
630
+ // Type aware rules
631
+ ...{
632
+ "ts/await-thenable": "off",
633
+ "ts/dot-notation": "off",
634
+ "ts/no-floating-promises": "off",
635
+ "ts/no-for-in-array": "off",
636
+ "ts/no-implied-eval": "off",
637
+ "ts/no-misused-promises": "off",
638
+ "ts/no-throw-literal": "off",
639
+ "ts/no-unnecessary-type-assertion": "off",
640
+ "ts/no-unsafe-argument": "off",
641
+ "ts/no-unsafe-assignment": "off",
642
+ "ts/no-unsafe-call": "off",
643
+ "ts/no-unsafe-member-access": "off",
644
+ "ts/no-unsafe-return": "off",
645
+ "ts/restrict-plus-operands": "off",
646
+ "ts/restrict-template-expressions": "off",
647
+ "ts/unbound-method": "off"
648
+ },
649
+ ...overrides
650
+ }
651
+ }
652
+ ];
653
+ }
654
+
655
+ // src/configs/node.ts
656
+ async function node() {
657
+ return [
658
+ {
659
+ name: "antfu:node",
660
+ plugins: {
661
+ node: default4
662
+ },
663
+ rules: {
664
+ "node/handle-callback-err": ["error", "^(err|error)$"],
665
+ "node/no-deprecated-api": "error",
666
+ "node/no-exports-assign": "error",
667
+ "node/no-new-require": "error",
668
+ "node/no-path-concat": "error",
669
+ "node/prefer-global/buffer": ["error", "never"],
670
+ "node/prefer-global/process": ["error", "never"],
671
+ "node/process-exit-as-throw": "error"
672
+ }
673
+ }
674
+ ];
675
+ }
676
+
677
+ // src/configs/perfectionist.ts
678
+ async function perfectionist() {
679
+ return [
680
+ {
681
+ name: "antfu:perfectionist",
682
+ plugins: {
683
+ perfectionist: default7
684
+ }
685
+ }
686
+ ];
687
+ }
688
+
689
+ // src/configs/formatters.ts
690
+ import { isPackageExists as isPackageExists2 } from "local-pkg";
691
+
692
+ // src/configs/stylistic.ts
693
+ var StylisticConfigDefaults = {
694
+ indent: 2,
695
+ jsx: true,
696
+ quotes: "single",
697
+ semi: true
698
+ };
699
+ async function stylistic(options = {}) {
700
+ const {
701
+ indent,
702
+ jsx,
703
+ overrides = {},
704
+ quotes,
705
+ semi
706
+ } = {
707
+ ...StylisticConfigDefaults,
708
+ ...options
709
+ };
710
+ const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
711
+ const config = pluginStylistic.configs.customize({
712
+ arrowParens: true,
713
+ braceStyle: "1tbs",
714
+ flat: true,
715
+ indent,
716
+ jsx,
717
+ pluginName: "style",
718
+ quotes,
719
+ semi
720
+ });
721
+ return [
722
+ {
723
+ name: "antfu:stylistic",
724
+ plugins: {
725
+ antfu: default2,
726
+ style: pluginStylistic
727
+ },
728
+ rules: {
729
+ ...config.rules,
730
+ "antfu/consistent-list-newline": "error",
731
+ "antfu/if-newline": "error",
732
+ "antfu/top-level-function": "error",
733
+ "curly": ["error", "all"],
734
+ ...overrides
735
+ }
736
+ }
737
+ ];
738
+ }
739
+
740
+ // src/configs/formatters.ts
741
+ async function formatters(options = {}, stylistic2 = {}) {
742
+ if (options === true) {
743
+ options = {
744
+ astro: isPackageExists2("astro"),
745
+ css: true,
746
+ graphql: true,
747
+ html: true,
748
+ markdown: true,
749
+ slidev: isPackageExists2("@slidev/cli")
750
+ };
751
+ }
752
+ await ensurePackages([
753
+ "eslint-plugin-format",
754
+ options.markdown && options.slidev ? "prettier-plugin-slidev" : void 0,
755
+ options.astro ? "prettier-plugin-astro" : void 0
756
+ ]);
757
+ if (options.slidev && options.markdown !== true && options.markdown !== "prettier")
758
+ throw new Error("`slidev` option only works when `markdown` is enabled with `prettier`");
759
+ const {
760
+ indent,
761
+ quotes,
762
+ semi
763
+ } = {
764
+ ...StylisticConfigDefaults,
765
+ ...stylistic2
766
+ };
767
+ const prettierOptions = Object.assign(
768
+ {
769
+ endOfLine: "auto",
770
+ semi,
771
+ singleQuote: quotes === "single",
772
+ tabWidth: typeof indent === "number" ? indent : 2,
773
+ trailingComma: "all",
774
+ useTabs: indent === "tab"
775
+ },
776
+ options.prettierOptions || {}
777
+ );
778
+ const dprintOptions = Object.assign(
779
+ {
780
+ indentWidth: typeof indent === "number" ? indent : 2,
781
+ quoteStyle: quotes === "single" ? "preferSingle" : "preferDouble",
782
+ useTabs: indent === "tab"
783
+ },
784
+ options.dprintOptions || {}
785
+ );
786
+ const pluginFormat = await interopDefault(import("eslint-plugin-format"));
787
+ const configs = [
788
+ {
789
+ name: "antfu:formatters:setup",
790
+ plugins: {
791
+ format: pluginFormat
792
+ }
793
+ }
794
+ ];
795
+ if (options.css) {
796
+ configs.push(
797
+ {
798
+ files: [GLOB_CSS, GLOB_POSTCSS],
799
+ languageOptions: {
800
+ parser: parserPlain
801
+ },
802
+ name: "antfu:formatter:css",
803
+ rules: {
804
+ "format/prettier": [
805
+ "error",
806
+ {
807
+ ...prettierOptions,
808
+ parser: "css"
809
+ }
810
+ ]
811
+ }
812
+ },
813
+ {
814
+ files: [GLOB_SCSS],
815
+ languageOptions: {
816
+ parser: parserPlain
817
+ },
818
+ name: "antfu:formatter:scss",
819
+ rules: {
820
+ "format/prettier": [
821
+ "error",
822
+ {
823
+ ...prettierOptions,
824
+ parser: "scss"
825
+ }
826
+ ]
827
+ }
828
+ },
829
+ {
830
+ files: [GLOB_LESS],
831
+ languageOptions: {
832
+ parser: parserPlain
833
+ },
834
+ name: "antfu:formatter:less",
835
+ rules: {
836
+ "format/prettier": [
837
+ "error",
838
+ {
839
+ ...prettierOptions,
840
+ parser: "less"
841
+ }
842
+ ]
843
+ }
844
+ }
845
+ );
846
+ }
847
+ if (options.html) {
848
+ configs.push({
849
+ files: ["**/*.html"],
850
+ languageOptions: {
851
+ parser: parserPlain
852
+ },
853
+ name: "antfu:formatter:html",
854
+ rules: {
855
+ "format/prettier": [
856
+ "error",
857
+ {
858
+ ...prettierOptions,
859
+ parser: "html"
860
+ }
861
+ ]
862
+ }
863
+ });
864
+ }
865
+ if (options.markdown) {
866
+ const formater = options.markdown === true ? "prettier" : options.markdown;
867
+ const GLOB_SLIDEV = !options.slidev ? [] : options.slidev === true ? ["**/slides.md"] : options.slidev.files;
868
+ configs.push({
869
+ files: [GLOB_MARKDOWN],
870
+ ignores: GLOB_SLIDEV,
871
+ languageOptions: {
872
+ parser: parserPlain
873
+ },
874
+ name: "antfu:formatter:markdown",
875
+ rules: {
876
+ [`format/${formater}`]: [
877
+ "error",
878
+ formater === "prettier" ? {
879
+ printWidth: 120,
880
+ ...prettierOptions,
881
+ embeddedLanguageFormatting: "off",
882
+ parser: "markdown"
883
+ } : {
884
+ ...dprintOptions,
885
+ language: "markdown"
886
+ }
887
+ ]
888
+ }
889
+ });
890
+ if (options.slidev) {
891
+ configs.push({
892
+ files: GLOB_SLIDEV,
893
+ languageOptions: {
894
+ parser: parserPlain
895
+ },
896
+ name: "antfu:formatter:slidev",
897
+ rules: {
898
+ "format/prettier": [
899
+ "error",
900
+ {
901
+ printWidth: 120,
902
+ ...prettierOptions,
903
+ embeddedLanguageFormatting: "off",
904
+ parser: "slidev",
905
+ plugins: [
906
+ "prettier-plugin-slidev"
907
+ ]
908
+ }
909
+ ]
910
+ }
911
+ });
912
+ }
913
+ }
914
+ if (options.astro) {
915
+ configs.push({
916
+ files: [GLOB_ASTRO],
917
+ languageOptions: {
918
+ parser: parserPlain
919
+ },
920
+ name: "antfu:formatter:astro",
921
+ rules: {
922
+ "format/prettier": [
923
+ "error",
924
+ {
925
+ ...prettierOptions,
926
+ parser: "astro",
927
+ plugins: [
928
+ "prettier-plugin-astro"
929
+ ]
930
+ }
931
+ ]
932
+ }
933
+ });
934
+ }
935
+ if (options.graphql) {
936
+ configs.push({
937
+ files: ["**/*.graphql"],
938
+ languageOptions: {
939
+ parser: parserPlain
940
+ },
941
+ name: "antfu:formatter:graphql",
942
+ rules: {
943
+ "format/prettier": [
944
+ "error",
945
+ {
946
+ ...prettierOptions,
947
+ parser: "graphql"
948
+ }
949
+ ]
950
+ }
951
+ });
952
+ }
953
+ return configs;
954
+ }
955
+
956
+ // src/configs/react.ts
957
+ import { isPackageExists as isPackageExists3 } from "local-pkg";
958
+ var ReactRefreshAllowConstantExportPackages = [
959
+ "vite"
960
+ ];
961
+ async function react(options = {}) {
962
+ const {
963
+ files = [GLOB_JSX, GLOB_TSX],
964
+ overrides = {},
965
+ typescript: typescript2 = true
966
+ } = options;
967
+ await ensurePackages([
968
+ "eslint-plugin-react",
969
+ "eslint-plugin-react-hooks",
970
+ "eslint-plugin-react-refresh"
971
+ ]);
972
+ const [
973
+ pluginReact,
974
+ pluginReactHooks,
975
+ pluginReactRefresh
976
+ ] = await Promise.all([
977
+ interopDefault(import("eslint-plugin-react")),
978
+ interopDefault(import("eslint-plugin-react-hooks")),
979
+ interopDefault(import("eslint-plugin-react-refresh"))
980
+ ]);
981
+ const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
982
+ (i) => isPackageExists3(i)
983
+ );
984
+ return [
985
+ {
986
+ name: "antfu:react:setup",
987
+ plugins: {
988
+ "react": pluginReact,
989
+ "react-hooks": pluginReactHooks,
990
+ "react-refresh": pluginReactRefresh
991
+ },
992
+ settings: {
993
+ react: {
994
+ version: "detect"
995
+ }
996
+ }
997
+ },
998
+ {
999
+ files,
1000
+ languageOptions: {
1001
+ parserOptions: {
1002
+ ecmaFeatures: {
1003
+ jsx: true
1004
+ }
1005
+ }
1006
+ },
1007
+ name: "antfu:react:rules",
1008
+ rules: {
1009
+ // recommended rules react-hooks
1010
+ "react-hooks/exhaustive-deps": "warn",
1011
+ "react-hooks/rules-of-hooks": "error",
1012
+ // react refresh
1013
+ "react-refresh/only-export-components": [
1014
+ "warn",
1015
+ { allowConstantExport: isAllowConstantExport }
1016
+ ],
1017
+ // recommended rules react
1018
+ "react/display-name": "error",
1019
+ "react/jsx-key": "error",
1020
+ "react/jsx-no-comment-textnodes": "error",
1021
+ "react/jsx-no-duplicate-props": "error",
1022
+ "react/jsx-no-target-blank": "error",
1023
+ "react/jsx-no-undef": "error",
1024
+ "react/jsx-uses-react": "error",
1025
+ "react/jsx-uses-vars": "error",
1026
+ "react/no-children-prop": "error",
1027
+ "react/no-danger-with-children": "error",
1028
+ "react/no-deprecated": "error",
1029
+ "react/no-direct-mutation-state": "error",
1030
+ "react/no-find-dom-node": "error",
1031
+ "react/no-is-mounted": "error",
1032
+ "react/no-render-return-value": "error",
1033
+ "react/no-string-refs": "error",
1034
+ "react/no-unescaped-entities": "error",
1035
+ "react/no-unknown-property": "error",
1036
+ "react/no-unsafe": "off",
1037
+ "react/prop-types": "error",
1038
+ "react/react-in-jsx-scope": "off",
1039
+ "react/require-render-return": "error",
1040
+ ...typescript2 ? {
1041
+ "react/jsx-no-undef": "off",
1042
+ "react/prop-type": "off"
1043
+ } : {},
1044
+ // overrides
1045
+ ...overrides
1046
+ }
1047
+ }
1048
+ ];
1049
+ }
1050
+
1051
+ // src/configs/sort.ts
1052
+ async function sortPackageJson() {
1053
+ return [
1054
+ {
1055
+ files: ["**/package.json"],
1056
+ name: "antfu:sort-package-json",
1057
+ rules: {
1058
+ "jsonc/sort-array-values": [
1059
+ "error",
1060
+ {
1061
+ order: { type: "asc" },
1062
+ pathPattern: "^files$"
1063
+ }
1064
+ ],
1065
+ "jsonc/sort-keys": [
1066
+ "error",
1067
+ {
1068
+ order: [
1069
+ "publisher",
1070
+ "name",
1071
+ "displayName",
1072
+ "type",
1073
+ "version",
1074
+ "private",
1075
+ "packageManager",
1076
+ "description",
1077
+ "author",
1078
+ "license",
1079
+ "funding",
1080
+ "homepage",
1081
+ "repository",
1082
+ "bugs",
1083
+ "keywords",
1084
+ "categories",
1085
+ "sideEffects",
1086
+ "exports",
1087
+ "main",
1088
+ "module",
1089
+ "unpkg",
1090
+ "jsdelivr",
1091
+ "types",
1092
+ "typesVersions",
1093
+ "bin",
1094
+ "icon",
1095
+ "files",
1096
+ "engines",
1097
+ "activationEvents",
1098
+ "contributes",
1099
+ "scripts",
1100
+ "peerDependencies",
1101
+ "peerDependenciesMeta",
1102
+ "dependencies",
1103
+ "optionalDependencies",
1104
+ "devDependencies",
1105
+ "pnpm",
1106
+ "overrides",
1107
+ "resolutions",
1108
+ "husky",
1109
+ "simple-git-hooks",
1110
+ "lint-staged",
1111
+ "eslintConfig"
1112
+ ],
1113
+ pathPattern: "^$"
1114
+ },
1115
+ {
1116
+ order: { type: "asc" },
1117
+ pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
1118
+ },
1119
+ {
1120
+ order: { type: "asc" },
1121
+ pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
1122
+ },
1123
+ {
1124
+ order: [
1125
+ "types",
1126
+ "import",
1127
+ "require",
1128
+ "default"
1129
+ ],
1130
+ pathPattern: "^exports.*$"
1131
+ },
1132
+ {
1133
+ order: [
1134
+ // client hooks only
1135
+ "pre-commit",
1136
+ "prepare-commit-msg",
1137
+ "commit-msg",
1138
+ "post-commit",
1139
+ "pre-rebase",
1140
+ "post-rewrite",
1141
+ "post-checkout",
1142
+ "post-merge",
1143
+ "pre-push",
1144
+ "pre-auto-gc"
1145
+ ],
1146
+ pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
1147
+ }
1148
+ ]
1149
+ }
1150
+ }
1151
+ ];
1152
+ }
1153
+ function sortTsconfig() {
1154
+ return [
1155
+ {
1156
+ files: ["**/tsconfig.json", "**/tsconfig.*.json"],
1157
+ name: "antfu:sort-tsconfig",
1158
+ rules: {
1159
+ "jsonc/sort-keys": [
1160
+ "error",
1161
+ {
1162
+ order: [
1163
+ "extends",
1164
+ "compilerOptions",
1165
+ "references",
1166
+ "files",
1167
+ "include",
1168
+ "exclude"
1169
+ ],
1170
+ pathPattern: "^$"
1171
+ },
1172
+ {
1173
+ order: [
1174
+ /* Projects */
1175
+ "incremental",
1176
+ "composite",
1177
+ "tsBuildInfoFile",
1178
+ "disableSourceOfProjectReferenceRedirect",
1179
+ "disableSolutionSearching",
1180
+ "disableReferencedProjectLoad",
1181
+ /* Language and Environment */
1182
+ "target",
1183
+ "jsx",
1184
+ "jsxFactory",
1185
+ "jsxFragmentFactory",
1186
+ "jsxImportSource",
1187
+ "lib",
1188
+ "moduleDetection",
1189
+ "noLib",
1190
+ "reactNamespace",
1191
+ "useDefineForClassFields",
1192
+ "emitDecoratorMetadata",
1193
+ "experimentalDecorators",
1194
+ /* Modules */
1195
+ "baseUrl",
1196
+ "rootDir",
1197
+ "rootDirs",
1198
+ "customConditions",
1199
+ "module",
1200
+ "moduleResolution",
1201
+ "moduleSuffixes",
1202
+ "noResolve",
1203
+ "paths",
1204
+ "resolveJsonModule",
1205
+ "resolvePackageJsonExports",
1206
+ "resolvePackageJsonImports",
1207
+ "typeRoots",
1208
+ "types",
1209
+ "allowArbitraryExtensions",
1210
+ "allowImportingTsExtensions",
1211
+ "allowUmdGlobalAccess",
1212
+ /* JavaScript Support */
1213
+ "allowJs",
1214
+ "checkJs",
1215
+ "maxNodeModuleJsDepth",
1216
+ /* Type Checking */
1217
+ "strict",
1218
+ "strictBindCallApply",
1219
+ "strictFunctionTypes",
1220
+ "strictNullChecks",
1221
+ "strictPropertyInitialization",
1222
+ "allowUnreachableCode",
1223
+ "allowUnusedLabels",
1224
+ "alwaysStrict",
1225
+ "exactOptionalPropertyTypes",
1226
+ "noFallthroughCasesInSwitch",
1227
+ "noImplicitAny",
1228
+ "noImplicitOverride",
1229
+ "noImplicitReturns",
1230
+ "noImplicitThis",
1231
+ "noPropertyAccessFromIndexSignature",
1232
+ "noUncheckedIndexedAccess",
1233
+ "noUnusedLocals",
1234
+ "noUnusedParameters",
1235
+ "useUnknownInCatchVariables",
1236
+ /* Emit */
1237
+ "declaration",
1238
+ "declarationDir",
1239
+ "declarationMap",
1240
+ "downlevelIteration",
1241
+ "emitBOM",
1242
+ "emitDeclarationOnly",
1243
+ "importHelpers",
1244
+ "importsNotUsedAsValues",
1245
+ "inlineSourceMap",
1246
+ "inlineSources",
1247
+ "mapRoot",
1248
+ "newLine",
1249
+ "noEmit",
1250
+ "noEmitHelpers",
1251
+ "noEmitOnError",
1252
+ "outDir",
1253
+ "outFile",
1254
+ "preserveConstEnums",
1255
+ "preserveValueImports",
1256
+ "removeComments",
1257
+ "sourceMap",
1258
+ "sourceRoot",
1259
+ "stripInternal",
1260
+ /* Interop Constraints */
1261
+ "allowSyntheticDefaultImports",
1262
+ "esModuleInterop",
1263
+ "forceConsistentCasingInFileNames",
1264
+ "isolatedModules",
1265
+ "preserveSymlinks",
1266
+ "verbatimModuleSyntax",
1267
+ /* Completeness */
1268
+ "skipDefaultLibCheck",
1269
+ "skipLibCheck"
1270
+ ],
1271
+ pathPattern: "^compilerOptions$"
1272
+ }
1273
+ ]
1274
+ }
1275
+ }
1276
+ ];
1277
+ }
1278
+
1279
+ // src/configs/svelte.ts
1280
+ async function svelte(options = {}) {
1281
+ const {
1282
+ files = [GLOB_SVELTE],
1283
+ overrides = {},
1284
+ stylistic: stylistic2 = true
1285
+ } = options;
1286
+ const {
1287
+ indent = 2,
1288
+ quotes = "single"
1289
+ } = typeof stylistic2 === "boolean" ? {} : stylistic2;
1290
+ await ensurePackages([
1291
+ "eslint-plugin-svelte"
1292
+ ]);
1293
+ const [
1294
+ pluginSvelte,
1295
+ parserSvelte
1296
+ ] = await Promise.all([
1297
+ interopDefault(import("eslint-plugin-svelte")),
1298
+ interopDefault(import("svelte-eslint-parser"))
1299
+ ]);
1300
+ return [
1301
+ {
1302
+ name: "antfu:svelte:setup",
1303
+ plugins: {
1304
+ svelte: pluginSvelte
1305
+ }
1306
+ },
1307
+ {
1308
+ files,
1309
+ languageOptions: {
1310
+ parser: parserSvelte,
1311
+ parserOptions: {
1312
+ extraFileExtensions: [".svelte"],
1313
+ parser: options.typescript ? await interopDefault(import("@typescript-eslint/parser")) : null
1314
+ }
1315
+ },
1316
+ name: "antfu:svelte:rules",
1317
+ processor: pluginSvelte.processors[".svelte"],
1318
+ rules: {
1319
+ "import/no-mutable-exports": "off",
1320
+ "no-undef": "off",
1321
+ // incompatible with most recent (attribute-form) generic types RFC
1322
+ "no-unused-vars": ["error", {
1323
+ args: "none",
1324
+ caughtErrors: "none",
1325
+ ignoreRestSiblings: true,
1326
+ vars: "all",
1327
+ varsIgnorePattern: "^\\$\\$Props$"
1328
+ }],
1329
+ "svelte/comment-directive": "error",
1330
+ "svelte/no-at-debug-tags": "warn",
1331
+ "svelte/no-at-html-tags": "error",
1332
+ "svelte/no-dupe-else-if-blocks": "error",
1333
+ "svelte/no-dupe-style-properties": "error",
1334
+ "svelte/no-dupe-use-directives": "error",
1335
+ "svelte/no-dynamic-slot-name": "error",
1336
+ "svelte/no-export-load-in-svelte-module-in-kit-pages": "error",
1337
+ "svelte/no-inner-declarations": "error",
1338
+ "svelte/no-not-function-handler": "error",
1339
+ "svelte/no-object-in-text-mustaches": "error",
1340
+ "svelte/no-reactive-functions": "error",
1341
+ "svelte/no-reactive-literals": "error",
1342
+ "svelte/no-shorthand-style-property-overrides": "error",
1343
+ "svelte/no-unknown-style-directive-property": "error",
1344
+ "svelte/no-unused-svelte-ignore": "error",
1345
+ "svelte/no-useless-mustaches": "error",
1346
+ "svelte/require-store-callbacks-use-set-param": "error",
1347
+ "svelte/system": "error",
1348
+ "svelte/valid-compile": "error",
1349
+ "svelte/valid-each-key": "error",
1350
+ "unused-imports/no-unused-vars": [
1351
+ "error",
1352
+ { args: "after-used", argsIgnorePattern: "^_", vars: "all", varsIgnorePattern: "^(_|\\$\\$Props$)" }
1353
+ ],
1354
+ ...stylistic2 ? {
1355
+ "style/indent": "off",
1356
+ // superseded by svelte/indent
1357
+ "style/no-trailing-spaces": "off",
1358
+ // superseded by svelte/no-trailing-spaces
1359
+ "svelte/derived-has-same-inputs-outputs": "error",
1360
+ "svelte/html-closing-bracket-spacing": "error",
1361
+ "svelte/html-quotes": ["error", { prefer: quotes }],
1362
+ "svelte/indent": ["error", { alignAttributesVertically: true, indent }],
1363
+ "svelte/mustache-spacing": "error",
1364
+ "svelte/no-spaces-around-equal-signs-in-attribute": "error",
1365
+ "svelte/no-trailing-spaces": "error",
1366
+ "svelte/spaced-html-comment": "error"
1367
+ } : {},
1368
+ ...overrides
1369
+ }
1370
+ }
1371
+ ];
1372
+ }
1373
+
1374
+ // src/configs/test.ts
1375
+ async function test(options = {}) {
1376
+ const {
1377
+ files = GLOB_TESTS,
1378
+ isInEditor = false,
1379
+ overrides = {}
1380
+ } = options;
1381
+ const [
1382
+ pluginVitest,
1383
+ pluginNoOnlyTests
1384
+ ] = await Promise.all([
1385
+ interopDefault(import("eslint-plugin-vitest")),
1386
+ // @ts-expect-error missing types
1387
+ interopDefault(import("eslint-plugin-no-only-tests"))
1388
+ ]);
1389
+ return [
1390
+ {
1391
+ name: "antfu:test:setup",
1392
+ plugins: {
1393
+ test: {
1394
+ ...pluginVitest,
1395
+ rules: {
1396
+ ...pluginVitest.rules,
1397
+ // extend `test/no-only-tests` rule
1398
+ ...pluginNoOnlyTests.rules
1399
+ }
1400
+ }
1401
+ }
1402
+ },
1403
+ {
1404
+ files,
1405
+ name: "antfu:test:rules",
1406
+ rules: {
1407
+ "node/prefer-global/process": "off",
1408
+ "test/consistent-test-it": ["error", { fn: "it", withinDescribe: "it" }],
1409
+ "test/no-identical-title": "error",
1410
+ "test/no-import-node-test": "error",
1411
+ "test/no-only-tests": isInEditor ? "off" : "error",
1412
+ "test/prefer-hooks-in-order": "error",
1413
+ "test/prefer-lowercase-title": "error",
1414
+ ...overrides
1415
+ }
1416
+ }
1417
+ ];
1418
+ }
1419
+
1420
+ // src/configs/typescript.ts
1421
+ import process2 from "process";
1422
+ async function typescript(options = {}) {
1423
+ const {
1424
+ componentExts = [],
1425
+ overrides = {},
1426
+ parserOptions = {}
1427
+ } = options;
1428
+ const files = options.files ?? [
1429
+ GLOB_SRC,
1430
+ ...componentExts.map((ext) => `**/*.${ext}`)
1431
+ ];
1432
+ const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
1433
+ const tsconfigPath = options?.tsconfigPath ? toArray(options.tsconfigPath) : void 0;
1434
+ const isTypeAware = !!tsconfigPath;
1435
+ const typeAwareRules = {
1436
+ "dot-notation": "off",
1437
+ "no-implied-eval": "off",
1438
+ "no-throw-literal": "off",
1439
+ "ts/await-thenable": "error",
1440
+ "ts/dot-notation": ["error", { allowKeywords: true }],
1441
+ "ts/no-floating-promises": "error",
1442
+ "ts/no-for-in-array": "error",
1443
+ "ts/no-implied-eval": "error",
1444
+ "ts/no-misused-promises": "error",
1445
+ "ts/no-throw-literal": "error",
1446
+ "ts/no-unnecessary-type-assertion": "error",
1447
+ "ts/no-unsafe-argument": "error",
1448
+ "ts/no-unsafe-assignment": "error",
1449
+ "ts/no-unsafe-call": "error",
1450
+ "ts/no-unsafe-member-access": "error",
1451
+ "ts/no-unsafe-return": "error",
1452
+ "ts/restrict-plus-operands": "error",
1453
+ "ts/restrict-template-expressions": "error",
1454
+ "ts/unbound-method": "error"
1455
+ };
1456
+ const [
1457
+ pluginTs,
1458
+ parserTs
1459
+ ] = await Promise.all([
1460
+ interopDefault(import("@typescript-eslint/eslint-plugin")),
1461
+ interopDefault(import("@typescript-eslint/parser"))
1462
+ ]);
1463
+ function makeParser(typeAware, files2, ignores2) {
1464
+ return {
1465
+ files: files2,
1466
+ ...ignores2 ? { ignores: ignores2 } : {},
1467
+ languageOptions: {
1468
+ parser: parserTs,
1469
+ parserOptions: {
1470
+ extraFileExtensions: componentExts.map((ext) => `.${ext}`),
1471
+ sourceType: "module",
1472
+ ...typeAware ? {
1473
+ project: tsconfigPath,
1474
+ tsconfigRootDir: process2.cwd()
1475
+ } : {},
1476
+ ...parserOptions
1477
+ }
1478
+ },
1479
+ name: `antfu:typescript:${typeAware ? "type-aware-parser" : "parser"}`
1480
+ };
1481
+ }
1482
+ return [
1483
+ {
1484
+ // Install the plugins without globs, so they can be configured separately.
1485
+ name: "antfu:typescript:setup",
1486
+ plugins: {
1487
+ antfu: default2,
1488
+ ts: pluginTs
1489
+ }
1490
+ },
1491
+ // assign type-aware parser for type-aware files and type-unaware parser for the rest
1492
+ ...isTypeAware ? [
1493
+ makeParser(true, filesTypeAware),
1494
+ makeParser(false, files, filesTypeAware)
1495
+ ] : [makeParser(false, files)],
1496
+ {
1497
+ files,
1498
+ name: "antfu:typescript:rules",
1499
+ rules: {
1500
+ ...renameRules(
1501
+ pluginTs.configs["eslint-recommended"].overrides[0].rules,
1502
+ { "@typescript-eslint": "ts" }
1503
+ ),
1504
+ ...renameRules(
1505
+ pluginTs.configs.strict.rules,
1506
+ { "@typescript-eslint": "ts" }
1507
+ ),
1508
+ "no-dupe-class-members": "off",
1509
+ "no-loss-of-precision": "off",
1510
+ "no-redeclare": "off",
1511
+ "no-use-before-define": "off",
1512
+ "no-useless-constructor": "off",
1513
+ "ts/ban-ts-comment": ["error", { "ts-ignore": "allow-with-description" }],
1514
+ "ts/ban-types": ["error", { types: { Function: false } }],
1515
+ "ts/consistent-type-definitions": ["error", "interface"],
1516
+ "ts/consistent-type-imports": ["error", { disallowTypeAnnotations: false, prefer: "type-imports" }],
1517
+ "ts/method-signature-style": ["error", "property"],
1518
+ // https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful
1519
+ "ts/no-dupe-class-members": "error",
1520
+ "ts/no-dynamic-delete": "off",
1521
+ "ts/no-explicit-any": "off",
1522
+ "ts/no-extraneous-class": "off",
1523
+ "ts/no-import-type-side-effects": "error",
1524
+ "ts/no-invalid-void-type": "off",
1525
+ "ts/no-loss-of-precision": "error",
1526
+ "ts/no-non-null-assertion": "off",
1527
+ "ts/no-redeclare": "error",
1528
+ "ts/no-require-imports": "error",
1529
+ "ts/no-unused-vars": "off",
1530
+ "ts/no-use-before-define": ["error", { classes: false, functions: false, variables: true }],
1531
+ "ts/no-useless-constructor": "off",
1532
+ "ts/prefer-ts-expect-error": "error",
1533
+ "ts/triple-slash-reference": "off",
1534
+ "ts/unified-signatures": "off",
1535
+ ...overrides
1536
+ }
1537
+ },
1538
+ {
1539
+ files: filesTypeAware,
1540
+ name: "antfu:typescript:rules-type-aware",
1541
+ rules: {
1542
+ ...tsconfigPath ? typeAwareRules : {},
1543
+ ...overrides
1544
+ }
1545
+ },
1546
+ {
1547
+ files: ["**/*.d.ts"],
1548
+ name: "antfu:typescript:dts-overrides",
1549
+ rules: {
1550
+ "eslint-comments/no-unlimited-disable": "off",
1551
+ "import/no-duplicates": "off",
1552
+ "no-restricted-syntax": "off",
1553
+ "unused-imports/no-unused-vars": "off"
1554
+ }
1555
+ },
1556
+ {
1557
+ files: ["**/*.{test,spec}.ts?(x)"],
1558
+ name: "antfu:typescript:tests-overrides",
1559
+ rules: {
1560
+ "no-unused-expressions": "off"
1561
+ }
1562
+ },
1563
+ {
1564
+ files: ["**/*.js", "**/*.cjs"],
1565
+ name: "antfu:typescript:javascript-overrides",
1566
+ rules: {
1567
+ "ts/no-require-imports": "off",
1568
+ "ts/no-var-requires": "off"
1569
+ }
1570
+ }
1571
+ ];
1572
+ }
1573
+
1574
+ // src/configs/unicorn.ts
1575
+ async function unicorn() {
1576
+ return [
1577
+ {
1578
+ name: "antfu:unicorn",
1579
+ plugins: {
1580
+ unicorn: default5
1581
+ },
1582
+ rules: {
1583
+ // Pass error message when throwing errors
1584
+ "unicorn/error-message": "error",
1585
+ // Uppercase regex escapes
1586
+ "unicorn/escape-case": "error",
1587
+ // Array.isArray instead of instanceof
1588
+ "unicorn/no-instanceof-array": "error",
1589
+ // Ban `new Array` as `Array` constructor's params are ambiguous
1590
+ "unicorn/no-new-array": "error",
1591
+ // Prevent deprecated `new Buffer()`
1592
+ "unicorn/no-new-buffer": "error",
1593
+ // Lowercase number formatting for octal, hex, binary (0x1'error' instead of 0X1'error')
1594
+ "unicorn/number-literal-case": "error",
1595
+ // textContent instead of innerText
1596
+ "unicorn/prefer-dom-node-text-content": "error",
1597
+ // includes over indexOf when checking for existence
1598
+ "unicorn/prefer-includes": "error",
1599
+ // Prefer using the node: protocol
1600
+ "unicorn/prefer-node-protocol": "error",
1601
+ // Prefer using number properties like `Number.isNaN` rather than `isNaN`
1602
+ "unicorn/prefer-number-properties": "error",
1603
+ // String methods startsWith/endsWith instead of more complicated stuff
1604
+ "unicorn/prefer-string-starts-ends-with": "error",
1605
+ // Enforce throwing type error when throwing error while checking typeof
1606
+ "unicorn/prefer-type-error": "error",
1607
+ // Use new when throwing error
1608
+ "unicorn/throw-new-error": "error"
1609
+ }
1610
+ }
1611
+ ];
1612
+ }
1613
+
1614
+ // src/configs/unocss.ts
1615
+ async function unocss(options = {}) {
1616
+ const {
1617
+ attributify = true,
1618
+ strict = false
1619
+ } = options;
1620
+ await ensurePackages([
1621
+ "@unocss/eslint-plugin"
1622
+ ]);
1623
+ const [
1624
+ pluginUnoCSS
1625
+ ] = await Promise.all([
1626
+ interopDefault(import("@unocss/eslint-plugin"))
1627
+ ]);
1628
+ return [
1629
+ {
1630
+ name: "antfu:unocss",
1631
+ plugins: {
1632
+ unocss: pluginUnoCSS
1633
+ },
1634
+ rules: {
1635
+ "unocss/order": "warn",
1636
+ ...attributify ? {
1637
+ "unocss/order-attributify": "warn"
1638
+ } : {},
1639
+ ...strict ? {
1640
+ "unocss/blocklist": "error"
1641
+ } : {}
1642
+ }
1643
+ }
1644
+ ];
1645
+ }
1646
+
1647
+ // src/configs/vue.ts
1648
+ import { mergeProcessors as mergeProcessors2 } from "eslint-merge-processors";
1649
+ async function vue(options = {}) {
1650
+ const {
1651
+ files = [GLOB_VUE],
1652
+ overrides = {},
1653
+ stylistic: stylistic2 = true,
1654
+ vueVersion = 3
1655
+ } = options;
1656
+ const sfcBlocks = options.sfcBlocks === true ? {} : options.sfcBlocks ?? {};
1657
+ const {
1658
+ indent = 2
1659
+ } = typeof stylistic2 === "boolean" ? {} : stylistic2;
1660
+ const [
1661
+ pluginVue,
1662
+ parserVue,
1663
+ processorVueBlocks
1664
+ ] = await Promise.all([
1665
+ // @ts-expect-error missing types
1666
+ interopDefault(import("eslint-plugin-vue")),
1667
+ interopDefault(import("vue-eslint-parser")),
1668
+ interopDefault(import("eslint-processor-vue-blocks"))
1669
+ ]);
1670
+ return [
1671
+ {
1672
+ // This allows Vue plugin to work with auto imports
1673
+ // https://github.com/vuejs/eslint-plugin-vue/pull/2422
1674
+ languageOptions: {
1675
+ globals: {
1676
+ computed: "readonly",
1677
+ defineEmits: "readonly",
1678
+ defineExpose: "readonly",
1679
+ defineProps: "readonly",
1680
+ onMounted: "readonly",
1681
+ onUnmounted: "readonly",
1682
+ reactive: "readonly",
1683
+ ref: "readonly",
1684
+ shallowReactive: "readonly",
1685
+ shallowRef: "readonly",
1686
+ toRef: "readonly",
1687
+ toRefs: "readonly",
1688
+ watch: "readonly",
1689
+ watchEffect: "readonly"
1690
+ }
1691
+ },
1692
+ name: "antfu:vue:setup",
1693
+ plugins: {
1694
+ vue: pluginVue
1695
+ }
1696
+ },
1697
+ {
1698
+ files,
1699
+ languageOptions: {
1700
+ parser: parserVue,
1701
+ parserOptions: {
1702
+ ecmaFeatures: {
1703
+ jsx: true
1704
+ },
1705
+ extraFileExtensions: [".vue"],
1706
+ parser: options.typescript ? await interopDefault(import("@typescript-eslint/parser")) : null,
1707
+ sourceType: "module"
1708
+ }
1709
+ },
1710
+ name: "antfu:vue:rules",
1711
+ processor: sfcBlocks === false ? pluginVue.processors[".vue"] : mergeProcessors2([
1712
+ pluginVue.processors[".vue"],
1713
+ processorVueBlocks({
1714
+ ...sfcBlocks,
1715
+ blocks: {
1716
+ styles: true,
1717
+ ...sfcBlocks.blocks
1718
+ }
1719
+ })
1720
+ ]),
1721
+ rules: {
1722
+ ...pluginVue.configs.base.rules,
1723
+ ...vueVersion === 2 ? {
1724
+ ...pluginVue.configs.essential.rules,
1725
+ ...pluginVue.configs["strongly-recommended"].rules,
1726
+ ...pluginVue.configs.recommended.rules
1727
+ } : {
1728
+ ...pluginVue.configs["vue3-essential"].rules,
1729
+ ...pluginVue.configs["vue3-strongly-recommended"].rules,
1730
+ ...pluginVue.configs["vue3-recommended"].rules
1731
+ },
1732
+ "node/prefer-global/process": "off",
1733
+ "vue/block-order": ["error", {
1734
+ order: ["script", "template", "style"]
1735
+ }],
1736
+ "vue/component-name-in-template-casing": ["error", "PascalCase"],
1737
+ "vue/component-options-name-casing": ["error", "PascalCase"],
1738
+ // this is deprecated
1739
+ "vue/component-tags-order": "off",
1740
+ "vue/custom-event-name-casing": ["error", "camelCase"],
1741
+ "vue/define-macros-order": ["error", {
1742
+ order: ["defineOptions", "defineProps", "defineEmits", "defineSlots"]
1743
+ }],
1744
+ "vue/dot-location": ["error", "property"],
1745
+ "vue/dot-notation": ["error", { allowKeywords: true }],
1746
+ "vue/eqeqeq": ["error", "smart"],
1747
+ "vue/html-indent": ["error", indent],
1748
+ "vue/html-quotes": ["error", "double"],
1749
+ "vue/max-attributes-per-line": "off",
1750
+ "vue/multi-word-component-names": "off",
1751
+ "vue/no-dupe-keys": "off",
1752
+ "vue/no-empty-pattern": "error",
1753
+ "vue/no-irregular-whitespace": "error",
1754
+ "vue/no-loss-of-precision": "error",
1755
+ "vue/no-restricted-syntax": [
1756
+ "error",
1757
+ "DebuggerStatement",
1758
+ "LabeledStatement",
1759
+ "WithStatement"
1760
+ ],
1761
+ "vue/no-restricted-v-bind": ["error", "/^v-/"],
1762
+ "vue/no-setup-props-reactivity-loss": "off",
1763
+ "vue/no-sparse-arrays": "error",
1764
+ "vue/no-unused-refs": "error",
1765
+ "vue/no-useless-v-bind": "error",
1766
+ "vue/no-v-html": "off",
1767
+ "vue/object-shorthand": [
1768
+ "error",
1769
+ "always",
1770
+ {
1771
+ avoidQuotes: true,
1772
+ ignoreConstructors: false
1773
+ }
1774
+ ],
1775
+ "vue/prefer-separate-static-class": "error",
1776
+ "vue/prefer-template": "error",
1777
+ "vue/prop-name-casing": ["error", "camelCase"],
1778
+ "vue/require-default-prop": "off",
1779
+ "vue/require-prop-types": "off",
1780
+ "vue/space-infix-ops": "error",
1781
+ "vue/space-unary-ops": ["error", { nonwords: false, words: true }],
1782
+ ...stylistic2 ? {
1783
+ "vue/array-bracket-spacing": ["error", "never"],
1784
+ "vue/arrow-spacing": ["error", { after: true, before: true }],
1785
+ "vue/block-spacing": ["error", "always"],
1786
+ "vue/block-tag-newline": ["error", {
1787
+ multiline: "always",
1788
+ singleline: "always"
1789
+ }],
1790
+ "vue/brace-style": ["error", "stroustrup", { allowSingleLine: true }],
1791
+ "vue/comma-dangle": ["error", "always-multiline"],
1792
+ "vue/comma-spacing": ["error", { after: true, before: false }],
1793
+ "vue/comma-style": ["error", "last"],
1794
+ "vue/html-comment-content-spacing": ["error", "always", {
1795
+ exceptions: ["-"]
1796
+ }],
1797
+ "vue/key-spacing": ["error", { afterColon: true, beforeColon: false }],
1798
+ "vue/keyword-spacing": ["error", { after: true, before: true }],
1799
+ "vue/object-curly-newline": "off",
1800
+ "vue/object-curly-spacing": ["error", "always"],
1801
+ "vue/object-property-newline": ["error", { allowMultiplePropertiesPerLine: true }],
1802
+ "vue/operator-linebreak": ["error", "before"],
1803
+ "vue/padding-line-between-blocks": ["error", "always"],
1804
+ "vue/quote-props": ["error", "consistent-as-needed"],
1805
+ "vue/space-in-parens": ["error", "never"],
1806
+ "vue/template-curly-spacing": "error"
1807
+ } : {},
1808
+ ...overrides
1809
+ }
1810
+ }
1811
+ ];
1812
+ }
1813
+
1814
+ // src/configs/yaml.ts
1815
+ async function yaml(options = {}) {
1816
+ const {
1817
+ files = [GLOB_YAML],
1818
+ overrides = {},
1819
+ stylistic: stylistic2 = true
1820
+ } = options;
1821
+ const {
1822
+ indent = 2,
1823
+ quotes = "single"
1824
+ } = typeof stylistic2 === "boolean" ? {} : stylistic2;
1825
+ const [
1826
+ pluginYaml,
1827
+ parserYaml
1828
+ ] = await Promise.all([
1829
+ interopDefault(import("eslint-plugin-yml")),
1830
+ interopDefault(import("yaml-eslint-parser"))
1831
+ ]);
1832
+ return [
1833
+ {
1834
+ name: "antfu:yaml:setup",
1835
+ plugins: {
1836
+ yaml: pluginYaml
1837
+ }
1838
+ },
1839
+ {
1840
+ files,
1841
+ languageOptions: {
1842
+ parser: parserYaml
1843
+ },
1844
+ name: "antfu:yaml:rules",
1845
+ rules: {
1846
+ "style/spaced-comment": "off",
1847
+ "yaml/block-mapping": "error",
1848
+ "yaml/block-sequence": "error",
1849
+ "yaml/no-empty-key": "error",
1850
+ "yaml/no-empty-sequence-entry": "error",
1851
+ "yaml/no-irregular-whitespace": "error",
1852
+ "yaml/plain-scalar": "error",
1853
+ "yaml/vue-custom-block/no-parsing-error": "error",
1854
+ ...stylistic2 ? {
1855
+ "yaml/block-mapping-question-indicator-newline": "error",
1856
+ "yaml/block-sequence-hyphen-indicator-newline": "error",
1857
+ "yaml/flow-mapping-curly-newline": "error",
1858
+ "yaml/flow-mapping-curly-spacing": "error",
1859
+ "yaml/flow-sequence-bracket-newline": "error",
1860
+ "yaml/flow-sequence-bracket-spacing": "error",
1861
+ "yaml/indent": ["error", indent === "tab" ? 2 : indent],
1862
+ "yaml/key-spacing": "error",
1863
+ "yaml/no-tab-indent": "error",
1864
+ "yaml/quotes": ["error", { avoidEscape: false, prefer: quotes }],
1865
+ "yaml/spaced-comment": "error"
1866
+ } : {},
1867
+ ...overrides
1868
+ }
1869
+ }
1870
+ ];
1871
+ }
1872
+
1873
+ // src/configs/toml.ts
1874
+ async function toml(options = {}) {
1875
+ const {
1876
+ files = [GLOB_TOML],
1877
+ overrides = {},
1878
+ stylistic: stylistic2 = true
1879
+ } = options;
1880
+ const {
1881
+ indent = 2
1882
+ } = typeof stylistic2 === "boolean" ? {} : stylistic2;
1883
+ const [
1884
+ pluginToml,
1885
+ parserToml
1886
+ ] = await Promise.all([
1887
+ interopDefault(import("eslint-plugin-toml")),
1888
+ interopDefault(import("toml-eslint-parser"))
1889
+ ]);
1890
+ return [
1891
+ {
1892
+ name: "antfu:toml:setup",
1893
+ plugins: {
1894
+ toml: pluginToml
1895
+ }
1896
+ },
1897
+ {
1898
+ files,
1899
+ languageOptions: {
1900
+ parser: parserToml
1901
+ },
1902
+ name: "antfu:toml:rules",
1903
+ rules: {
1904
+ "style/spaced-comment": "off",
1905
+ "toml/comma-style": "error",
1906
+ "toml/keys-order": "error",
1907
+ "toml/no-space-dots": "error",
1908
+ "toml/no-unreadable-number-separator": "error",
1909
+ "toml/precision-of-fractional-seconds": "error",
1910
+ "toml/precision-of-integer": "error",
1911
+ "toml/tables-order": "error",
1912
+ "toml/vue-custom-block/no-parsing-error": "error",
1913
+ ...stylistic2 ? {
1914
+ "toml/array-bracket-newline": "error",
1915
+ "toml/array-bracket-spacing": "error",
1916
+ "toml/array-element-newline": "error",
1917
+ "toml/indent": ["error", indent === "tab" ? 2 : indent],
1918
+ "toml/inline-table-curly-spacing": "error",
1919
+ "toml/key-spacing": "error",
1920
+ "toml/padding-line-between-pairs": "error",
1921
+ "toml/padding-line-between-tables": "error",
1922
+ "toml/quoted-keys": "error",
1923
+ "toml/spaced-comment": "error",
1924
+ "toml/table-bracket-spacing": "error"
1925
+ } : {},
1926
+ ...overrides
1927
+ }
1928
+ }
1929
+ ];
1930
+ }
1931
+
1932
+ // src/configs/astro.ts
1933
+ async function astro(options = {}) {
1934
+ const {
1935
+ files = [GLOB_ASTRO],
1936
+ overrides = {},
1937
+ stylistic: stylistic2 = true
1938
+ } = options;
1939
+ const [
1940
+ pluginAstro,
1941
+ parserAstro,
1942
+ parserTs
1943
+ ] = await Promise.all([
1944
+ interopDefault(import("eslint-plugin-astro")),
1945
+ interopDefault(import("astro-eslint-parser")),
1946
+ interopDefault(import("@typescript-eslint/parser"))
1947
+ ]);
1948
+ return [
1949
+ {
1950
+ name: "antfu:astro:setup",
1951
+ plugins: {
1952
+ astro: pluginAstro
1953
+ }
1954
+ },
1955
+ {
1956
+ files,
1957
+ languageOptions: {
1958
+ parser: parserAstro,
1959
+ parserOptions: {
1960
+ extraFileExtensions: [".astro"],
1961
+ parser: parserTs
1962
+ }
1963
+ },
1964
+ name: "antfu:astro:rules",
1965
+ rules: {
1966
+ "astro/no-set-html-directive": "off",
1967
+ "astro/semi": "off",
1968
+ ...stylistic2 ? {
1969
+ "style/indent": "off",
1970
+ "style/jsx-closing-tag-location": "off",
1971
+ "style/jsx-indent": "off",
1972
+ "style/jsx-one-expression-per-line": "off",
1973
+ "style/no-multiple-empty-lines": "off"
1974
+ } : {},
1975
+ ...overrides
1976
+ }
1977
+ }
1978
+ ];
1979
+ }
1980
+
1981
+ // src/factory.ts
1982
+ var flatConfigProps = [
1983
+ "name",
1984
+ "files",
1985
+ "ignores",
1986
+ "languageOptions",
1987
+ "linterOptions",
1988
+ "processor",
1989
+ "plugins",
1990
+ "rules",
1991
+ "settings"
1992
+ ];
1993
+ var VuePackages = [
1994
+ "vue",
1995
+ "nuxt",
1996
+ "vitepress",
1997
+ "@slidev/cli"
1998
+ ];
1999
+ var defaultPluginRenaming = {
2000
+ "@stylistic": "style",
2001
+ "@typescript-eslint": "ts",
2002
+ "import-x": "import",
2003
+ "n": "node",
2004
+ "vitest": "test",
2005
+ "yml": "yaml"
2006
+ };
2007
+ async function dhzh(options = {}, ...userConfigs) {
2008
+ const {
2009
+ astro: enableAstro = false,
2010
+ autoRenamePlugins = true,
2011
+ componentExts = [],
2012
+ gitignore: enableGitignore = true,
2013
+ isInEditor = !!((process3.env.VSCODE_PID || process3.env.VSCODE_CWD || process3.env.JETBRAINS_IDE || process3.env.VIM) && !process3.env.CI),
2014
+ react: enableReact = false,
2015
+ svelte: enableSvelte = false,
2016
+ typescript: enableTypeScript = isPackageExists4("typescript"),
2017
+ unocss: enableUnoCSS = false,
2018
+ vue: enableVue = VuePackages.some((i) => isPackageExists4(i))
2019
+ } = options;
2020
+ const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
2021
+ if (stylisticOptions && !("jsx" in stylisticOptions))
2022
+ stylisticOptions.jsx = options.jsx ?? true;
2023
+ const configs = [];
2024
+ if (enableGitignore) {
2025
+ if (typeof enableGitignore !== "boolean") {
2026
+ configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r(enableGitignore)]));
2027
+ } else {
2028
+ if (fs.existsSync(".gitignore"))
2029
+ configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r()]));
2030
+ }
2031
+ }
2032
+ configs.push(
2033
+ ignores(),
2034
+ javascript({
2035
+ isInEditor,
2036
+ overrides: getOverrides(options, "javascript")
2037
+ }),
2038
+ comments(),
2039
+ node(),
2040
+ jsdoc({
2041
+ stylistic: stylisticOptions
2042
+ }),
2043
+ imports({
2044
+ stylistic: stylisticOptions
2045
+ }),
2046
+ unicorn(),
2047
+ // Optional plugins (installed but not enabled by default)
2048
+ perfectionist()
2049
+ );
2050
+ if (enableVue)
2051
+ componentExts.push("vue");
2052
+ if (enableTypeScript) {
2053
+ configs.push(typescript({
2054
+ ...resolveSubOptions(options, "typescript"),
2055
+ componentExts,
2056
+ overrides: getOverrides(options, "typescript")
2057
+ }));
2058
+ }
2059
+ if (stylisticOptions) {
2060
+ configs.push(stylistic({
2061
+ ...stylisticOptions,
2062
+ overrides: getOverrides(options, "stylistic")
2063
+ }));
2064
+ }
2065
+ if (options.test ?? true) {
2066
+ configs.push(test({
2067
+ isInEditor,
2068
+ overrides: getOverrides(options, "test")
2069
+ }));
2070
+ }
2071
+ if (enableVue) {
2072
+ configs.push(vue({
2073
+ ...resolveSubOptions(options, "vue"),
2074
+ overrides: getOverrides(options, "vue"),
2075
+ stylistic: stylisticOptions,
2076
+ typescript: !!enableTypeScript
2077
+ }));
2078
+ }
2079
+ if (enableReact) {
2080
+ configs.push(react({
2081
+ overrides: getOverrides(options, "react"),
2082
+ typescript: !!enableTypeScript
2083
+ }));
2084
+ }
2085
+ if (enableSvelte) {
2086
+ configs.push(svelte({
2087
+ overrides: getOverrides(options, "svelte"),
2088
+ stylistic: stylisticOptions,
2089
+ typescript: !!enableTypeScript
2090
+ }));
2091
+ }
2092
+ if (enableUnoCSS) {
2093
+ configs.push(unocss({
2094
+ ...resolveSubOptions(options, "unocss"),
2095
+ overrides: getOverrides(options, "unocss")
2096
+ }));
2097
+ }
2098
+ if (enableAstro) {
2099
+ configs.push(astro({
2100
+ overrides: getOverrides(options, "astro"),
2101
+ stylistic: stylisticOptions
2102
+ }));
2103
+ }
2104
+ if (options.jsonc ?? true) {
2105
+ configs.push(
2106
+ jsonc({
2107
+ overrides: getOverrides(options, "jsonc"),
2108
+ stylistic: stylisticOptions
2109
+ }),
2110
+ sortPackageJson(),
2111
+ sortTsconfig()
2112
+ );
2113
+ }
2114
+ if (options.yaml ?? true) {
2115
+ configs.push(yaml({
2116
+ overrides: getOverrides(options, "yaml"),
2117
+ stylistic: stylisticOptions
2118
+ }));
2119
+ }
2120
+ if (options.toml ?? true) {
2121
+ configs.push(toml({
2122
+ overrides: getOverrides(options, "toml"),
2123
+ stylistic: stylisticOptions
2124
+ }));
2125
+ }
2126
+ if (options.markdown ?? true) {
2127
+ configs.push(
2128
+ markdown(
2129
+ {
2130
+ componentExts,
2131
+ overrides: getOverrides(options, "markdown")
2132
+ }
2133
+ )
2134
+ );
2135
+ }
2136
+ if (options.formatters) {
2137
+ configs.push(formatters(
2138
+ options.formatters,
2139
+ typeof stylisticOptions === "boolean" ? {} : stylisticOptions
2140
+ ));
2141
+ }
2142
+ const fusedConfig = flatConfigProps.reduce((acc, key) => {
2143
+ if (key in options)
2144
+ acc[key] = options[key];
2145
+ return acc;
2146
+ }, {});
2147
+ if (Object.keys(fusedConfig).length)
2148
+ configs.push([fusedConfig]);
2149
+ const merged = await combine(
2150
+ ...configs,
2151
+ ...userConfigs
2152
+ );
2153
+ if (autoRenamePlugins)
2154
+ return renamePluginInConfigs(merged, defaultPluginRenaming);
2155
+ return merged;
2156
+ }
2157
+ function resolveSubOptions(options, key) {
2158
+ return typeof options[key] === "boolean" ? {} : options[key] || {};
2159
+ }
2160
+ function getOverrides(options, key) {
2161
+ const sub = resolveSubOptions(options, key);
2162
+ return {
2163
+ ...options.overrides?.[key],
2164
+ ..."overrides" in sub ? sub.overrides : {}
2165
+ };
2166
+ }
2167
+
2168
+ // src/index.ts
2169
+ var src_default = dhzh;
2170
+ export {
2171
+ GLOB_ALL_SRC,
2172
+ GLOB_ASTRO,
2173
+ GLOB_CSS,
2174
+ GLOB_EXCLUDE,
2175
+ GLOB_HTML,
2176
+ GLOB_JS,
2177
+ GLOB_JSON,
2178
+ GLOB_JSON5,
2179
+ GLOB_JSONC,
2180
+ GLOB_JSX,
2181
+ GLOB_LESS,
2182
+ GLOB_MARKDOWN,
2183
+ GLOB_MARKDOWN_CODE,
2184
+ GLOB_MARKDOWN_IN_MARKDOWN,
2185
+ GLOB_POSTCSS,
2186
+ GLOB_SCSS,
2187
+ GLOB_SRC,
2188
+ GLOB_SRC_EXT,
2189
+ GLOB_STYLE,
2190
+ GLOB_SVELTE,
2191
+ GLOB_TESTS,
2192
+ GLOB_TOML,
2193
+ GLOB_TS,
2194
+ GLOB_TSX,
2195
+ GLOB_VUE,
2196
+ GLOB_YAML,
2197
+ StylisticConfigDefaults,
2198
+ astro,
2199
+ combine,
2200
+ comments,
2201
+ src_default as default,
2202
+ defaultPluginRenaming,
2203
+ dhzh,
2204
+ ensurePackages,
2205
+ formatters,
2206
+ getOverrides,
2207
+ ignores,
2208
+ imports,
2209
+ interopDefault,
2210
+ javascript,
2211
+ jsdoc,
2212
+ jsonc,
2213
+ markdown,
2214
+ node,
2215
+ parserPlain,
2216
+ perfectionist,
2217
+ react,
2218
+ renamePluginInConfigs,
2219
+ renameRules,
2220
+ resolveSubOptions,
2221
+ sortPackageJson,
2222
+ sortTsconfig,
2223
+ stylistic,
2224
+ svelte,
2225
+ test,
2226
+ toArray,
2227
+ toml,
2228
+ typescript,
2229
+ unicorn,
2230
+ unocss,
2231
+ vue,
2232
+ yaml
2233
+ };