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