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