@dhzh/eslint-config 1.25.2 → 1.27.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.mjs ADDED
@@ -0,0 +1,1417 @@
1
+ import pluginReact from "@eslint-react/eslint-plugin";
2
+ import pluginReactHooks from "eslint-plugin-react-hooks";
3
+ import pluginReactRefresh from "eslint-plugin-react-refresh";
4
+ import pluginReactCompiler from "eslint-plugin-react-compiler";
5
+ import pluginReactGoogleTranslate from "eslint-plugin-react-google-translate";
6
+ import { isPackageExists } from "local-pkg";
7
+ import { defineConfig as defineConfig$1 } from "eslint/config";
8
+ import js from "@eslint/js";
9
+ import tseslint from "typescript-eslint";
10
+ import pluginVue from "eslint-plugin-vue";
11
+ import globals from "globals";
12
+ import { mergeProcessors } from "eslint-merge-processors";
13
+ import processorVueBlocks from "eslint-processor-vue-blocks";
14
+ import pluginStylistic from "@stylistic/eslint-plugin";
15
+ import pluginAntfu from "eslint-plugin-antfu";
16
+ import process from "node:process";
17
+ import pluginNode from "eslint-plugin-n";
18
+ import pluginJsonc from "eslint-plugin-jsonc";
19
+ import pluginPackageJson from "eslint-plugin-package-json";
20
+ import pluginUnicorn from "eslint-plugin-unicorn";
21
+ import pluginImportX from "eslint-plugin-import-x";
22
+ import pluginUnusedImports from "eslint-plugin-unused-imports";
23
+ import pluginSimpleImportSort from "eslint-plugin-simple-import-sort";
24
+ import pluginFormat from "eslint-plugin-format";
25
+ import pluginTailwindcss from "eslint-plugin-tailwindcss";
26
+ import configUnocss from "@unocss/eslint-config/flat";
27
+ import pluginYml from "eslint-plugin-yml";
28
+ import pluginToml from "eslint-plugin-toml";
29
+ import * as parserToml from "toml-eslint-parser";
30
+ import * as pluginRegexp from "eslint-plugin-regexp";
31
+ import pluginEslintComments from "@eslint-community/eslint-plugin-eslint-comments/configs";
32
+ //#region src/consts.ts
33
+ const RULE_PREFIX = "tinywaves";
34
+ const GLOB_YML = "**/*.y?(a)ml";
35
+ const GLOB_TOML = "**/*.toml";
36
+ const GLOB_JSON = "**/*.json";
37
+ const GLOB_JSON5 = "**/*.json5";
38
+ const GLOB_JSONC = "**/*.jsonc";
39
+ const GLOB_PACKAGE_JSON = "**/package.json";
40
+ const GLOB_HTML = "**/*.htm?(l)";
41
+ const GLOB_CSS = "**/*.css";
42
+ const GLOB_POSTCSS = "**/*.{p,post}css";
43
+ const GLOB_LESS = "**/*.less";
44
+ const GLOB_SCSS = "**/*.scss";
45
+ const GLOB_GRAPHQL = "**/*.{g,graph}ql";
46
+ const GLOB_XML = "**/*.xml";
47
+ const GLOB_SVG = "**/*.svg";
48
+ const GLOB_VUE = "**/*.vue";
49
+ const GLOB_JSON_SRC = [
50
+ GLOB_JSON,
51
+ GLOB_JSON5,
52
+ GLOB_JSONC,
53
+ GLOB_PACKAGE_JSON
54
+ ];
55
+ const GLOB_TS_SRC = [
56
+ "**/*.cts",
57
+ "**/*.mts",
58
+ "**/*.ts",
59
+ "**/*.tsx"
60
+ ];
61
+ const GLOB_JS_SRC = [
62
+ "**/*.cjs",
63
+ "**/*.mjs",
64
+ "**/*.js",
65
+ "**/*.jsx"
66
+ ];
67
+ const GLOB_JSX_SRC = ["**/*.jsx", "**/*.tsx"];
68
+ const GLOB_SRC = [...GLOB_TS_SRC, ...GLOB_JS_SRC];
69
+ const GLOB_SRC_EXT = GLOB_SRC.map((item) => item.replace("**/*.", ""));
70
+ GLOB_SRC_EXT.flatMap((item) => [
71
+ `**/__tests__/**/*.${item}`,
72
+ `**/*.spec.${item}`,
73
+ `**/*.test.${item}`,
74
+ `**/*.bench.${item}`,
75
+ `**/*.benchmark.${item}`
76
+ ]);
77
+ const GLOB_EXCLUDE = [
78
+ "**/node_modules",
79
+ "**/dist",
80
+ "**/package-lock.json",
81
+ "**/yarn.lock",
82
+ "**/pnpm-lock.yaml",
83
+ "**/bun.lockb",
84
+ "**/output",
85
+ "**/coverage",
86
+ "**/temp",
87
+ "**/.temp",
88
+ "**/tmp",
89
+ "**/.tmp",
90
+ "**/.history",
91
+ "**/.vitepress/cache",
92
+ "**/.nuxt",
93
+ "**/.next",
94
+ "**/.svelte-kit",
95
+ "**/.vercel",
96
+ "**/.changeset",
97
+ "**/.idea",
98
+ "**/.cache",
99
+ "**/.output",
100
+ "**/.vite-inspect",
101
+ "**/.yarn",
102
+ "**/vite.config.*.timestamp-*",
103
+ "**/CHANGELOG*.md",
104
+ "**/*.min.*",
105
+ "**/LICENSE*",
106
+ "**/__snapshots__",
107
+ "**/auto-import?(s).d.ts",
108
+ "**/components.d.ts"
109
+ ];
110
+ //#endregion
111
+ //#region src/utils.ts
112
+ const parserPlain = {
113
+ meta: { name: "parser-plain" },
114
+ parseForESLint: (code) => ({
115
+ ast: {
116
+ body: [],
117
+ comments: [],
118
+ loc: {
119
+ end: code.length,
120
+ start: 0
121
+ },
122
+ range: [0, code.length],
123
+ tokens: [],
124
+ type: "Program"
125
+ },
126
+ scopeManager: null,
127
+ services: { isPlain: true },
128
+ visitorKeys: { Program: [] }
129
+ })
130
+ };
131
+ const mergeRule = (...rules) => {
132
+ let finalLevel;
133
+ let finalOptions = {};
134
+ for (const rule of rules) {
135
+ if (!rule) continue;
136
+ if (!Array.isArray(rule)) {
137
+ finalLevel = rule;
138
+ continue;
139
+ }
140
+ const [level, options] = rule;
141
+ finalLevel = level;
142
+ if (options && typeof options === "object") finalOptions = {
143
+ ...finalOptions,
144
+ ...options
145
+ };
146
+ }
147
+ if (Object.keys(finalOptions).length === 0) return finalLevel;
148
+ return [finalLevel, finalOptions];
149
+ };
150
+ //#endregion
151
+ //#region src/configs/react.ts
152
+ const ReactRefreshAllowConstantExportPackages = ["vite"];
153
+ const RemixPackages = [
154
+ "@remix-run/node",
155
+ "@remix-run/react",
156
+ "@remix-run/serve",
157
+ "@remix-run/dev"
158
+ ];
159
+ const ReactRouterPackages = [
160
+ "@react-router/node",
161
+ "@react-router/react",
162
+ "@react-router/serve",
163
+ "@react-router/dev"
164
+ ];
165
+ const NextJsPackages = ["next"];
166
+ const ExpoPackages = ["expo"];
167
+ function react(options = {}) {
168
+ const { language = "typescript", overrides = {
169
+ compiler: {},
170
+ core: {},
171
+ hooks: {},
172
+ refresh: {},
173
+ googleTranslate: {}
174
+ } } = options;
175
+ const config = language === "typescript" ? pluginReact.configs["recommended-type-checked"] : pluginReact.configs.recommended;
176
+ const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((i) => isPackageExists(i));
177
+ const isUsingRemix = RemixPackages.some((i) => isPackageExists(i));
178
+ const isUsingReactRouter = ReactRouterPackages.some((i) => isPackageExists(i));
179
+ const isUsingNext = NextJsPackages.some((i) => isPackageExists(i));
180
+ const isUsingExpo = ExpoPackages.some((i) => isPackageExists(i));
181
+ return [
182
+ {
183
+ ...config,
184
+ name: `${RULE_PREFIX}/react/core/shared`,
185
+ files: GLOB_SRC
186
+ },
187
+ {
188
+ name: `${RULE_PREFIX}/react/core/customize`,
189
+ files: GLOB_SRC,
190
+ rules: {
191
+ "@eslint-react/no-missing-context-display-name": "warn",
192
+ "@eslint-react/no-missing-component-display-name": "off",
193
+ "@eslint-react/dom-no-hydrate": "error",
194
+ "@eslint-react/jsx-no-useless-fragment": ["warn", {
195
+ allowEmptyFragment: true,
196
+ allowExpressions: true
197
+ }],
198
+ "@eslint-react/no-unnecessary-use-prefix": "warn",
199
+ "@eslint-react/naming-convention-context-name": "warn",
200
+ ...language === "typescript" ? { "@eslint-react/no-leaked-conditional-rendering": "warn" } : {},
201
+ ...overrides.core
202
+ }
203
+ },
204
+ ...defineConfig$1([pluginReactHooks.configs.flat["recommended-latest"]]).map((item) => ({
205
+ ...item,
206
+ name: `${RULE_PREFIX}/react/hooks/shared`,
207
+ files: GLOB_SRC
208
+ })),
209
+ {
210
+ name: `${RULE_PREFIX}/react/hooks/customize`,
211
+ files: GLOB_SRC,
212
+ rules: overrides.hooks || {}
213
+ },
214
+ {
215
+ ...pluginReactRefresh.configs.recommended,
216
+ name: `${RULE_PREFIX}/react/refresh/shared`,
217
+ files: GLOB_JSX_SRC
218
+ },
219
+ {
220
+ name: `${RULE_PREFIX}/react/refresh/customize`,
221
+ files: GLOB_JSX_SRC,
222
+ rules: {
223
+ "react-refresh/only-export-components": mergeRule(["warn", { allowConstantExport: isAllowConstantExport }], ["warn", { allowExportNames: [
224
+ ...isUsingNext ? [
225
+ "dynamic",
226
+ "dynamicParams",
227
+ "revalidate",
228
+ "fetchCache",
229
+ "runtime",
230
+ "preferredRegion",
231
+ "maxDuration",
232
+ "config",
233
+ "generateMetadata",
234
+ "generateViewport",
235
+ "experimental_ppr",
236
+ "metadata",
237
+ "viewport",
238
+ "generateImageMetadata",
239
+ "generateSitemaps",
240
+ "generateStaticParams"
241
+ ] : [],
242
+ ...isUsingRemix || isUsingReactRouter ? [
243
+ "meta",
244
+ "links",
245
+ "headers",
246
+ "loader",
247
+ "action"
248
+ ] : [],
249
+ ...isUsingExpo ? ["unstable_settings"] : []
250
+ ] }]),
251
+ ...overrides.refresh
252
+ }
253
+ },
254
+ {
255
+ ...pluginReactCompiler.configs.recommended,
256
+ name: `${RULE_PREFIX}/react/compiler/shared`,
257
+ files: GLOB_SRC
258
+ },
259
+ {
260
+ name: `${RULE_PREFIX}/react/compiler/customize`,
261
+ files: GLOB_SRC,
262
+ rules: overrides.compiler || {}
263
+ },
264
+ {
265
+ name: `${RULE_PREFIX}/react/google-translate`,
266
+ files: GLOB_JSX_SRC,
267
+ plugins: { "react-google-translate": pluginReactGoogleTranslate },
268
+ rules: {
269
+ "react-google-translate/no-conditional-text-nodes-with-siblings": "warn",
270
+ "react-google-translate/no-return-text-nodes": "warn",
271
+ ...overrides.googleTranslate
272
+ }
273
+ }
274
+ ];
275
+ }
276
+ //#endregion
277
+ //#region src/configs/vue.ts
278
+ function vue(options = {}) {
279
+ const { overrides = {} } = options;
280
+ return defineConfig$1({
281
+ ...js.configs.recommended,
282
+ name: `${RULE_PREFIX}/vue/shared/javascript`,
283
+ files: [GLOB_VUE]
284
+ }, tseslint.configs.recommended.map((item) => ({
285
+ ...item,
286
+ name: `${RULE_PREFIX}/vue/shared/typescript/${item.name?.replace("typescript-eslint/", "")}`,
287
+ files: [GLOB_VUE]
288
+ })), pluginVue.configs["flat/recommended"].map((item) => ({
289
+ ...item,
290
+ name: `${RULE_PREFIX}/vue/shared/${item.name?.replace("vue/", "")}`,
291
+ files: [GLOB_VUE]
292
+ })), {
293
+ name: `${RULE_PREFIX}/vue/customize`,
294
+ files: [GLOB_VUE],
295
+ languageOptions: {
296
+ ecmaVersion: "latest",
297
+ sourceType: "module",
298
+ globals: globals.browser,
299
+ parserOptions: { parser: tseslint.parser }
300
+ },
301
+ processor: mergeProcessors([pluginVue.processors[".vue"], processorVueBlocks({ blocks: {
302
+ styles: true,
303
+ customBlocks: true,
304
+ script: false,
305
+ template: false
306
+ } })]),
307
+ rules: overrides
308
+ });
309
+ }
310
+ //#endregion
311
+ //#region src/configs/stylistic.ts
312
+ function stylistic(options = {}) {
313
+ const { overrides = {} } = options;
314
+ const jsxIgnoreNodes = [
315
+ "TemplateLiteral *",
316
+ "TSUnionType",
317
+ "TSIntersectionType",
318
+ "TSTypeParameterInstantiation",
319
+ "FunctionExpression > .params[decorators.length > 0]",
320
+ "FunctionExpression > .params > :matches(Decorator, :not(:first-child))"
321
+ ];
322
+ const nonJsxIgnoreNodes = ["JSXOpeningElement", "JSXClosingElement"];
323
+ const basicIndentRuleOptions = {
324
+ ArrayExpression: 1,
325
+ CallExpression: { arguments: 1 },
326
+ flatTernaryExpressions: false,
327
+ FunctionDeclaration: {
328
+ body: 1,
329
+ parameters: 1
330
+ },
331
+ FunctionExpression: {
332
+ body: 1,
333
+ parameters: 1
334
+ },
335
+ ignoreComments: false,
336
+ ImportDeclaration: 1,
337
+ MemberExpression: 1,
338
+ ObjectExpression: 1,
339
+ offsetTernaryExpressions: true,
340
+ outerIIFEBody: 1,
341
+ SwitchCase: 1,
342
+ VariableDeclarator: 1
343
+ };
344
+ return [
345
+ {
346
+ ...pluginStylistic.configs.customize({
347
+ arrowParens: true,
348
+ semi: true,
349
+ braceStyle: "1tbs"
350
+ }),
351
+ name: `${RULE_PREFIX}/stylistic/shared`,
352
+ files: [
353
+ ...GLOB_SRC,
354
+ ...GLOB_JSON_SRC,
355
+ GLOB_VUE
356
+ ]
357
+ },
358
+ {
359
+ name: `${RULE_PREFIX}/stylistic/customize`,
360
+ files: [
361
+ ...GLOB_SRC,
362
+ ...GLOB_JSON_SRC,
363
+ GLOB_VUE
364
+ ],
365
+ plugins: {
366
+ stylistic: pluginStylistic,
367
+ antfu: pluginAntfu
368
+ },
369
+ rules: {
370
+ "curly": ["error", "all"],
371
+ "object-shorthand": "error",
372
+ "prefer-destructuring": [
373
+ "error",
374
+ {
375
+ VariableDeclarator: {
376
+ array: false,
377
+ object: true
378
+ },
379
+ AssignmentExpression: {
380
+ array: false,
381
+ object: false
382
+ }
383
+ },
384
+ { enforceForRenamedProperties: false }
385
+ ],
386
+ "prefer-template": "error",
387
+ "stylistic/array-bracket-newline": ["error", { multiline: true }],
388
+ "stylistic/array-element-newline": ["error", "consistent"],
389
+ "stylistic/brace-style": [
390
+ "error",
391
+ "1tbs",
392
+ { allowSingleLine: false }
393
+ ],
394
+ "stylistic/function-call-spacing": ["error", "never"],
395
+ "stylistic/function-paren-newline": "off",
396
+ "stylistic/indent": [
397
+ "error",
398
+ 2,
399
+ {
400
+ ...basicIndentRuleOptions,
401
+ ignoredNodes: [...jsxIgnoreNodes, ...nonJsxIgnoreNodes]
402
+ }
403
+ ],
404
+ "stylistic/key-spacing": ["error", {
405
+ beforeColon: false,
406
+ afterColon: true,
407
+ mode: "strict"
408
+ }],
409
+ "stylistic/keyword-spacing": ["error", {
410
+ before: true,
411
+ after: true
412
+ }],
413
+ "stylistic/line-comment-position": "off",
414
+ "stylistic/linebreak-style": ["error", "unix"],
415
+ "stylistic/lines-around-comment": "off",
416
+ "stylistic/new-parens": ["error", "always"],
417
+ "stylistic/no-confusing-arrow": ["error", {
418
+ allowParens: true,
419
+ onlyOneSimpleParam: true
420
+ }],
421
+ "stylistic/no-extra-semi": "error",
422
+ "stylistic/object-property-newline": ["error", { allowAllPropertiesOnSameLine: true }],
423
+ "stylistic/space-before-function-paren": ["error", {
424
+ named: "never",
425
+ anonymous: "always",
426
+ asyncArrow: "always",
427
+ catch: "always"
428
+ }],
429
+ "stylistic/switch-colon-spacing": ["error", {
430
+ after: true,
431
+ before: false
432
+ }],
433
+ "stylistic/type-annotation-spacing": "error",
434
+ "stylistic/wrap-regex": "error",
435
+ "stylistic/quotes": [
436
+ "error",
437
+ "single",
438
+ {
439
+ allowTemplateLiterals: true,
440
+ avoidEscape: true
441
+ }
442
+ ],
443
+ "stylistic/no-tabs": "off",
444
+ "antfu/consistent-chaining": "error",
445
+ "antfu/consistent-list-newline": "error",
446
+ "antfu/top-level-function": "off",
447
+ "antfu/curly": "off",
448
+ ...overrides
449
+ }
450
+ },
451
+ {
452
+ name: `${RULE_PREFIX}/stylistic/customize/jsx`,
453
+ files: [...GLOB_JSX_SRC, GLOB_VUE],
454
+ plugins: { stylistic: pluginStylistic },
455
+ rules: {
456
+ "stylistic/indent": [
457
+ "error",
458
+ 2,
459
+ {
460
+ ...basicIndentRuleOptions,
461
+ ignoredNodes: jsxIgnoreNodes
462
+ }
463
+ ],
464
+ "stylistic/jsx-closing-bracket-location": ["error", {
465
+ nonEmpty: "tag-aligned",
466
+ selfClosing: "tag-aligned"
467
+ }],
468
+ "stylistic/jsx-closing-tag-location": ["error", "tag-aligned"],
469
+ "stylistic/jsx-curly-brace-presence": ["error", {
470
+ props: "never",
471
+ children: "never",
472
+ propElementValues: "always"
473
+ }],
474
+ "stylistic/jsx-curly-newline": ["error", {
475
+ singleline: "consistent",
476
+ multiline: "consistent"
477
+ }],
478
+ "stylistic/jsx-curly-spacing": ["error", {
479
+ when: "never",
480
+ attributes: { when: "never" },
481
+ children: { when: "never" }
482
+ }],
483
+ "stylistic/jsx-first-prop-new-line": ["error", "multiline"],
484
+ "stylistic/jsx-one-expression-per-line": ["error", { allow: "non-jsx" }],
485
+ "stylistic/jsx-pascal-case": ["error", {
486
+ allowAllCaps: false,
487
+ allowLeadingUnderscore: false,
488
+ allowNamespace: true
489
+ }],
490
+ "stylistic/jsx-props-no-multi-spaces": "error",
491
+ "stylistic/jsx-quotes": ["error", "prefer-double"],
492
+ "stylistic/jsx-self-closing-comp": ["error", {
493
+ component: true,
494
+ html: true
495
+ }],
496
+ "stylistic/jsx-sort-props": "off",
497
+ "stylistic/jsx-indent-props": "off",
498
+ ...overrides
499
+ }
500
+ }
501
+ ];
502
+ }
503
+ //#endregion
504
+ //#region src/configs/typescript.ts
505
+ function typescript(options = {}) {
506
+ const { overrides = {}, typeSafe = false, strict = false } = options;
507
+ return [...defineConfig$1(tseslint.configs.base, tseslint.configs.recommendedTypeChecked, tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked).map((item) => ({
508
+ ...item,
509
+ name: `${RULE_PREFIX}/typescript/shared/${item.name?.replace("typescript-eslint/", "")}`,
510
+ files: GLOB_TS_SRC
511
+ })), {
512
+ name: `${RULE_PREFIX}/typescript/customize`,
513
+ files: GLOB_TS_SRC,
514
+ languageOptions: {
515
+ parserOptions: {
516
+ projectService: true,
517
+ tsconfigRootDir: process.cwd()
518
+ },
519
+ sourceType: "module"
520
+ },
521
+ rules: {
522
+ "@typescript-eslint/consistent-type-imports": ["error", { disallowTypeAnnotations: false }],
523
+ "@typescript-eslint/no-import-type-side-effects": "error",
524
+ "@typescript-eslint/method-signature-style": ["error", "property"],
525
+ "no-unused-expressions": "off",
526
+ "@typescript-eslint/no-unused-expressions": ["error", {
527
+ allowShortCircuit: true,
528
+ allowTernary: true
529
+ }],
530
+ "@typescript-eslint/no-dynamic-delete": "off",
531
+ "@typescript-eslint/no-empty-object-type": ["error", {
532
+ allowInterfaces: "with-single-extends",
533
+ allowObjectTypes: "never",
534
+ allowWithName: "Props$"
535
+ }],
536
+ "@typescript-eslint/no-non-null-assertion": "off",
537
+ "@typescript-eslint/ban-ts-comment": "off",
538
+ "@typescript-eslint/no-explicit-any": "off",
539
+ "@typescript-eslint/no-non-null-asserted-optional-chain": "warn",
540
+ "@typescript-eslint/await-thenable": "error",
541
+ "@typescript-eslint/no-floating-promises": "error",
542
+ "@typescript-eslint/consistent-type-exports": "error",
543
+ "@typescript-eslint/no-misused-promises": ["error", { checksVoidReturn: {
544
+ arguments: false,
545
+ attributes: false
546
+ } }],
547
+ "@typescript-eslint/restrict-template-expressions": ["error", {}],
548
+ "@typescript-eslint/no-deprecated": "warn",
549
+ "@typescript-eslint/no-empty-function": "off",
550
+ "@typescript-eslint/consistent-type-definitions": "off",
551
+ "@typescript-eslint/array-type": ["error", { default: "array-simple" }],
552
+ "@typescript-eslint/prefer-nullish-coalescing": "off",
553
+ "@typescript-eslint/no-confusing-void-expression": ["error", { ignoreArrowShorthand: true }],
554
+ ...typeSafe ? {} : {
555
+ "@typescript-eslint/no-unsafe-assignment": "off",
556
+ "@typescript-eslint/no-unsafe-member-access": "off",
557
+ "@typescript-eslint/no-unsafe-call": "off",
558
+ "@typescript-eslint/no-unsafe-return": "off",
559
+ "@typescript-eslint/no-unsafe-argument": "off"
560
+ },
561
+ ...strict ? {} : { "@typescript-eslint/no-extraneous-class": "off" },
562
+ ...overrides
563
+ }
564
+ }];
565
+ }
566
+ //#endregion
567
+ //#region src/configs/javascript.ts
568
+ function javascript(options = {}) {
569
+ const { overrides = {} } = options;
570
+ return [{
571
+ name: `${RULE_PREFIX}/javascript/shared`,
572
+ files: GLOB_SRC,
573
+ languageOptions: {
574
+ ecmaVersion: 2022,
575
+ globals: {
576
+ ...globals.browser,
577
+ ...globals.es2021,
578
+ ...globals.node,
579
+ document: "readonly",
580
+ navigator: "readonly",
581
+ window: "readonly"
582
+ },
583
+ parserOptions: {
584
+ ecmaFeatures: { jsx: true },
585
+ ecmaVersion: 2022,
586
+ sourceType: "module"
587
+ },
588
+ sourceType: "module"
589
+ },
590
+ linterOptions: { reportUnusedDisableDirectives: true },
591
+ rules: js.configs.recommended.rules
592
+ }, {
593
+ name: `${RULE_PREFIX}/javascript/customize`,
594
+ files: GLOB_SRC,
595
+ plugins: { antfu: pluginAntfu },
596
+ rules: {
597
+ "arrow-body-style": ["error", "as-needed"],
598
+ "func-style": [
599
+ "warn",
600
+ "declaration",
601
+ { allowArrowFunctions: true }
602
+ ],
603
+ "no-empty-function": "off",
604
+ "prefer-destructuring": "off",
605
+ "capitalized-comments": "off",
606
+ "id-length": "off",
607
+ "accessor-pairs": ["error", {
608
+ enforceForClassMembers: true,
609
+ setWithoutGet: true
610
+ }],
611
+ "antfu/no-top-level-await": "error",
612
+ "array-callback-return": "error",
613
+ "block-scoped-var": "error",
614
+ "constructor-super": "error",
615
+ "default-case-last": "error",
616
+ "dot-notation": ["error", { allowKeywords: true }],
617
+ "eqeqeq": ["error", "smart"],
618
+ "new-cap": ["error", {
619
+ capIsNew: false,
620
+ newIsCap: true,
621
+ properties: true
622
+ }],
623
+ "no-alert": "error",
624
+ "no-array-constructor": "error",
625
+ "no-async-promise-executor": "error",
626
+ "no-caller": "error",
627
+ "no-case-declarations": "error",
628
+ "no-class-assign": "error",
629
+ "no-compare-neg-zero": "error",
630
+ "no-cond-assign": ["error", "always"],
631
+ "no-console": ["error", { allow: [
632
+ "warn",
633
+ "error",
634
+ "info"
635
+ ] }],
636
+ "no-const-assign": "error",
637
+ "no-control-regex": "error",
638
+ "no-debugger": "error",
639
+ "no-delete-var": "error",
640
+ "no-dupe-args": "error",
641
+ "no-dupe-class-members": "error",
642
+ "no-dupe-keys": "error",
643
+ "no-duplicate-case": "error",
644
+ "no-empty": ["error", { allowEmptyCatch: true }],
645
+ "no-empty-character-class": "error",
646
+ "no-empty-pattern": "error",
647
+ "no-eval": "error",
648
+ "no-ex-assign": "error",
649
+ "no-extend-native": "error",
650
+ "no-extra-bind": "error",
651
+ "no-extra-boolean-cast": "error",
652
+ "no-fallthrough": "error",
653
+ "no-func-assign": "error",
654
+ "no-global-assign": "error",
655
+ "no-implied-eval": "error",
656
+ "no-import-assign": "error",
657
+ "no-invalid-regexp": "error",
658
+ "no-irregular-whitespace": "error",
659
+ "no-iterator": "error",
660
+ "no-labels": ["error", {
661
+ allowLoop: false,
662
+ allowSwitch: false
663
+ }],
664
+ "no-lone-blocks": "error",
665
+ "no-loss-of-precision": "error",
666
+ "no-misleading-character-class": "error",
667
+ "no-multi-str": "error",
668
+ "no-new": "error",
669
+ "no-new-func": "error",
670
+ "no-new-native-nonconstructor": "error",
671
+ "no-new-wrappers": "error",
672
+ "no-obj-calls": "error",
673
+ "no-octal": "error",
674
+ "no-octal-escape": "error",
675
+ "no-param-reassign": "warn",
676
+ "no-proto": "error",
677
+ "no-prototype-builtins": "error",
678
+ "no-redeclare": ["error", { builtinGlobals: false }],
679
+ "no-regex-spaces": "error",
680
+ "no-restricted-globals": [
681
+ "error",
682
+ {
683
+ message: "Use `globalThis` instead.",
684
+ name: "global"
685
+ },
686
+ {
687
+ message: "Use `globalThis` instead.",
688
+ name: "self"
689
+ }
690
+ ],
691
+ "no-restricted-properties": [
692
+ "error",
693
+ {
694
+ message: "Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.",
695
+ property: "__proto__"
696
+ },
697
+ {
698
+ message: "Use `Object.defineProperty` instead.",
699
+ property: "__defineGetter__"
700
+ },
701
+ {
702
+ message: "Use `Object.defineProperty` instead.",
703
+ property: "__defineSetter__"
704
+ },
705
+ {
706
+ message: "Use `Object.getOwnPropertyDescriptor` instead.",
707
+ property: "__lookupGetter__"
708
+ },
709
+ {
710
+ message: "Use `Object.getOwnPropertyDescriptor` instead.",
711
+ property: "__lookupSetter__"
712
+ }
713
+ ],
714
+ "no-restricted-syntax": [
715
+ "error",
716
+ "TSEnumDeclaration[const=true]",
717
+ "TSExportAssignment"
718
+ ],
719
+ "no-self-assign": ["error", { props: true }],
720
+ "no-self-compare": "error",
721
+ "no-sequences": "error",
722
+ "no-shadow-restricted-names": "error",
723
+ "no-sparse-arrays": "error",
724
+ "no-template-curly-in-string": "error",
725
+ "no-this-before-super": "error",
726
+ "no-throw-literal": "error",
727
+ "no-undef": "error",
728
+ "no-undef-init": "error",
729
+ "no-unexpected-multiline": "error",
730
+ "no-unmodified-loop-condition": "error",
731
+ "no-unneeded-ternary": ["error", { defaultAssignment: false }],
732
+ "no-unreachable": "error",
733
+ "no-unreachable-loop": "error",
734
+ "no-unsafe-finally": "error",
735
+ "no-unsafe-negation": "error",
736
+ "no-unused-expressions": ["error", {
737
+ allowShortCircuit: true,
738
+ allowTaggedTemplates: true,
739
+ allowTernary: true
740
+ }],
741
+ "no-unused-vars": ["error", {
742
+ args: "none",
743
+ caughtErrors: "none",
744
+ ignoreRestSiblings: true,
745
+ vars: "all"
746
+ }],
747
+ "no-use-before-define": ["error", {
748
+ classes: false,
749
+ functions: false,
750
+ variables: true
751
+ }],
752
+ "no-useless-backreference": "error",
753
+ "no-useless-call": "error",
754
+ "no-useless-catch": "error",
755
+ "no-useless-computed-key": "error",
756
+ "no-useless-constructor": "error",
757
+ "no-useless-rename": "error",
758
+ "no-useless-return": "error",
759
+ "no-var": "error",
760
+ "no-with": "error",
761
+ "object-shorthand": [
762
+ "error",
763
+ "always",
764
+ {
765
+ avoidQuotes: true,
766
+ ignoreConstructors: false
767
+ }
768
+ ],
769
+ "one-var": ["error", { initialized: "never" }],
770
+ "prefer-arrow-callback": ["error", {
771
+ allowNamedFunctions: false,
772
+ allowUnboundThis: true
773
+ }],
774
+ "prefer-const": ["error", {
775
+ destructuring: "all",
776
+ ignoreReadBeforeAssign: true
777
+ }],
778
+ "prefer-exponentiation-operator": "error",
779
+ "prefer-promise-reject-errors": "error",
780
+ "prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
781
+ "prefer-rest-params": "error",
782
+ "prefer-spread": "error",
783
+ "prefer-template": "error",
784
+ "symbol-description": "error",
785
+ "unicode-bom": ["error", "never"],
786
+ "use-isnan": ["error", {
787
+ enforceForIndexOf: true,
788
+ enforceForSwitchCase: true
789
+ }],
790
+ "valid-typeof": ["error", { requireStringLiterals: true }],
791
+ "vars-on-top": "error",
792
+ "yoda": ["error", "never"],
793
+ ...overrides
794
+ }
795
+ }];
796
+ }
797
+ //#endregion
798
+ //#region src/configs/node.ts
799
+ function node(options = {}) {
800
+ const { overrides = {} } = options;
801
+ return [{
802
+ ...pluginNode.configs["flat/recommended"],
803
+ name: `${RULE_PREFIX}/node/shared`,
804
+ files: GLOB_SRC
805
+ }, {
806
+ name: `${RULE_PREFIX}/node/customize`,
807
+ files: GLOB_SRC,
808
+ rules: {
809
+ "n/handle-callback-err": ["error", "^(err|error)$"],
810
+ "n/no-new-require": "error",
811
+ "n/no-path-concat": "error",
812
+ "n/prefer-global/buffer": ["error", "never"],
813
+ "n/prefer-global/process": ["error", "never"],
814
+ "n/no-missing-import": "off",
815
+ ...overrides
816
+ }
817
+ }];
818
+ }
819
+ //#endregion
820
+ //#region src/configs/json.ts
821
+ function json(options = {}) {
822
+ const { overrides = {
823
+ core: {},
824
+ packageJson: {}
825
+ }, indent = 2, packageJsonRequireType = true } = options;
826
+ return [
827
+ ...pluginJsonc.configs["recommended-with-json"].map((item) => ({
828
+ ...item,
829
+ name: `${RULE_PREFIX}/json/shared/json`,
830
+ files: [GLOB_JSON]
831
+ })),
832
+ ...pluginJsonc.configs["recommended-with-jsonc"].map((item) => ({
833
+ ...item,
834
+ name: `${RULE_PREFIX}/json/shared/jsonc`,
835
+ files: [GLOB_JSONC]
836
+ })),
837
+ ...pluginJsonc.configs["recommended-with-json5"].map((item) => ({
838
+ ...item,
839
+ name: `${RULE_PREFIX}/json/shared/json5`,
840
+ files: [GLOB_JSON5]
841
+ })),
842
+ {
843
+ name: `${RULE_PREFIX}/json/customize`,
844
+ files: [
845
+ GLOB_JSON,
846
+ GLOB_JSON5,
847
+ GLOB_JSONC
848
+ ],
849
+ rules: {
850
+ "jsonc/array-bracket-spacing": ["error", "never"],
851
+ "jsonc/comma-dangle": ["error", "never"],
852
+ "jsonc/comma-style": ["error", "last"],
853
+ "jsonc/indent": ["error", indent],
854
+ "jsonc/no-comments": "off",
855
+ "jsonc/key-spacing": ["error", {
856
+ afterColon: true,
857
+ beforeColon: false
858
+ }],
859
+ "jsonc/object-curly-newline": ["error", {
860
+ consistent: true,
861
+ multiline: true
862
+ }],
863
+ "jsonc/object-curly-spacing": ["error", "always"],
864
+ "jsonc/quote-props": "error",
865
+ "jsonc/quotes": "error",
866
+ "jsonc/no-bigint-literals": "error",
867
+ "jsonc/object-property-newline": ["error", { allowMultiplePropertiesPerLine: true }],
868
+ "jsonc/no-binary-expression": "error",
869
+ "jsonc/no-binary-numeric-literals": "error",
870
+ "jsonc/no-dupe-keys": "error",
871
+ "jsonc/no-escape-sequence-in-identifier": "error",
872
+ "jsonc/no-floating-decimal": "error",
873
+ "jsonc/no-hexadecimal-numeric-literals": "error",
874
+ "jsonc/no-infinity": "error",
875
+ "jsonc/no-multi-str": "error",
876
+ "jsonc/no-nan": "error",
877
+ "jsonc/no-number-props": "error",
878
+ "jsonc/no-numeric-separators": "error",
879
+ "jsonc/no-octal": "error",
880
+ "jsonc/no-octal-escape": "error",
881
+ "jsonc/no-octal-numeric-literals": "error",
882
+ "jsonc/no-parenthesized": "error",
883
+ "jsonc/no-plus-sign": "error",
884
+ "jsonc/no-regexp-literals": "error",
885
+ "jsonc/no-sparse-arrays": "error",
886
+ "jsonc/no-template-literals": "error",
887
+ "jsonc/no-undefined-value": "error",
888
+ "jsonc/no-unicode-codepoint-escapes": "error",
889
+ "jsonc/no-useless-escape": "error",
890
+ "jsonc/space-unary-ops": "error",
891
+ "jsonc/valid-json-number": "error",
892
+ "jsonc/vue-custom-block/no-parsing-error": "error",
893
+ ...overrides.core
894
+ }
895
+ },
896
+ {
897
+ ...pluginPackageJson.configs.recommended,
898
+ name: `${RULE_PREFIX}/json/shared/package.json`,
899
+ files: [GLOB_PACKAGE_JSON]
900
+ },
901
+ {
902
+ name: `${RULE_PREFIX}/json/customize/package.json`,
903
+ files: [GLOB_PACKAGE_JSON],
904
+ rules: {
905
+ "package-json/order-properties": ["error", { order: [
906
+ "publisher",
907
+ "name",
908
+ "displayName",
909
+ "type",
910
+ "version",
911
+ "private",
912
+ "packageManager",
913
+ "description",
914
+ "author",
915
+ "contributors",
916
+ "license",
917
+ "funding",
918
+ "homepage",
919
+ "repository",
920
+ "bugs",
921
+ "keywords",
922
+ "categories",
923
+ "sideEffects",
924
+ "exports",
925
+ "main",
926
+ "module",
927
+ "unpkg",
928
+ "jsdelivr",
929
+ "types",
930
+ "typesVersions",
931
+ "bin",
932
+ "icon",
933
+ "files",
934
+ "engines",
935
+ "activationEvents",
936
+ "contributes",
937
+ "scripts",
938
+ "release-it",
939
+ "peerDependencies",
940
+ "peerDependenciesMeta",
941
+ "dependencies",
942
+ "optionalDependencies",
943
+ "devDependencies",
944
+ "pnpm",
945
+ "overrides",
946
+ "resolutions",
947
+ "husky",
948
+ "simple-git-hooks",
949
+ "lint-staged",
950
+ "eslintConfig"
951
+ ] }],
952
+ "package-json/require-type": packageJsonRequireType ? "error" : "off",
953
+ ...overrides.packageJson
954
+ }
955
+ }
956
+ ];
957
+ }
958
+ //#endregion
959
+ //#region src/configs/unicorn.ts
960
+ function unicorn(options = {}) {
961
+ const { overrides = {} } = options;
962
+ return [{
963
+ ...pluginUnicorn.configs.recommended,
964
+ name: `${RULE_PREFIX}/unicorn/shared`,
965
+ files: GLOB_SRC
966
+ }, {
967
+ name: `${RULE_PREFIX}/unicorn/customize`,
968
+ files: GLOB_SRC,
969
+ rules: {
970
+ "unicorn/consistent-destructuring": "off",
971
+ "unicorn/prevent-abbreviations": "off",
972
+ "unicorn/prefer-top-level-await": "off",
973
+ "unicorn/no-unreadable-array-destructuring": "off",
974
+ "unicorn/no-null": "off",
975
+ "unicorn/consistent-empty-array-spread": "error",
976
+ "unicorn/error-message": "error",
977
+ "unicorn/escape-case": "error",
978
+ "unicorn/no-hex-escape": "error",
979
+ "unicorn/new-for-builtins": "error",
980
+ "unicorn/no-instanceof-builtins": "error",
981
+ "unicorn/no-new-array": "error",
982
+ "unicorn/no-new-buffer": "error",
983
+ "unicorn/number-literal-case": "error",
984
+ "unicorn/prefer-dom-node-text-content": "error",
985
+ "unicorn/prefer-includes": "error",
986
+ "unicorn/prefer-node-protocol": "error",
987
+ "unicorn/prefer-query-selector": "off",
988
+ "unicorn/prefer-number-properties": "error",
989
+ "unicorn/prefer-string-starts-ends-with": "error",
990
+ "unicorn/prefer-type-error": "error",
991
+ "unicorn/throw-new-error": "error",
992
+ ...overrides
993
+ }
994
+ }];
995
+ }
996
+ //#endregion
997
+ //#region src/configs/imports.ts
998
+ function imports(options = {}) {
999
+ const { overrides = {}, closeOrder = true } = options;
1000
+ return [{
1001
+ name: `${RULE_PREFIX}/imports/customize`,
1002
+ files: GLOB_SRC,
1003
+ plugins: {
1004
+ "antfu": pluginAntfu,
1005
+ "import-x": pluginImportX,
1006
+ "unused-imports": pluginUnusedImports,
1007
+ "simple-import-sort": pluginSimpleImportSort
1008
+ },
1009
+ rules: {
1010
+ "sort-imports": "off",
1011
+ "no-unused-vars": "off",
1012
+ "no-duplicate-imports": "off",
1013
+ "@typescript-eslint/no-unused-vars": "off",
1014
+ "antfu/import-dedupe": "error",
1015
+ "antfu/no-import-dist": "error",
1016
+ "antfu/no-import-node-modules-by-path": "error",
1017
+ "import-x/consistent-type-specifier-style": ["error", "prefer-top-level"],
1018
+ "import-x/first": "error",
1019
+ "import-x/no-duplicates": "error",
1020
+ "import-x/no-mutable-exports": "error",
1021
+ "import-x/no-named-default": "error",
1022
+ "import-x/no-self-import": "error",
1023
+ "import-x/no-webpack-loader-syntax": "error",
1024
+ "import-x/order": "off",
1025
+ "import-x/newline-after-import": ["error", { count: 1 }],
1026
+ "unused-imports/no-unused-imports": "warn",
1027
+ "unused-imports/no-unused-vars": ["error", {
1028
+ args: "after-used",
1029
+ argsIgnorePattern: "^_",
1030
+ ignoreRestSiblings: true,
1031
+ vars: "all",
1032
+ varsIgnorePattern: "^_"
1033
+ }],
1034
+ "simple-import-sort/imports": closeOrder ? "off" : "error",
1035
+ "simple-import-sort/exports": closeOrder ? "off" : "error",
1036
+ ...overrides
1037
+ }
1038
+ }];
1039
+ }
1040
+ //#endregion
1041
+ //#region src/configs/format.ts
1042
+ const mergePrettierOptions = (options, overrides) => ({
1043
+ ...options,
1044
+ ...overrides,
1045
+ plugins: [...overrides.plugins || []]
1046
+ });
1047
+ function format(options = {}) {
1048
+ const { enable = {
1049
+ html: true,
1050
+ css: true,
1051
+ graphql: true,
1052
+ xml: true,
1053
+ svg: true
1054
+ }, customPrettierOptions = {} } = options;
1055
+ const configs = [];
1056
+ if (!enable) return configs;
1057
+ const prettierOptions = Object.assign({
1058
+ printWidth: 120,
1059
+ tabWidth: 2,
1060
+ semi: true,
1061
+ singleQuote: true,
1062
+ quoteProps: "consistent",
1063
+ jsxSingleQuote: false,
1064
+ trailingComma: "all",
1065
+ bracketSpacing: true,
1066
+ bracketSameLine: false,
1067
+ arrowParens: "always",
1068
+ useTabs: false,
1069
+ endOfLine: "lf",
1070
+ singleAttributePerLine: false
1071
+ }, customPrettierOptions);
1072
+ const prettierXmlOptions = {
1073
+ xmlQuoteAttributes: "double",
1074
+ xmlSelfClosingSpace: true,
1075
+ xmlSortAttributesByKey: false,
1076
+ xmlWhitespaceSensitivity: "ignore"
1077
+ };
1078
+ configs.push({
1079
+ name: `${RULE_PREFIX}/format`,
1080
+ plugins: { format: pluginFormat }
1081
+ });
1082
+ if (enable.html) configs.push({
1083
+ name: `${RULE_PREFIX}/format/html`,
1084
+ files: [GLOB_HTML],
1085
+ languageOptions: { parser: parserPlain },
1086
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "html" })] }
1087
+ });
1088
+ if (enable.css) configs.push({
1089
+ name: `${RULE_PREFIX}/format/css`,
1090
+ files: [GLOB_CSS, GLOB_POSTCSS],
1091
+ languageOptions: { parser: parserPlain },
1092
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "css" })] }
1093
+ }, {
1094
+ name: `${RULE_PREFIX}/format/scss`,
1095
+ files: [GLOB_SCSS],
1096
+ languageOptions: { parser: parserPlain },
1097
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "scss" })] }
1098
+ }, {
1099
+ name: `${RULE_PREFIX}/format/less`,
1100
+ files: [GLOB_LESS],
1101
+ languageOptions: { parser: parserPlain },
1102
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "less" })] }
1103
+ });
1104
+ if (enable.graphql) configs.push({
1105
+ name: `${RULE_PREFIX}/format/graphql`,
1106
+ files: [GLOB_GRAPHQL],
1107
+ languageOptions: { parser: parserPlain },
1108
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "graphql" })] }
1109
+ });
1110
+ if (enable.xml) configs.push({
1111
+ name: `${RULE_PREFIX}/format/xml`,
1112
+ files: [GLOB_XML],
1113
+ languageOptions: { parser: parserPlain },
1114
+ rules: { "format/prettier": ["error", mergePrettierOptions({
1115
+ ...prettierXmlOptions,
1116
+ ...prettierOptions
1117
+ }, {
1118
+ parser: "xml",
1119
+ plugins: ["@prettier/plugin-xml"]
1120
+ })] }
1121
+ });
1122
+ if (enable.svg) configs.push({
1123
+ name: `${RULE_PREFIX}/format/svg`,
1124
+ files: [GLOB_SVG],
1125
+ languageOptions: { parser: parserPlain },
1126
+ rules: { "format/prettier": ["error", mergePrettierOptions({
1127
+ ...prettierXmlOptions,
1128
+ ...prettierOptions
1129
+ }, {
1130
+ parser: "xml",
1131
+ plugins: ["@prettier/plugin-xml"]
1132
+ })] }
1133
+ });
1134
+ return configs;
1135
+ }
1136
+ //#endregion
1137
+ //#region src/configs/tailwindcss.ts
1138
+ function tailwindcss(options = {}) {
1139
+ const { overrides = {} } = options;
1140
+ return isPackageExists("tailwindcss") ? [...pluginTailwindcss.configs["flat/recommended"].map((item) => ({
1141
+ ...item,
1142
+ name: `${RULE_PREFIX}/tailwindcss/shared/${item.name?.replace("tailwindcss:", "")}`,
1143
+ files: GLOB_SRC
1144
+ })), {
1145
+ name: `${RULE_PREFIX}/tailwindcss/customize`,
1146
+ files: GLOB_SRC,
1147
+ rules: {
1148
+ "tailwindcss/no-custom-classname": "off",
1149
+ ...overrides
1150
+ }
1151
+ }] : [];
1152
+ }
1153
+ //#endregion
1154
+ //#region src/configs/unocss.ts
1155
+ function unocss(options = {}) {
1156
+ const { overrides = {} } = options;
1157
+ if (!isPackageExists("unocss")) return [];
1158
+ return [{
1159
+ ...configUnocss,
1160
+ name: `${RULE_PREFIX}/unocss/shared`,
1161
+ files: GLOB_SRC
1162
+ }, {
1163
+ name: `${RULE_PREFIX}/unocss/customize`,
1164
+ files: GLOB_SRC,
1165
+ rules: overrides
1166
+ }];
1167
+ }
1168
+ //#endregion
1169
+ //#region src/configs/yml.ts
1170
+ function yml(options = {}) {
1171
+ const { overrides = {}, indent = 2, quotes = "single" } = options;
1172
+ return [
1173
+ ...pluginYml.configs.recommended.map((item) => ({
1174
+ ...item,
1175
+ name: `${RULE_PREFIX}/yml/shared`,
1176
+ files: [GLOB_YML]
1177
+ })),
1178
+ {
1179
+ name: `${RULE_PREFIX}/yml/customize`,
1180
+ files: [GLOB_YML],
1181
+ rules: {
1182
+ "yml/block-mapping": "error",
1183
+ "yml/block-sequence": "error",
1184
+ "yml/no-empty-key": "error",
1185
+ "yml/no-empty-sequence-entry": "error",
1186
+ "yml/no-irregular-whitespace": "error",
1187
+ "yml/plain-scalar": "error",
1188
+ "yml/block-mapping-question-indicator-newline": "error",
1189
+ "yml/block-sequence-hyphen-indicator-newline": "error",
1190
+ "yml/flow-mapping-curly-newline": "error",
1191
+ "yml/flow-mapping-curly-spacing": "error",
1192
+ "yml/flow-sequence-bracket-newline": "error",
1193
+ "yml/flow-sequence-bracket-spacing": "error",
1194
+ "yml/indent": ["error", indent],
1195
+ "yml/key-spacing": "error",
1196
+ "yml/no-tab-indent": "error",
1197
+ "yml/quotes": ["error", {
1198
+ avoidEscape: true,
1199
+ prefer: quotes
1200
+ }],
1201
+ "yml/spaced-comment": "error",
1202
+ ...overrides
1203
+ }
1204
+ },
1205
+ {
1206
+ name: `${RULE_PREFIX}/yml/customize/pnpm-workspace.yaml`,
1207
+ files: ["pnpm-workspace.yaml"],
1208
+ rules: { "yml/sort-keys": [
1209
+ "error",
1210
+ {
1211
+ order: [
1212
+ "packages",
1213
+ "overrides",
1214
+ "patchedDependencies",
1215
+ "hoistPattern",
1216
+ "catalog",
1217
+ "catalogs",
1218
+ "allowedDeprecatedVersions",
1219
+ "allowNonAppliedPatches",
1220
+ "configDependencies",
1221
+ "ignoredBuiltDependencies",
1222
+ "ignoredOptionalDependencies",
1223
+ "neverBuiltDependencies",
1224
+ "onlyBuiltDependencies",
1225
+ "onlyBuiltDependenciesFile",
1226
+ "packageExtensions",
1227
+ "peerDependencyRules",
1228
+ "supportedArchitectures"
1229
+ ],
1230
+ pathPattern: "^$"
1231
+ },
1232
+ {
1233
+ order: { type: "asc" },
1234
+ pathPattern: ".*"
1235
+ }
1236
+ ] }
1237
+ }
1238
+ ];
1239
+ }
1240
+ //#endregion
1241
+ //#region src/configs/toml.ts
1242
+ function toml(options = {}) {
1243
+ const { overrides = {}, indent = 2 } = options;
1244
+ return [...pluginToml.configs.recommended.map((item) => ({
1245
+ ...item,
1246
+ name: `${RULE_PREFIX}/toml/shared`,
1247
+ files: [GLOB_TOML]
1248
+ })), {
1249
+ name: `${RULE_PREFIX}/toml/customize`,
1250
+ files: [GLOB_TOML],
1251
+ languageOptions: { parser: parserToml },
1252
+ rules: {
1253
+ "toml/comma-style": "error",
1254
+ "toml/keys-order": "error",
1255
+ "toml/no-space-dots": "error",
1256
+ "toml/no-unreadable-number-separator": "error",
1257
+ "toml/precision-of-fractional-seconds": "error",
1258
+ "toml/precision-of-integer": "error",
1259
+ "toml/tables-order": "error",
1260
+ "toml/array-bracket-newline": "error",
1261
+ "toml/array-bracket-spacing": "error",
1262
+ "toml/array-element-newline": "error",
1263
+ "toml/indent": ["error", indent],
1264
+ "toml/inline-table-curly-spacing": "error",
1265
+ "toml/key-spacing": "error",
1266
+ "toml/padding-line-between-pairs": "error",
1267
+ "toml/padding-line-between-tables": "error",
1268
+ "toml/quoted-keys": "error",
1269
+ "toml/spaced-comment": "error",
1270
+ "toml/table-bracket-spacing": "error",
1271
+ ...overrides
1272
+ }
1273
+ }];
1274
+ }
1275
+ //#endregion
1276
+ //#region src/configs/regexp.ts
1277
+ function regexp(options = {}) {
1278
+ const { overrides = {} } = options;
1279
+ return [{
1280
+ ...pluginRegexp.configs.recommended,
1281
+ name: `${RULE_PREFIX}/regexp/shared`,
1282
+ files: GLOB_SRC
1283
+ }, {
1284
+ name: `${RULE_PREFIX}/regexp/customize`,
1285
+ files: GLOB_SRC,
1286
+ rules: overrides
1287
+ }];
1288
+ }
1289
+ //#endregion
1290
+ //#region src/configs/ignores.ts
1291
+ function ignores(ignorePatterns) {
1292
+ return [{
1293
+ name: `${RULE_PREFIX}/ignores`,
1294
+ ignores: [...GLOB_EXCLUDE, ...ignorePatterns]
1295
+ }];
1296
+ }
1297
+ //#endregion
1298
+ //#region src/configs/eslint-comments.ts
1299
+ function eslintComments(options = {}) {
1300
+ const { overrides = {} } = options;
1301
+ return [{
1302
+ ...pluginEslintComments.recommended,
1303
+ name: `${RULE_PREFIX}/eslint-comments/shared`
1304
+ }, {
1305
+ name: `${RULE_PREFIX}/eslint-comments/customize`,
1306
+ rules: overrides
1307
+ }];
1308
+ }
1309
+ //#endregion
1310
+ //#region src/configs/disables.ts
1311
+ function disables(options = {}) {
1312
+ const { overrides = {
1313
+ scripts: {},
1314
+ cli: {},
1315
+ bin: {},
1316
+ dts: {},
1317
+ cjs: {},
1318
+ config: {}
1319
+ } } = options;
1320
+ return [
1321
+ {
1322
+ name: `${RULE_PREFIX}/disables/scripts`,
1323
+ files: GLOB_SRC.map((item) => `**/scripts/${item}`),
1324
+ rules: {
1325
+ "antfu/no-top-level-await": "off",
1326
+ "no-console": "off",
1327
+ "@typescript-eslint/explicit-function-return-type": "off",
1328
+ ...overrides.scripts
1329
+ }
1330
+ },
1331
+ {
1332
+ name: `${RULE_PREFIX}/disables/cli`,
1333
+ files: [...GLOB_SRC.map((item) => `**/cli/${item}`), ...GLOB_SRC_EXT.map((item) => `**/cli.${item}`)],
1334
+ rules: {
1335
+ "antfu/no-top-level-await": "off",
1336
+ "no-console": "off",
1337
+ ...overrides.cli
1338
+ }
1339
+ },
1340
+ {
1341
+ name: `${RULE_PREFIX}/disables/bin`,
1342
+ files: ["**/bin/**/*", ...GLOB_SRC_EXT.map((item) => `**/bin.${item}`)],
1343
+ rules: {
1344
+ "antfu/no-import-dist": "off",
1345
+ "antfu/no-import-node-modules-by-path": "off",
1346
+ ...overrides.bin
1347
+ }
1348
+ },
1349
+ {
1350
+ name: `${RULE_PREFIX}/disables/dts`,
1351
+ files: ["**/*.d.?([cm])ts"],
1352
+ rules: {
1353
+ "eslint-comments/no-unlimited-disable": "off",
1354
+ "import/no-duplicates": "off",
1355
+ "no-restricted-syntax": "off",
1356
+ "unused-imports/no-unused-vars": "off",
1357
+ ...overrides.dts
1358
+ }
1359
+ },
1360
+ {
1361
+ name: `${RULE_PREFIX}/disables/cjs`,
1362
+ files: ["**/*.js", "**/*.cjs"],
1363
+ rules: {
1364
+ "ts/no-require-imports": "off",
1365
+ ...overrides.cjs
1366
+ }
1367
+ },
1368
+ {
1369
+ name: `${RULE_PREFIX}/disables/config`,
1370
+ files: [...GLOB_SRC_EXT.map((item) => `**/*.config.${item}`), ...GLOB_SRC_EXT.map((item) => `**/*.config.*.${item}`)],
1371
+ rules: {
1372
+ "antfu/no-top-level-await": "off",
1373
+ "no-console": "off",
1374
+ "ts/explicit-function-return-type": "off",
1375
+ ...overrides.config
1376
+ }
1377
+ }
1378
+ ];
1379
+ }
1380
+ //#endregion
1381
+ //#region src/configs/language-options.ts
1382
+ function languageOptions(options = {}) {
1383
+ const { sourceType = "module" } = options;
1384
+ return [{
1385
+ name: `${RULE_PREFIX}/language-options`,
1386
+ files: GLOB_SRC,
1387
+ languageOptions: { sourceType }
1388
+ }];
1389
+ }
1390
+ //#endregion
1391
+ //#region src/index.ts
1392
+ function defineConfig(options = {}) {
1393
+ const { configs = {}, ignorePatterns = [], sourceType = "module" } = options;
1394
+ return [
1395
+ ...react(configs.react),
1396
+ ...vue(configs.vue),
1397
+ ...stylistic(configs.stylistic),
1398
+ ...typescript(configs.typescript),
1399
+ ...javascript(configs.javascript),
1400
+ ...node(configs.node),
1401
+ ...json(configs.json),
1402
+ ...unicorn(configs.unicorn),
1403
+ ...imports(configs.imports),
1404
+ ...format(configs.format),
1405
+ ...tailwindcss(configs.tailwindcss),
1406
+ ...unocss(configs.unocss),
1407
+ ...yml(configs.yml),
1408
+ ...toml(configs.toml),
1409
+ ...regexp(configs.regexp),
1410
+ ...ignores(ignorePatterns),
1411
+ ...eslintComments(configs.eslintComments),
1412
+ ...disables(configs.disables),
1413
+ ...languageOptions({ sourceType })
1414
+ ];
1415
+ }
1416
+ //#endregion
1417
+ export { defineConfig };