@coderwyd/eslint-config 4.11.1 → 5.0.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 CHANGED
@@ -1,128 +1,34 @@
1
1
  import { createRequire } from "node:module";
2
- import createCommand from "eslint-plugin-command/config";
3
- import pluginComments from "@eslint-community/eslint-plugin-eslint-comments";
4
- import pluginAntfu from "eslint-plugin-antfu";
5
- import pluginDeMorgan from "eslint-plugin-de-morgan";
6
- import pluginNode from "eslint-plugin-n";
7
- import pluginPerfectionist from "eslint-plugin-perfectionist";
8
- import pluginUnicorn from "eslint-plugin-unicorn";
9
- import pluginUnusedImports from "eslint-plugin-unused-imports";
2
+ import antfu, { GLOB_SRC, interopDefault, resolveSubOptions } from "@antfu/eslint-config";
3
+ import { createDefu } from "defu";
10
4
  import process from "node:process";
11
- import globals from "globals";
12
- import prettierRules from "eslint-config-prettier";
13
- import { configs } from "eslint-plugin-regexp";
14
-
15
5
  //#region \0rolldown/runtime.js
16
6
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
17
-
18
7
  //#endregion
19
- //#region src/configs/command.ts
20
- function command() {
21
- return [{
22
- ...createCommand(),
23
- name: "coderwyd/command/rules"
24
- }];
25
- }
26
-
27
- //#endregion
28
- //#region src/configs/comments.ts
29
- function comments() {
30
- return [{
31
- name: "coderwyd/eslint-comments/rules",
32
- plugins: { "eslint-comments": pluginComments },
33
- rules: {
34
- "eslint-comments/no-aggregating-enable": "error",
35
- "eslint-comments/no-duplicate-disable": "error",
36
- "eslint-comments/no-unlimited-disable": "error",
37
- "eslint-comments/no-unused-enable": "error"
38
- }
39
- }];
40
- }
41
-
42
- //#endregion
43
- //#region src/configs/de-morgan.ts
44
- function deMorgan() {
8
+ //#region src/config/tailwindcss.ts
9
+ async function tailwindcss(options = {}) {
10
+ const { files = [GLOB_SRC], overrides = {}, settings = {} } = options;
45
11
  return [{
46
- name: "coderwyd/de-morgan/rules",
47
- plugins: { "de-morgan": pluginDeMorgan },
12
+ name: "coderwyd/tailwindcss/setup",
13
+ plugins: { tailwindcss: await interopDefault(import("eslint-plugin-better-tailwindcss")) }
14
+ }, {
15
+ files,
16
+ name: "coderwyd/tailwindcss/rules",
48
17
  rules: {
49
- "de-morgan/no-negated-conjunction": "error",
50
- "de-morgan/no-negated-disjunction": "error"
51
- }
52
- }];
53
- }
54
-
55
- //#endregion
56
- //#region src/constants/glob.ts
57
- const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
58
- const GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
59
- const GLOB_TS = "**/*.?([cm])ts";
60
- const GLOB_DTS = "**/*.d.?([cm])ts";
61
- const GLOB_TSX = "**/*.?([cm])tsx";
62
- const GLOB_VUE = "**/*.vue";
63
- const GLOB_ASTRO_TS = "**/*.astro/*.ts";
64
- const GLOB_SVELTE = "**/*.svelte?(.{js,ts})";
65
- const GLOB_JSON = "**/*.json";
66
- const GLOB_JSON5 = "**/*.json5";
67
- const GLOB_JSONC = "**/*.jsonc";
68
- const GLOB_MARKDOWN = "**/*.md";
69
- const GLOB_YAML = "**/*.y?(a)ml";
70
- const GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
71
- const GLOB_TESTS = [
72
- `**/__tests__/**/*.${GLOB_SRC_EXT}`,
73
- `**/*.spec.${GLOB_SRC_EXT}`,
74
- `**/*.test.${GLOB_SRC_EXT}`,
75
- `**/*.bench.${GLOB_SRC_EXT}`,
76
- `**/*.benchmark.${GLOB_SRC_EXT}`
77
- ];
78
- const GLOB_EXCLUDE = [
79
- "**/node_modules",
80
- "**/dist",
81
- "**/package-lock.json",
82
- "**/yarn.lock",
83
- "**/pnpm-lock.yaml",
84
- "**/bun.lockb",
85
- "**/output",
86
- "**/coverage",
87
- "**/temp",
88
- "**/.temp",
89
- "**/tmp",
90
- "**/.tmp",
91
- "**/.history",
92
- "**/.vitepress/cache",
93
- "**/.nuxt",
94
- "**/.next",
95
- "**/.svelte-kit",
96
- "**/.vercel",
97
- "**/.changeset",
98
- "**/.idea",
99
- "**/.cache",
100
- "**/.output",
101
- "**/.vite-inspect",
102
- "**/.yarn",
103
- "**/vite.config.*.timestamp-*",
104
- "**/CHANGELOG*.md",
105
- "**/*.min.*",
106
- "**/LICENSE*",
107
- "**/__snapshots__",
108
- "**/auto-import?(s).d.ts",
109
- "**/components.d.ts"
110
- ];
111
-
112
- //#endregion
113
- //#region src/configs/ignores.ts
114
- function ignores(userIgnores = [], ignoreTypeScript = false) {
115
- let ignores = [...GLOB_EXCLUDE];
116
- if (ignoreTypeScript) ignores.push(GLOB_TS, GLOB_TSX);
117
- ignores = [...ignores, ...userIgnores];
118
- return [{
119
- ignores,
120
- name: "coderwyd/ignores"
18
+ "tailwindcss/enforce-consistent-class-order": "warn",
19
+ "tailwindcss/no-duplicate-classes": "warn",
20
+ "tailwindcss/no-unnecessary-whitespace": "warn",
21
+ "tailwindcss/no-deprecated-classes": "warn",
22
+ "tailwindcss/no-conflicting-classes": "warn",
23
+ "tailwindcss/enforce-shorthand-classes": "warn",
24
+ "tailwindcss/enforce-consistent-variable-syntax": "warn",
25
+ ...overrides
26
+ },
27
+ settings: { "better-tailwindcss": settings }
121
28
  }];
122
29
  }
123
-
124
30
  //#endregion
125
- //#region src/shared/utils.ts
31
+ //#region src/utils.ts
126
32
  const cwd = process.cwd();
127
33
  function isPackageExists(name) {
128
34
  try {
@@ -132,1539 +38,23 @@ function isPackageExists(name) {
132
38
  return false;
133
39
  }
134
40
  }
135
-
136
- //#endregion
137
- //#region src/env.ts
138
- const isInEditor = !!((process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM) && !process.env.CI);
139
- const VueJsPackages = [
140
- "vue",
141
- "nuxt",
142
- "vitepress",
143
- "@slidev/cli"
144
- ];
145
- const RemixPackages = [
146
- "@remix-run/node",
147
- "@remix-run/react",
148
- "@remix-run/serve",
149
- "@remix-run/dev"
150
- ];
151
- const ReactRouterPackages = [
152
- "@react-router/node",
153
- "@react-router/react",
154
- "@react-router/serve",
155
- "@react-router/dev"
156
- ];
157
- const NextJsPackages = ["next"];
158
- const isCwdInScope = isPackageExists("@coderwyd/eslint-config");
159
- const ReactRefreshAllowConstantExportPackages = ["vite"];
160
- const isUsingTypeScript = isPackageExists("typescript");
161
- const isUsingVue = hasPackages(VueJsPackages);
162
- const isUsingOxfmt = hasPackages(["oxfmt"]);
163
- const isUsingRemix = hasPackages(RemixPackages);
164
- const isUsingReactRouter = hasPackages(ReactRouterPackages);
165
- const isUsingNext = hasPackages(NextJsPackages);
166
- const isAllowConstantExport = hasPackages(ReactRefreshAllowConstantExportPackages);
167
- function hasPackages(packages) {
168
- return packages.some((name) => isPackageExists(name));
169
- }
170
-
171
41
  //#endregion
172
- //#region src/shared/index.ts
173
- /**
174
- * Combine array and non-array configs into a single array.
175
- */
176
- async function combine(...configs) {
177
- return (await Promise.all(configs)).flat();
178
- }
179
- /**
180
- * Rename plugin prefixes in a rule object.
181
- * Accepts a map of prefixes to rename.
182
- *
183
- * @example
184
- * ```ts
185
- * import { renameRules } from '@coderwyd/eslint-config'
186
- *
187
- * export default [{
188
- * rules: renameRules(
189
- * {
190
- * '@typescript-eslint/indent': 'error'
191
- * },
192
- * { '@typescript-eslint': 'ts' }
193
- * )
194
- * }]
195
- * ```
196
- */
197
- function renameRules(rules, map) {
198
- return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
199
- for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
200
- return [key, value];
201
- }));
202
- }
203
- /**
204
- * Rename plugin names a flat configs array
205
- *
206
- * @example
207
- * ```ts
208
- * import { renamePluginInConfigs } from '@antfu/eslint-config'
209
- * import someConfigs from './some-configs'
210
- *
211
- * export default renamePluginInConfigs(someConfigs, {
212
- * '@typescript-eslint': 'ts',
213
- * 'import-x': 'import',
214
- * })
215
- * ```
216
- */
217
- function renamePluginInConfigs(configs, map) {
218
- return configs.map((i) => {
219
- const clone = { ...i };
220
- if (clone.rules) clone.rules = renameRules(clone.rules, map);
221
- if (clone.plugins) clone.plugins = Object.fromEntries(Object.entries(clone.plugins).map(([key, value]) => {
222
- if (key in map) return [map[key], value];
223
- return [key, value];
224
- }));
225
- return clone;
226
- });
227
- }
228
- function toArray(value) {
229
- return Array.isArray(value) ? value : [value];
230
- }
231
- async function interopDefault(m) {
232
- const resolved = await m;
233
- return resolved.default || resolved;
234
- }
235
- async function ensurePackages(packages) {
236
- if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false) return;
237
- const nonExistingPackages = packages.filter((i) => !isPackageExists(i));
238
- if (nonExistingPackages.length === 0) return;
239
- const { default: prompts } = await import("prompts");
240
- const { result } = await prompts([{
241
- message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(", ")}. Do you want to install them?`,
242
- name: "result",
243
- type: "confirm"
244
- }]);
245
- if (result) {
246
- const { installPackage } = await import("@antfu/install-pkg");
247
- await installPackage(nonExistingPackages, { dev: true });
248
- }
249
- }
250
- function resolveSubOptions(options, key) {
251
- return typeof options[key] === "boolean" ? {} : options[key] || {};
252
- }
253
- function getOverrides(options, key) {
254
- const subOptions = resolveSubOptions(options, key);
255
- return { ..."overrides" in subOptions && subOptions.overrides ? subOptions.overrides : {} };
256
- }
257
- function isInEditorEnv() {
258
- if (process.env.CI) return false;
259
- if (isInGitHooksOrLintStaged()) return false;
260
- return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM || false);
261
- }
262
- function isInGitHooksOrLintStaged() {
263
- return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged") || process.env.npm_lifecycle_script?.startsWith("nano-staged") || false);
264
- }
265
-
266
- //#endregion
267
- //#region src/configs/imports.ts
268
- async function imports() {
269
- return [{
270
- name: "coderwyd/imports/rules",
271
- plugins: {
272
- antfu: pluginAntfu,
273
- import: await interopDefault(import("eslint-plugin-import-lite"))
274
- },
275
- rules: {
276
- "antfu/import-dedupe": "error",
277
- "antfu/no-import-dist": "error",
278
- "antfu/no-import-node-modules-by-path": "error",
279
- "import/consistent-type-specifier-style": ["error", "top-level"],
280
- "import/first": "error",
281
- "import/newline-after-import": ["error", { count: 1 }],
282
- "import/no-duplicates": "error",
283
- "import/no-mutable-exports": "error",
284
- "import/no-named-default": "error"
285
- }
286
- }];
287
- }
288
-
289
- //#endregion
290
- //#region src/configs/javascript.ts
291
- function javascript(options = {}) {
292
- const { isInEditor = false, overrides = {} } = options;
293
- return [{
294
- languageOptions: {
295
- ecmaVersion: "latest",
296
- globals: {
297
- ...globals.browser,
298
- ...globals.es2026,
299
- ...globals.node,
300
- document: "readonly",
301
- navigator: "readonly",
302
- window: "readonly"
303
- },
304
- parserOptions: {
305
- ecmaFeatures: { jsx: true },
306
- ecmaVersion: "latest",
307
- sourceType: "module"
308
- },
309
- sourceType: "module"
310
- },
311
- linterOptions: { reportUnusedDisableDirectives: true },
312
- name: "coderwyd/javascript/setup"
313
- }, {
314
- name: "coderwyd/javascript/rules",
315
- plugins: { "unused-imports": pluginUnusedImports },
316
- rules: {
317
- "accessor-pairs": ["error", {
318
- enforceForClassMembers: true,
319
- setWithoutGet: true
320
- }],
321
- "antfu/no-top-level-await": "error",
322
- "antfu/top-level-function": "error",
323
- "array-callback-return": "error",
324
- "block-scoped-var": "error",
325
- "constructor-super": "error",
326
- "default-case-last": "error",
327
- "dot-notation": ["error", { allowKeywords: true }],
328
- eqeqeq: ["error", "smart"],
329
- "for-direction": "error",
330
- "getter-return": "error",
331
- "new-cap": ["error", {
332
- capIsNew: false,
333
- newIsCap: true,
334
- properties: true
335
- }],
336
- "no-alert": "error",
337
- "no-array-constructor": "error",
338
- "no-async-promise-executor": "error",
339
- "no-caller": "error",
340
- "no-case-declarations": "error",
341
- "no-class-assign": "error",
342
- "no-compare-neg-zero": "error",
343
- "no-cond-assign": ["error", "always"],
344
- "no-console": ["error", { allow: ["warn", "error"] }],
345
- "no-const-assign": "error",
346
- "no-constant-binary-expression": "error",
347
- "no-constant-condition": "error",
348
- "no-control-regex": "error",
349
- "no-debugger": "error",
350
- "no-delete-var": "error",
351
- "no-dupe-args": "error",
352
- "no-dupe-class-members": "error",
353
- "no-dupe-keys": "error",
354
- "no-duplicate-case": "error",
355
- "no-empty": ["error", { allowEmptyCatch: true }],
356
- "no-empty-character-class": "error",
357
- "no-empty-pattern": "error",
358
- "no-eval": "error",
359
- "no-ex-assign": "error",
360
- "no-extend-native": "error",
361
- "no-extra-bind": "error",
362
- "no-extra-boolean-cast": "error",
363
- "no-fallthrough": "error",
364
- "no-func-assign": "error",
365
- "no-global-assign": "error",
366
- "no-implied-eval": "error",
367
- "no-import-assign": "error",
368
- "no-invalid-regexp": "error",
369
- "no-irregular-whitespace": "error",
370
- "no-iterator": "error",
371
- "no-labels": ["error", {
372
- allowLoop: false,
373
- allowSwitch: false
374
- }],
375
- "no-lone-blocks": "error",
376
- "no-loss-of-precision": "error",
377
- "no-misleading-character-class": "error",
378
- "no-multi-str": "error",
379
- "no-new": "error",
380
- "no-new-func": "error",
381
- "no-new-native-nonconstructor": "error",
382
- "no-new-wrappers": "error",
383
- "no-obj-calls": "error",
384
- "no-object-constructor": "error",
385
- "no-octal": "error",
386
- "no-octal-escape": "error",
387
- "no-proto": "error",
388
- "no-prototype-builtins": "error",
389
- "no-redeclare": ["error", { builtinGlobals: false }],
390
- "no-regex-spaces": "error",
391
- "no-restricted-globals": [
392
- "error",
393
- {
394
- message: "Use `globalThis` instead.",
395
- name: "global"
396
- },
397
- {
398
- message: "Use `globalThis` instead.",
399
- name: "self"
400
- }
401
- ],
402
- "no-restricted-properties": [
403
- "error",
404
- {
405
- message: "Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.",
406
- property: "__proto__"
407
- },
408
- {
409
- message: "Use `Object.defineProperty` instead.",
410
- property: "__defineGetter__"
411
- },
412
- {
413
- message: "Use `Object.defineProperty` instead.",
414
- property: "__defineSetter__"
415
- },
416
- {
417
- message: "Use `Object.getOwnPropertyDescriptor` instead.",
418
- property: "__lookupGetter__"
419
- },
420
- {
421
- message: "Use `Object.getOwnPropertyDescriptor` instead.",
422
- property: "__lookupSetter__"
423
- }
424
- ],
425
- "no-restricted-syntax": [
426
- "error",
427
- "TSEnumDeclaration[const=true]",
428
- "TSExportAssignment"
429
- ],
430
- "no-self-assign": ["error", { props: true }],
431
- "no-self-compare": "error",
432
- "no-sequences": "error",
433
- "no-shadow-restricted-names": "error",
434
- "no-sparse-arrays": "error",
435
- "no-template-curly-in-string": "error",
436
- "no-this-before-super": "error",
437
- "no-throw-literal": "error",
438
- "no-undef": "error",
439
- "no-undef-init": "error",
440
- "no-unexpected-multiline": "error",
441
- "no-unmodified-loop-condition": "error",
442
- "no-unneeded-ternary": ["error", { defaultAssignment: false }],
443
- "no-unreachable": "error",
444
- "no-unreachable-loop": "error",
445
- "no-unsafe-finally": "error",
446
- "no-unsafe-negation": "error",
447
- "no-unused-expressions": ["error", {
448
- allowShortCircuit: true,
449
- allowTaggedTemplates: true,
450
- allowTernary: true
451
- }],
452
- "no-unused-vars": "off",
453
- "no-use-before-define": ["error", {
454
- classes: false,
455
- functions: false,
456
- variables: true
457
- }],
458
- "no-useless-backreference": "error",
459
- "no-useless-call": "error",
460
- "no-useless-catch": "error",
461
- "no-useless-computed-key": "error",
462
- "no-useless-constructor": "error",
463
- "no-useless-rename": "error",
464
- "no-useless-return": "error",
465
- "no-var": "error",
466
- "no-with": "error",
467
- "object-shorthand": [
468
- "error",
469
- "always",
470
- {
471
- avoidQuotes: true,
472
- ignoreConstructors: false
473
- }
474
- ],
475
- "one-var": ["error", { initialized: "never" }],
476
- "prefer-arrow-callback": ["error", {
477
- allowNamedFunctions: false,
478
- allowUnboundThis: true
479
- }],
480
- "prefer-const": ["error", {
481
- destructuring: "all",
482
- ignoreReadBeforeAssign: true
483
- }],
484
- "prefer-exponentiation-operator": "error",
485
- "prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
486
- "prefer-rest-params": "error",
487
- "prefer-spread": "error",
488
- "prefer-template": "error",
489
- "require-await": "error",
490
- "require-yield": "error",
491
- "symbol-description": "error",
492
- "unicode-bom": ["error", "never"],
493
- "unused-imports/no-unused-imports": isInEditor ? "off" : "error",
494
- "unused-imports/no-unused-vars": ["error", {
495
- args: "after-used",
496
- argsIgnorePattern: "^_",
497
- ignoreRestSiblings: true,
498
- vars: "all",
499
- varsIgnorePattern: "^_"
500
- }],
501
- "use-isnan": ["error", {
502
- enforceForIndexOf: true,
503
- enforceForSwitchCase: true
504
- }],
505
- "valid-typeof": ["error", { requireStringLiterals: true }],
506
- "vars-on-top": "error",
507
- yoda: ["error", "never"],
508
- ...overrides
509
- }
510
- }];
511
- }
512
-
513
- //#endregion
514
- //#region src/configs/jsdoc.ts
515
- async function jsdoc() {
516
- return [{
517
- name: "coderwyd/jsdoc/setup",
518
- plugins: { jsdoc: await interopDefault(import("eslint-plugin-jsdoc")) }
519
- }, {
520
- files: [GLOB_SRC],
521
- name: "coderwyd/jsdoc/rules",
522
- rules: {
523
- "jsdoc/check-access": "warn",
524
- "jsdoc/check-param-names": "warn",
525
- "jsdoc/check-property-names": "warn",
526
- "jsdoc/check-types": "warn",
527
- "jsdoc/empty-tags": "warn",
528
- "jsdoc/implements-on-classes": "warn",
529
- "jsdoc/no-defaults": "warn",
530
- "jsdoc/no-multi-asterisks": "warn",
531
- "jsdoc/require-param-name": "warn",
532
- "jsdoc/require-property": "warn",
533
- "jsdoc/require-property-description": "warn",
534
- "jsdoc/require-property-name": "warn",
535
- "jsdoc/require-returns-check": "warn",
536
- "jsdoc/require-returns-description": "warn",
537
- "jsdoc/require-yields-check": "warn"
538
- }
539
- }];
540
- }
541
-
542
- //#endregion
543
- //#region src/configs/jsonc.ts
544
- async function jsonc(options = {}) {
545
- const { files = [
546
- GLOB_JSON,
547
- GLOB_JSON5,
548
- GLOB_JSONC
549
- ], overrides = {} } = options || {};
550
- return [{
551
- name: "coderwyd/jsonc/setup",
552
- plugins: { jsonc: await interopDefault(import("eslint-plugin-jsonc")) }
553
- }, {
554
- files,
555
- language: "jsonc/x",
556
- name: "coderwyd/jsonc/rules",
557
- rules: {
558
- "jsonc/no-bigint-literals": "error",
559
- "jsonc/no-binary-expression": "error",
560
- "jsonc/no-binary-numeric-literals": "error",
561
- "jsonc/no-dupe-keys": "error",
562
- "jsonc/no-escape-sequence-in-identifier": "error",
563
- "jsonc/no-floating-decimal": "error",
564
- "jsonc/no-hexadecimal-numeric-literals": "error",
565
- "jsonc/no-infinity": "error",
566
- "jsonc/no-multi-str": "error",
567
- "jsonc/no-nan": "error",
568
- "jsonc/no-number-props": "error",
569
- "jsonc/no-numeric-separators": "error",
570
- "jsonc/no-octal": "error",
571
- "jsonc/no-octal-escape": "error",
572
- "jsonc/no-octal-numeric-literals": "error",
573
- "jsonc/no-parenthesized": "error",
574
- "jsonc/no-plus-sign": "error",
575
- "jsonc/no-regexp-literals": "error",
576
- "jsonc/no-sparse-arrays": "error",
577
- "jsonc/no-template-literals": "error",
578
- "jsonc/no-undefined-value": "error",
579
- "jsonc/no-unicode-codepoint-escapes": "error",
580
- "jsonc/no-useless-escape": "error",
581
- "jsonc/space-unary-ops": "error",
582
- "jsonc/valid-json-number": "error",
583
- "jsonc/vue-custom-block/no-parsing-error": "error",
584
- ...overrides
585
- }
586
- }];
587
- }
588
-
589
- //#endregion
590
- //#region src/configs/node.ts
591
- function node() {
592
- return [{
593
- name: "coderwyd/node/setup",
594
- plugins: { node: pluginNode }
595
- }, {
596
- files: [GLOB_SRC],
597
- name: "coderwyd/node/rules",
598
- rules: {
599
- "node/handle-callback-err": ["error", "^(err|error)$"],
600
- "node/no-deprecated-api": "error",
601
- "node/no-exports-assign": "error",
602
- "node/no-new-require": "error",
603
- "node/no-path-concat": "error",
604
- "node/no-unsupported-features/es-builtins": "error",
605
- "node/prefer-global/buffer": ["error", "never"],
606
- "node/prefer-global/process": ["error", "never"],
607
- "node/process-exit-as-throw": "error"
608
- }
609
- }];
610
- }
611
-
612
- //#endregion
613
- //#region src/configs/perfectionist.ts
614
- /**
615
- * Optional perfectionist plugin for props and items sorting.
616
- *
617
- * @see https://github.com/azat-io/eslint-plugin-perfectionist
618
- */
619
- function perfectionist() {
620
- return [{
621
- name: "coderwyd/perfectionist/rules",
622
- plugins: { perfectionist: pluginPerfectionist },
623
- rules: {
624
- "perfectionist/sort-exports": ["error", {
625
- order: "asc",
626
- type: "natural"
627
- }],
628
- "perfectionist/sort-imports": ["warn", {
629
- groups: [
630
- "side-effect-style",
631
- "value-style",
632
- "value-builtin",
633
- "value-external",
634
- "value-subpath",
635
- "value-internal",
636
- "value-parent",
637
- "value-sibling",
638
- "value-index",
639
- "ts-equals-import",
640
- "side-effect",
641
- "type-builtin",
642
- "type-external",
643
- "type-subpath",
644
- "type-internal",
645
- "type-parent",
646
- "type-sibling",
647
- "type-index",
648
- "unknown"
649
- ],
650
- internalPattern: ["^[~@#]/.*"],
651
- newlinesBetween: "ignore",
652
- order: "asc",
653
- type: "natural"
654
- }],
655
- "perfectionist/sort-named-exports": ["warn", {
656
- groups: ["value-export", "type-export"],
657
- type: "natural"
658
- }],
659
- "perfectionist/sort-named-imports": ["warn", {
660
- groups: ["value-import", "type-import"],
661
- type: "natural"
662
- }]
663
- }
664
- }];
665
- }
666
-
667
- //#endregion
668
- //#region src/configs/pnpm.ts
669
- async function pnpm() {
670
- const [pluginPnpm, yamlParser] = await Promise.all([interopDefault(import("eslint-plugin-pnpm")), interopDefault(import("yaml-eslint-parser"))]);
671
- return [{
672
- files: ["package.json", "**/package.json"],
673
- language: "jsonc/x",
674
- name: "coderwyd/pnpm/package-json",
675
- plugins: { pnpm: pluginPnpm },
676
- rules: {
677
- "pnpm/json-enforce-catalog": "error",
678
- "pnpm/json-prefer-workspace-settings": "error",
679
- "pnpm/json-valid-catalog": "error"
680
- }
681
- }, {
682
- files: ["pnpm-workspace.yaml"],
683
- languageOptions: { parser: yamlParser },
684
- name: "coderwyd/pnpm/pnpm-workspace-yaml",
685
- plugins: { pnpm: pluginPnpm },
686
- rules: {
687
- "pnpm/yaml-enforce-settings": ["error", { settings: { shellEmulator: true } }],
688
- "pnpm/yaml-no-duplicate-catalog-item": "error",
689
- "pnpm/yaml-no-unused-catalog-item": "error"
690
- }
691
- }];
692
- }
693
-
694
- //#endregion
695
- //#region src/configs/prettier.ts
696
- const rules = prettierRules.rules;
697
- delete rules["vue/html-self-closing"];
698
- function prettier() {
699
- return [{
700
- name: "coderwyd/prettier/rules",
701
- rules: {
702
- ...rules,
703
- "arrow-body-style": "off",
704
- "prefer-arrow-callback": "off"
705
- }
706
- }];
707
- }
708
-
709
- //#endregion
710
- //#region src/configs/react.ts
711
- async function react(options = {}) {
712
- const { files = [GLOB_SRC], filesTypeAware = [GLOB_TS, GLOB_TSX], ignoresTypeAware = [`${GLOB_MARKDOWN}/**`, GLOB_ASTRO_TS], overrides = {}, tsconfigPath } = options;
713
- await ensurePackages([
714
- "@eslint-react/eslint-plugin",
715
- "eslint-plugin-react-hooks",
716
- "eslint-plugin-react-refresh"
717
- ]);
718
- const isTypeAware = !!tsconfigPath;
719
- const typeAwareRules = { "react/no-leaked-conditional-rendering": "warn" };
720
- const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all([
721
- interopDefault(import("@eslint-react/eslint-plugin")),
722
- interopDefault(import("eslint-plugin-react-hooks")),
723
- interopDefault(import("eslint-plugin-react-refresh"))
724
- ]);
725
- const plugins = pluginReact.configs.all.plugins;
726
- return [
727
- {
728
- name: "coderwyd/react/setup",
729
- plugins: {
730
- react: plugins["@eslint-react"],
731
- "react-dom": plugins["@eslint-react/dom"],
732
- "react-hooks": pluginReactHooks,
733
- "react-hooks-extra": plugins["@eslint-react/hooks-extra"],
734
- "react-naming-convention": plugins["@eslint-react/naming-convention"],
735
- "react-refresh": pluginReactRefresh,
736
- "react-web-api": plugins["@eslint-react/web-api"]
737
- }
738
- },
739
- {
740
- files,
741
- languageOptions: {
742
- parserOptions: { ecmaFeatures: { jsx: true } },
743
- sourceType: "module"
744
- },
745
- name: "coderwyd/react/rules",
746
- rules: {
747
- "react/jsx-no-comment-textnodes": "warn",
748
- "react/jsx-no-duplicate-props": "warn",
749
- "react/jsx-uses-vars": "warn",
750
- "react/no-access-state-in-setstate": "error",
751
- "react/no-array-index-key": "warn",
752
- "react/no-children-count": "warn",
753
- "react/no-children-for-each": "warn",
754
- "react/no-children-map": "warn",
755
- "react/no-children-only": "warn",
756
- "react/no-children-to-array": "warn",
757
- "react/no-clone-element": "warn",
758
- "react/no-component-will-mount": "error",
759
- "react/no-component-will-receive-props": "error",
760
- "react/no-component-will-update": "error",
761
- "react/no-context-provider": "warn",
762
- "react/no-create-ref": "error",
763
- "react/no-default-props": "error",
764
- "react/no-direct-mutation-state": "error",
765
- "react/no-duplicate-key": "warn",
766
- "react/no-forward-ref": "warn",
767
- "react/no-implicit-key": "warn",
768
- "react/no-missing-key": "error",
769
- "react/no-nested-component-definitions": "error",
770
- "react/no-prop-types": "error",
771
- "react/no-redundant-should-component-update": "error",
772
- "react/no-set-state-in-component-did-mount": "warn",
773
- "react/no-set-state-in-component-did-update": "warn",
774
- "react/no-set-state-in-component-will-update": "warn",
775
- "react/no-string-refs": "error",
776
- "react/no-unnecessary-use-prefix": "warn",
777
- "react/no-unsafe-component-will-mount": "warn",
778
- "react/no-unsafe-component-will-receive-props": "warn",
779
- "react/no-unsafe-component-will-update": "warn",
780
- "react/no-unstable-context-value": "warn",
781
- "react/no-unstable-default-props": "warn",
782
- "react/no-unused-class-component-members": "warn",
783
- "react/no-unused-state": "warn",
784
- "react/no-use-context": "warn",
785
- "react/no-useless-forward-ref": "warn",
786
- "react/prefer-use-state-lazy-initialization": "warn",
787
- "react-dom/no-dangerously-set-innerhtml": "warn",
788
- "react-dom/no-dangerously-set-innerhtml-with-children": "error",
789
- "react-dom/no-find-dom-node": "error",
790
- "react-dom/no-flush-sync": "error",
791
- "react-dom/no-hydrate": "error",
792
- "react-dom/no-missing-button-type": "warn",
793
- "react-dom/no-missing-iframe-sandbox": "warn",
794
- "react-dom/no-namespace": "error",
795
- "react-dom/no-render": "error",
796
- "react-dom/no-render-return-value": "error",
797
- "react-dom/no-script-url": "warn",
798
- "react-dom/no-unsafe-iframe-sandbox": "warn",
799
- "react-dom/no-unsafe-target-blank": "warn",
800
- "react-dom/no-use-form-state": "error",
801
- "react-dom/no-void-elements-with-children": "error",
802
- ...pluginReactHooks.configs.recommended.rules,
803
- "react-hooks-extra/no-direct-set-state-in-use-effect": "warn",
804
- "react-web-api/no-leaked-event-listener": "warn",
805
- "react-web-api/no-leaked-interval": "warn",
806
- "react-web-api/no-leaked-resize-observer": "warn",
807
- "react-web-api/no-leaked-timeout": "warn",
808
- "react-refresh/only-export-components": ["warn", {
809
- allowConstantExport: isAllowConstantExport,
810
- allowExportNames: [...isUsingNext ? [
811
- "dynamic",
812
- "dynamicParams",
813
- "revalidate",
814
- "fetchCache",
815
- "runtime",
816
- "preferredRegion",
817
- "maxDuration",
818
- "config",
819
- "generateStaticParams",
820
- "metadata",
821
- "generateMetadata",
822
- "viewport",
823
- "generateViewport"
824
- ] : [], ...isUsingRemix || isUsingReactRouter ? [
825
- "meta",
826
- "links",
827
- "headers",
828
- "loader",
829
- "action",
830
- "clientLoader",
831
- "clientAction",
832
- "handle",
833
- "shouldRevalidate"
834
- ] : []]
835
- }],
836
- ...overrides
837
- }
838
- },
839
- ...isTypeAware ? [{
840
- files: filesTypeAware,
841
- ignores: ignoresTypeAware,
842
- name: "coderwyd/react/type-aware-rules",
843
- rules: { ...typeAwareRules }
844
- }] : []
845
- ];
846
- }
847
-
848
- //#endregion
849
- //#region src/configs/regexp.ts
850
- function regexp(options = {}) {
851
- const config = configs["flat/recommended"];
852
- const rules = { ...config.rules };
853
- if (options.level === "warn") Object.keys(rules).forEach((key) => {
854
- if (rules[key] === "error") rules[key] = "warn";
855
- });
856
- return [{
857
- ...config,
858
- name: "coderwyd/regexp/rules",
859
- rules: {
860
- ...rules,
861
- ...options.overrides
862
- }
863
- }];
864
- }
865
-
866
- //#endregion
867
- //#region src/configs/sort.ts
868
- /**
869
- * Sort package.json
870
- *
871
- * Requires `jsonc` config
872
- */
873
- function sortPackageJson() {
874
- return [{
875
- files: ["**/package.json"],
876
- name: "coderwyd/sort/package-json",
877
- rules: {
878
- "jsonc/sort-array-values": ["error", {
879
- order: { type: "asc" },
880
- pathPattern: "^files$"
881
- }],
882
- "jsonc/sort-keys": [
883
- "error",
884
- {
885
- order: [
886
- "publisher",
887
- "name",
888
- "displayName",
889
- "type",
890
- "version",
891
- "private",
892
- "packageManager",
893
- "description",
894
- "author",
895
- "contributors",
896
- "license",
897
- "funding",
898
- "homepage",
899
- "repository",
900
- "bugs",
901
- "keywords",
902
- "categories",
903
- "sideEffects",
904
- "imports",
905
- "exports",
906
- "main",
907
- "module",
908
- "unpkg",
909
- "jsdelivr",
910
- "types",
911
- "typesVersions",
912
- "bin",
913
- "icon",
914
- "files",
915
- "engines",
916
- "activationEvents",
917
- "contributes",
918
- "scripts",
919
- "peerDependencies",
920
- "peerDependenciesMeta",
921
- "dependencies",
922
- "optionalDependencies",
923
- "devDependencies",
924
- "pnpm",
925
- "overrides",
926
- "resolutions",
927
- "husky",
928
- "simple-git-hooks",
929
- "lint-staged",
930
- "nano-staged",
931
- "eslintConfig",
932
- "prettier",
933
- "tsdown"
934
- ],
935
- pathPattern: "^$"
936
- },
937
- {
938
- order: { type: "asc" },
939
- pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
940
- },
941
- {
942
- order: { type: "asc" },
943
- pathPattern: String.raw`^(?:resolutions|overrides|pnpm\.overrides)$`
944
- },
945
- {
946
- order: [
947
- "types",
948
- "import",
949
- "require",
950
- "default"
951
- ],
952
- pathPattern: "^exports.*$"
953
- },
954
- {
955
- order: [
956
- "pre-commit",
957
- "prepare-commit-msg",
958
- "commit-msg",
959
- "post-commit",
960
- "pre-rebase",
961
- "post-rewrite",
962
- "post-checkout",
963
- "post-merge",
964
- "pre-push",
965
- "pre-auto-gc"
966
- ],
967
- pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
968
- }
969
- ]
970
- }
971
- }];
972
- }
973
- /**
974
- * Sort tsconfig.json
975
- *
976
- * Requires `jsonc` config
977
- */
978
- function sortTsconfig() {
979
- return [{
980
- files: ["**/[jt]sconfig.json", "**/[jt]sconfig.*.json"],
981
- name: "coderwyd/sort/tsconfig-json",
982
- rules: { "jsonc/sort-keys": [
983
- "error",
984
- {
985
- order: [
986
- "extends",
987
- "compilerOptions",
988
- "references",
989
- "files",
990
- "include",
991
- "exclude"
992
- ],
993
- pathPattern: "^$"
994
- },
995
- {
996
- order: [
997
- "incremental",
998
- "composite",
999
- "tsBuildInfoFile",
1000
- "disableSourceOfProjectReferenceRedirect",
1001
- "disableSolutionSearching",
1002
- "disableReferencedProjectLoad",
1003
- "target",
1004
- "jsx",
1005
- "jsxFactory",
1006
- "jsxFragmentFactory",
1007
- "jsxImportSource",
1008
- "lib",
1009
- "moduleDetection",
1010
- "noLib",
1011
- "reactNamespace",
1012
- "useDefineForClassFields",
1013
- "emitDecoratorMetadata",
1014
- "experimentalDecorators",
1015
- "libReplacement",
1016
- "baseUrl",
1017
- "rootDir",
1018
- "rootDirs",
1019
- "customConditions",
1020
- "module",
1021
- "moduleResolution",
1022
- "moduleSuffixes",
1023
- "noResolve",
1024
- "paths",
1025
- "resolveJsonModule",
1026
- "resolvePackageJsonExports",
1027
- "resolvePackageJsonImports",
1028
- "typeRoots",
1029
- "types",
1030
- "allowArbitraryExtensions",
1031
- "allowImportingTsExtensions",
1032
- "allowUmdGlobalAccess",
1033
- "allowJs",
1034
- "checkJs",
1035
- "maxNodeModuleJsDepth",
1036
- "strict",
1037
- "strictBindCallApply",
1038
- "strictFunctionTypes",
1039
- "strictNullChecks",
1040
- "strictPropertyInitialization",
1041
- "allowUnreachableCode",
1042
- "allowUnusedLabels",
1043
- "alwaysStrict",
1044
- "exactOptionalPropertyTypes",
1045
- "noFallthroughCasesInSwitch",
1046
- "noImplicitAny",
1047
- "noImplicitOverride",
1048
- "noImplicitReturns",
1049
- "noImplicitThis",
1050
- "noPropertyAccessFromIndexSignature",
1051
- "noUncheckedIndexedAccess",
1052
- "noUnusedLocals",
1053
- "noUnusedParameters",
1054
- "useUnknownInCatchVariables",
1055
- "declaration",
1056
- "declarationDir",
1057
- "declarationMap",
1058
- "downlevelIteration",
1059
- "emitBOM",
1060
- "emitDeclarationOnly",
1061
- "importHelpers",
1062
- "importsNotUsedAsValues",
1063
- "inlineSourceMap",
1064
- "inlineSources",
1065
- "mapRoot",
1066
- "newLine",
1067
- "noEmit",
1068
- "noEmitHelpers",
1069
- "noEmitOnError",
1070
- "outDir",
1071
- "outFile",
1072
- "preserveConstEnums",
1073
- "preserveValueImports",
1074
- "removeComments",
1075
- "sourceMap",
1076
- "sourceRoot",
1077
- "stripInternal",
1078
- "allowSyntheticDefaultImports",
1079
- "esModuleInterop",
1080
- "forceConsistentCasingInFileNames",
1081
- "isolatedDeclarations",
1082
- "isolatedModules",
1083
- "preserveSymlinks",
1084
- "verbatimModuleSyntax",
1085
- "erasableSyntaxOnly",
1086
- "skipDefaultLibCheck",
1087
- "skipLibCheck"
1088
- ],
1089
- pathPattern: "^compilerOptions$"
1090
- }
1091
- ] }
1092
- }];
1093
- }
1094
- function sortPnpmWorkspace() {
1095
- return [{
1096
- files: ["**/pnpm-workspace.yaml"],
1097
- name: "coderwyd/sort/pnpm-workspace",
1098
- rules: { "yaml/sort-keys": [
1099
- "error",
1100
- {
1101
- order: [
1102
- ...[
1103
- "cacheDir",
1104
- "catalogMode",
1105
- "cleanupUnusedCatalogs",
1106
- "dedupeDirectDeps",
1107
- "deployAllFiles",
1108
- "enablePrePostScripts",
1109
- "engineStrict",
1110
- "extendNodePath",
1111
- "hoist",
1112
- "hoistPattern",
1113
- "hoistWorkspacePackages",
1114
- "ignoreCompatibilityDb",
1115
- "ignoreDepScripts",
1116
- "ignoreScripts",
1117
- "ignoreWorkspaceRootCheck",
1118
- "managePackageManagerVersions",
1119
- "minimumReleaseAge",
1120
- "minimumReleaseAgeExclude",
1121
- "modulesDir",
1122
- "nodeLinker",
1123
- "nodeVersion",
1124
- "optimisticRepeatInstall",
1125
- "packageManagerStrict",
1126
- "packageManagerStrictVersion",
1127
- "preferSymlinkedExecutables",
1128
- "preferWorkspacePackages",
1129
- "publicHoistPattern",
1130
- "registrySupportsTimeField",
1131
- "requiredScripts",
1132
- "resolutionMode",
1133
- "savePrefix",
1134
- "scriptShell",
1135
- "shamefullyHoist",
1136
- "shellEmulator",
1137
- "stateDir",
1138
- "supportedArchitectures",
1139
- "symlink",
1140
- "tag",
1141
- "trustPolicy",
1142
- "trustPolicyExclude",
1143
- "updateNotifier"
1144
- ],
1145
- "packages",
1146
- "overrides",
1147
- "patchedDependencies",
1148
- "catalog",
1149
- "catalogs",
1150
- ...[
1151
- "allowedDeprecatedVersions",
1152
- "allowNonAppliedPatches",
1153
- "configDependencies",
1154
- "ignoredBuiltDependencies",
1155
- "ignoredOptionalDependencies",
1156
- "neverBuiltDependencies",
1157
- "onlyBuiltDependencies",
1158
- "onlyBuiltDependenciesFile",
1159
- "packageExtensions",
1160
- "peerDependencyRules"
1161
- ]
1162
- ],
1163
- pathPattern: "^$"
1164
- },
1165
- {
1166
- order: { type: "asc" },
1167
- pathPattern: ".*"
1168
- }
1169
- ] }
1170
- }];
1171
- }
1172
-
1173
- //#endregion
1174
- //#region src/configs/specials.ts
1175
- function specials() {
1176
- return [
1177
- {
1178
- files: [`**/scripts/${GLOB_SRC}`],
1179
- name: "coderwyd/specials/scripts",
1180
- rules: {
1181
- "antfu/no-top-level-await": "off",
1182
- "no-console": "off",
1183
- "ts/explicit-function-return-type": "off"
1184
- }
1185
- },
1186
- {
1187
- files: [`**/cli/${GLOB_SRC}`, `**/cli.${GLOB_SRC_EXT}`],
1188
- name: "coderwyd/specials/cli",
1189
- rules: {
1190
- "antfu/no-top-level-await": "off",
1191
- "no-console": "off"
1192
- }
1193
- },
1194
- {
1195
- files: ["**/bin/**/*", `**/bin.${GLOB_SRC_EXT}`],
1196
- name: "coderwyd/specials/bin",
1197
- rules: {
1198
- "antfu/no-import-dist": "off",
1199
- "antfu/no-import-node-modules-by-path": "off"
1200
- }
1201
- },
1202
- {
1203
- files: [GLOB_DTS],
1204
- name: "coderwyd/specials/dts",
1205
- rules: {
1206
- "eslint-comments/no-unlimited-disable": "off",
1207
- "import/no-duplicates": "off",
1208
- "no-restricted-syntax": "off",
1209
- "unused-imports/no-unused-vars": "off"
1210
- }
1211
- },
1212
- {
1213
- files: ["**/*.{test,spec}.([tj])s?(x)"],
1214
- name: "coderwyd/specials/test",
1215
- rules: {
1216
- "antfu/no-top-level-await": "off",
1217
- "no-unused-expressions": "off"
1218
- }
1219
- },
1220
- {
1221
- files: ["**/*.js", "**/*.cjs"],
1222
- name: "coderwyd/specials/cjs",
1223
- rules: { "ts/no-require-imports": "off" }
1224
- }
1225
- ];
1226
- }
1227
-
1228
- //#endregion
1229
- //#region src/configs/svelte.ts
1230
- async function svelte(options = {}) {
1231
- const { files = [GLOB_SVELTE], overrides = {} } = options;
1232
- await ensurePackages(["eslint-plugin-svelte"]);
1233
- const [pluginSvelte, parserSvelte] = await Promise.all([interopDefault(import("eslint-plugin-svelte")), interopDefault(import("svelte-eslint-parser"))]);
1234
- return [{
1235
- name: "coderwyd/svelte/setup",
1236
- plugins: { svelte: pluginSvelte }
1237
- }, {
1238
- files,
1239
- languageOptions: {
1240
- parser: parserSvelte,
1241
- parserOptions: {
1242
- extraFileExtensions: [".svelte"],
1243
- parser: options.typescript ? await interopDefault(import("@typescript-eslint/parser")) : null
1244
- }
1245
- },
1246
- name: "coderwyd/svelte/rules",
1247
- processor: pluginSvelte.processors[".svelte"],
1248
- rules: {
1249
- "import/no-mutable-exports": "off",
1250
- "no-undef": "off",
1251
- "no-unused-vars": ["error", {
1252
- args: "none",
1253
- caughtErrors: "none",
1254
- ignoreRestSiblings: true,
1255
- vars: "all",
1256
- varsIgnorePattern: "^(\\$\\$Props$|\\$\\$Events$|\\$\\$Slots$)"
1257
- }],
1258
- "svelte/comment-directive": "error",
1259
- "svelte/no-at-debug-tags": "warn",
1260
- "svelte/no-at-html-tags": "error",
1261
- "svelte/no-dupe-else-if-blocks": "error",
1262
- "svelte/no-dupe-style-properties": "error",
1263
- "svelte/no-dupe-use-directives": "error",
1264
- "svelte/no-export-load-in-svelte-module-in-kit-pages": "error",
1265
- "svelte/no-inner-declarations": "error",
1266
- "svelte/no-not-function-handler": "error",
1267
- "svelte/no-object-in-text-mustaches": "error",
1268
- "svelte/no-reactive-functions": "error",
1269
- "svelte/no-reactive-literals": "error",
1270
- "svelte/no-shorthand-style-property-overrides": "error",
1271
- "svelte/no-unknown-style-directive-property": "error",
1272
- "svelte/no-unused-svelte-ignore": "error",
1273
- "svelte/no-useless-mustaches": "error",
1274
- "svelte/require-store-callbacks-use-set-param": "error",
1275
- "svelte/system": "error",
1276
- "svelte/valid-each-key": "error",
1277
- "unused-imports/no-unused-vars": ["error", {
1278
- args: "after-used",
1279
- argsIgnorePattern: "^_",
1280
- vars: "all",
1281
- varsIgnorePattern: "^(_|\\$\\$Props$|\\$\\$Events$|\\$\\$Slots$)"
1282
- }],
1283
- ...overrides
1284
- }
1285
- }];
1286
- }
1287
-
1288
- //#endregion
1289
- //#region src/configs/tailwindcss.ts
1290
- async function tailwindcss(options = {}) {
1291
- const { overrides } = options;
1292
- await ensurePackages(["eslint-plugin-tailwindcss"]);
1293
- return [{
1294
- name: "coderwyd/tailwindcss/rules",
1295
- plugins: { tailwindcss: await interopDefault(import("eslint-plugin-tailwindcss")) },
1296
- rules: {
1297
- "tailwindcss/classnames-order": "warn",
1298
- "tailwindcss/enforces-negative-arbitrary-values": "warn",
1299
- "tailwindcss/enforces-shorthand": "warn",
1300
- "tailwindcss/migration-from-tailwind-2": "warn",
1301
- "tailwindcss/no-arbitrary-value": "off",
1302
- "tailwindcss/no-contradicting-classname": "warn",
1303
- "tailwindcss/no-custom-classname": "off",
1304
- "tailwindcss/no-unnecessary-arbitrary-value": "warn",
1305
- ...overrides
1306
- }
1307
- }];
1308
- }
1309
-
1310
- //#endregion
1311
- //#region src/configs/test.ts
1312
- let _pluginTest;
1313
- async function test(options = {}) {
1314
- const { files = GLOB_TESTS, isInEditor = false, overrides = {} } = options;
1315
- const [pluginVitest, pluginNoOnlyTests] = await Promise.all([interopDefault(import("@vitest/eslint-plugin")), interopDefault(import("eslint-plugin-no-only-tests"))]);
1316
- _pluginTest = _pluginTest || {
1317
- ...pluginVitest,
1318
- rules: {
1319
- ...pluginVitest.rules,
1320
- ...pluginNoOnlyTests.rules
1321
- }
1322
- };
1323
- return [{
1324
- name: "coderwyd/test/setup",
1325
- plugins: { test: _pluginTest }
1326
- }, {
1327
- files,
1328
- name: "coderwyd/test/rules",
1329
- rules: {
1330
- "node/prefer-global/process": "off",
1331
- "test/consistent-test-it": ["error", {
1332
- fn: "it",
1333
- withinDescribe: "it"
1334
- }],
1335
- "test/no-identical-title": "error",
1336
- "test/no-import-node-test": "error",
1337
- "test/no-only-tests": isInEditor ? "off" : "error",
1338
- "test/prefer-hooks-in-order": "error",
1339
- "test/prefer-lowercase-title": "error",
1340
- "ts/explicit-function-return-type": "off",
1341
- ...overrides
1342
- }
1343
- }];
1344
- }
1345
-
1346
- //#endregion
1347
- //#region src/configs/typescript.ts
1348
- async function typescript(options = {}) {
1349
- const { componentExts = [], overrides = {}, overridesTypeAware = {}, parserOptions = {} } = options;
1350
- const files = options.files ?? [
1351
- GLOB_TS,
1352
- GLOB_TSX,
1353
- ...componentExts.map((ext) => `**/*.${ext}`)
1354
- ];
1355
- const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
1356
- const ignoresTypeAware = options.ignoresTypeAware ?? [`${GLOB_MARKDOWN}/**`, GLOB_ASTRO_TS];
1357
- const tsconfigPath = options.tsconfigPath;
1358
- const isTypeAware = !!tsconfigPath;
1359
- const typeAwareRules = {
1360
- "no-array-constructor": "off",
1361
- "no-implied-eval": "off",
1362
- "no-throw-literal": "off",
1363
- "no-unused-expressions": "off",
1364
- "no-unused-vars": "off",
1365
- "prefer-promise-reject-errors": "off",
1366
- "require-await": "off",
1367
- "ts/await-thenable": "error",
1368
- "ts/ban-ts-comment": "error",
1369
- "ts/no-array-constructor": "error",
1370
- "ts/no-array-delete": "error",
1371
- "ts/no-base-to-string": "error",
1372
- "ts/no-duplicate-enum-values": "error",
1373
- "ts/no-duplicate-type-constituents": "error",
1374
- "ts/no-empty-object-type": "error",
1375
- "ts/no-explicit-any": "error",
1376
- "ts/no-extra-non-null-assertion": "error",
1377
- "ts/no-floating-promises": "error",
1378
- "ts/no-for-in-array": "error",
1379
- "ts/no-implied-eval": "error",
1380
- "ts/no-misused-new": "error",
1381
- "ts/no-misused-promises": "error",
1382
- "ts/no-namespace": "error",
1383
- "ts/no-non-null-asserted-optional-chain": "error",
1384
- "ts/no-redundant-type-constituents": "error",
1385
- "ts/no-require-imports": "error",
1386
- "ts/no-this-alias": "error",
1387
- "ts/no-unnecessary-type-assertion": "error",
1388
- "ts/no-unnecessary-type-constraint": "error",
1389
- "ts/no-unsafe-argument": "error",
1390
- "ts/no-unsafe-assignment": "error",
1391
- "ts/no-unsafe-call": "error",
1392
- "ts/no-unsafe-declaration-merging": "error",
1393
- "ts/no-unsafe-enum-comparison": "error",
1394
- "ts/no-unsafe-function-type": "error",
1395
- "ts/no-unsafe-member-access": "error",
1396
- "ts/no-unsafe-return": "error",
1397
- "ts/no-unsafe-unary-minus": "error",
1398
- "ts/no-unused-expressions": "error",
1399
- "ts/no-unused-vars": "error",
1400
- "ts/no-wrapper-object-types": "error",
1401
- "ts/only-throw-error": "error",
1402
- "ts/prefer-as-const": "error",
1403
- "ts/prefer-namespace-keyword": "error",
1404
- "ts/prefer-promise-reject-errors": "error",
1405
- "ts/require-await": "error",
1406
- "ts/restrict-plus-operands": "error",
1407
- "ts/restrict-template-expressions": "error",
1408
- "ts/triple-slash-reference": "error",
1409
- "ts/unbound-method": "error"
1410
- };
1411
- const [pluginTs, parserTs] = await Promise.all([interopDefault(import("@typescript-eslint/eslint-plugin")), interopDefault(import("@typescript-eslint/parser"))]);
1412
- function makeParser(typeAware, files, ignores) {
1413
- return {
1414
- files,
1415
- ...ignores ? { ignores } : {},
1416
- languageOptions: {
1417
- parser: parserTs,
1418
- parserOptions: {
1419
- extraFileExtensions: componentExts.map((ext) => `.${ext}`),
1420
- sourceType: "module",
1421
- ...typeAware ? {
1422
- projectService: {
1423
- allowDefaultProject: ["./*.js"],
1424
- defaultProject: tsconfigPath
1425
- },
1426
- tsconfigRootDir: process.cwd()
1427
- } : {},
1428
- ...parserOptions
1429
- }
1430
- },
1431
- name: `coderwyd/typescript/${typeAware ? "type-aware-parser" : "parser"}`
1432
- };
1433
- }
1434
- return [
1435
- {
1436
- name: "coderwyd/typescript/setup",
1437
- plugins: {
1438
- antfu: pluginAntfu,
1439
- ts: pluginTs
1440
- }
1441
- },
1442
- ...isTypeAware ? [makeParser(false, files), makeParser(true, filesTypeAware, ignoresTypeAware)] : [makeParser(false, files)],
1443
- {
1444
- files,
1445
- name: "coderwyd/typescript/rules",
1446
- rules: {
1447
- ...renameRules(pluginTs.configs["eslint-recommended"].overrides[0].rules, { "@typescript-eslint": "ts" }),
1448
- ...renameRules(pluginTs.configs.strict.rules, { "@typescript-eslint": "ts" }),
1449
- "no-dupe-class-members": "off",
1450
- "no-redeclare": "off",
1451
- "no-use-before-define": "off",
1452
- "no-useless-constructor": "off",
1453
- "ts/ban-ts-comment": ["error", { "ts-expect-error": "allow-with-description" }],
1454
- "ts/consistent-type-definitions": ["error", "interface"],
1455
- "ts/consistent-type-imports": ["error", {
1456
- disallowTypeAnnotations: false,
1457
- fixStyle: "separate-type-imports",
1458
- prefer: "type-imports"
1459
- }],
1460
- "ts/method-signature-style": ["error", "property"],
1461
- "ts/no-dupe-class-members": "error",
1462
- "ts/no-dynamic-delete": "off",
1463
- "ts/no-empty-object-type": ["error", {
1464
- allowInterfaces: "with-single-extends",
1465
- allowObjectTypes: "never",
1466
- allowWithName: "Props$"
1467
- }],
1468
- "ts/no-explicit-any": "off",
1469
- "ts/no-extraneous-class": "off",
1470
- "ts/no-import-type-side-effects": "error",
1471
- "ts/no-invalid-void-type": "off",
1472
- "ts/no-non-null-assertion": "off",
1473
- "ts/no-redeclare": ["error", { builtinGlobals: false }],
1474
- "ts/no-require-imports": "error",
1475
- "ts/no-unused-expressions": ["error", {
1476
- allowShortCircuit: true,
1477
- allowTaggedTemplates: true,
1478
- allowTernary: true
1479
- }],
1480
- "ts/no-unused-vars": "off",
1481
- "ts/no-use-before-define": ["error", {
1482
- classes: false,
1483
- functions: false,
1484
- variables: true
1485
- }],
1486
- "ts/no-useless-constructor": "off",
1487
- "ts/no-wrapper-object-types": "error",
1488
- "ts/triple-slash-reference": "off",
1489
- "ts/unified-signatures": "off",
1490
- ...overrides
1491
- }
1492
- },
1493
- ...isTypeAware ? [{
1494
- files: filesTypeAware,
1495
- ignores: ignoresTypeAware,
1496
- name: "coderwyd/typescript/rules-type-aware",
1497
- rules: {
1498
- ...typeAwareRules,
1499
- ...overridesTypeAware
1500
- }
1501
- }] : []
1502
- ];
1503
- }
1504
-
1505
- //#endregion
1506
- //#region src/configs/unicorn.ts
1507
- function unicorn(options = {}) {
1508
- const { overrides = {} } = options;
1509
- return [{
1510
- name: "coderwyd/unicorn/rules",
1511
- plugins: { unicorn: pluginUnicorn },
1512
- rules: {
1513
- "unicorn/catch-error-name": "error",
1514
- "unicorn/consistent-empty-array-spread": "error",
1515
- "unicorn/consistent-existence-index-check": "error",
1516
- "unicorn/custom-error-definition": "error",
1517
- "unicorn/error-message": "error",
1518
- "unicorn/escape-case": "error",
1519
- "unicorn/new-for-builtins": "error",
1520
- "unicorn/no-array-method-this-argument": "error",
1521
- "unicorn/no-await-in-promise-methods": "error",
1522
- "unicorn/no-console-spaces": "error",
1523
- "unicorn/no-for-loop": "error",
1524
- "unicorn/no-hex-escape": "error",
1525
- "unicorn/no-immediate-mutation": "error",
1526
- "unicorn/no-instanceof-builtins": "error",
1527
- "unicorn/no-invalid-remove-event-listener": "error",
1528
- "unicorn/no-lonely-if": "error",
1529
- "unicorn/no-negation-in-equality-check": "error",
1530
- "unicorn/no-new-array": "error",
1531
- "unicorn/no-new-buffer": "error",
1532
- "unicorn/no-single-promise-in-promise-methods": "error",
1533
- "unicorn/no-static-only-class": "error",
1534
- "unicorn/no-unnecessary-array-flat-depth": "error",
1535
- "unicorn/no-unnecessary-array-splice-count": "error",
1536
- "unicorn/no-unnecessary-await": "error",
1537
- "unicorn/no-unnecessary-slice-end": "error",
1538
- "unicorn/no-useless-collection-argument": "error",
1539
- "unicorn/no-useless-error-capture-stack-trace": "error",
1540
- "unicorn/no-zero-fractions": "error",
1541
- "unicorn/prefer-add-event-listener": "error",
1542
- "unicorn/prefer-array-find": "error",
1543
- "unicorn/prefer-array-flat-map": "error",
1544
- "unicorn/prefer-array-index-of": "error",
1545
- "unicorn/prefer-array-some": "error",
1546
- "unicorn/prefer-at": "error",
1547
- "unicorn/prefer-bigint-literals": "error",
1548
- "unicorn/prefer-blob-reading-methods": "error",
1549
- "unicorn/prefer-class-fields": "error",
1550
- "unicorn/prefer-classlist-toggle": "error",
1551
- "unicorn/prefer-date-now": "error",
1552
- "unicorn/prefer-dom-node-append": "error",
1553
- "unicorn/prefer-dom-node-dataset": "error",
1554
- "unicorn/prefer-dom-node-remove": "error",
1555
- "unicorn/prefer-dom-node-text-content": "error",
1556
- "unicorn/prefer-includes": "error",
1557
- "unicorn/prefer-keyboard-event-key": "error",
1558
- "unicorn/prefer-math-min-max": "error",
1559
- "unicorn/prefer-math-trunc": "error",
1560
- "unicorn/prefer-modern-dom-apis": "error",
1561
- "unicorn/prefer-modern-math-apis": "error",
1562
- "unicorn/prefer-negative-index": "error",
1563
- "unicorn/prefer-node-protocol": "error",
1564
- "unicorn/prefer-number-properties": "error",
1565
- "unicorn/prefer-optional-catch-binding": "error",
1566
- "unicorn/prefer-prototype-methods": "error",
1567
- "unicorn/prefer-query-selector": "error",
1568
- "unicorn/prefer-reflect-apply": "error",
1569
- "unicorn/prefer-response-static-json": "error",
1570
- "unicorn/prefer-single-call": "error",
1571
- "unicorn/prefer-string-replace-all": "error",
1572
- "unicorn/prefer-string-slice": "error",
1573
- "unicorn/prefer-string-starts-ends-with": "error",
1574
- "unicorn/prefer-string-trim-start-end": "error",
1575
- "unicorn/prefer-type-error": "error",
1576
- "unicorn/require-module-attributes": "error",
1577
- "unicorn/require-module-specifiers": "error",
1578
- "unicorn/throw-new-error": "error",
1579
- ...overrides
1580
- }
1581
- }];
1582
- }
1583
-
1584
- //#endregion
1585
- //#region src/configs/unocss.ts
1586
- async function unocss(options = {}) {
1587
- const { attributify = true, strict = false } = options;
1588
- await ensurePackages(["@unocss/eslint-plugin"]);
1589
- return [{
1590
- name: "coderwyd/unocss/rules",
1591
- plugins: { unocss: await interopDefault(import("@unocss/eslint-plugin")) },
1592
- rules: {
1593
- "unocss/order": "warn",
1594
- ...attributify ? { "unocss/order-attributify": "warn" } : {},
1595
- ...strict ? { "unocss/blocklist": "error" } : {}
1596
- }
1597
- }];
1598
- }
1599
-
1600
- //#endregion
1601
- //#region src/configs/vue.ts
1602
- async function vue(options = {}) {
1603
- const { files = [GLOB_VUE], overrides = {}, vueVersion = 3 } = options;
1604
- const [pluginVue, parserVue] = await Promise.all([interopDefault(import("eslint-plugin-vue")), interopDefault(import("vue-eslint-parser"))]);
1605
- const isVue3 = vueVersion === 3;
1606
- const configKeys = isVue3 ? [
1607
- "flat/essential",
1608
- "flat/strongly-recommended",
1609
- "flat/recommended"
1610
- ] : [
1611
- "flat/vue2-essential",
1612
- "flat/vue2-strongly-recommended",
1613
- "flat/vue2-recommended"
1614
- ];
1615
- function extractRules(config) {
1616
- if (Array.isArray(config)) return config.reduce((acc, c) => {
1617
- if (c && c.rules) Object.assign(acc, c.rules);
1618
- return acc;
1619
- }, {});
1620
- return config?.rules ?? {};
42
+ //#region src/merge-options.ts
43
+ const defuOverrideArray = createDefu((obj, key, value) => {
44
+ if (Array.isArray(obj[key]) && Array.isArray(value)) {
45
+ obj[key] = value;
46
+ return true;
1621
47
  }
1622
- const vueRules = configKeys.reduce((preRules, key) => {
1623
- const config = pluginVue.configs[key];
1624
- return {
1625
- ...preRules,
1626
- ...extractRules(config)
1627
- };
1628
- }, {});
1629
- return [{
1630
- languageOptions: { globals: {
1631
- computed: "readonly",
1632
- defineEmits: "readonly",
1633
- defineExpose: "readonly",
1634
- defineProps: "readonly",
1635
- onMounted: "readonly",
1636
- onUnmounted: "readonly",
1637
- reactive: "readonly",
1638
- ref: "readonly",
1639
- shallowReactive: "readonly",
1640
- shallowRef: "readonly",
1641
- toRef: "readonly",
1642
- toRefs: "readonly",
1643
- watch: "readonly",
1644
- watchEffect: "readonly"
48
+ });
49
+ function mergeOptions(options) {
50
+ const { vueVersion = 3 } = resolveSubOptions(options ?? {}, "vue");
51
+ const defaults = {
52
+ typescript: { overrides: {
53
+ "ts/consistent-type-definitions": "off",
54
+ "ts/no-explicit-any": "warn"
1645
55
  } },
1646
- name: "coderwyd/vue/setup",
1647
- plugins: { vue: pluginVue }
1648
- }, {
1649
- files,
1650
- languageOptions: {
1651
- parser: parserVue,
1652
- parserOptions: {
1653
- ecmaFeatures: { jsx: true },
1654
- extraFileExtensions: [".vue"],
1655
- parser: options.typescript ? await interopDefault(import("@typescript-eslint/parser")) : null,
1656
- sourceType: "module"
1657
- }
1658
- },
1659
- name: "coderwyd/vue/rules",
1660
- processor: pluginVue.processors[".vue"],
1661
- rules: {
1662
- ...pluginVue.configs["flat/base"].rules,
1663
- ...vueRules,
1664
- "antfu/no-top-level-await": "off",
1665
- "node/prefer-global/process": "off",
1666
- "ts/explicit-function-return-type": "off",
1667
- "vue/block-order": ["error", { order: isVue3 ? [
56
+ vue: { overrides: {
57
+ "vue/block-order": ["error", { order: vueVersion === 3 ? [
1668
58
  "script",
1669
59
  "template",
1670
60
  "style"
@@ -1673,19 +63,6 @@ async function vue(options = {}) {
1673
63
  "script",
1674
64
  "style"
1675
65
  ] }],
1676
- "vue/component-name-in-template-casing": ["error", "PascalCase"],
1677
- "vue/component-options-name-casing": ["error", "PascalCase"],
1678
- "vue/component-tags-order": "off",
1679
- "vue/custom-event-name-casing": ["error", "camelCase"],
1680
- "vue/define-macros-order": ["error", { order: [
1681
- "defineOptions",
1682
- "defineProps",
1683
- "defineEmits",
1684
- "defineSlots"
1685
- ] }],
1686
- "vue/dot-location": ["error", "property"],
1687
- "vue/dot-notation": ["error", { allowKeywords: true }],
1688
- "vue/eqeqeq": ["error", "smart"],
1689
66
  "vue/html-self-closing": ["error", {
1690
67
  html: {
1691
68
  component: "always",
@@ -1694,232 +71,41 @@ async function vue(options = {}) {
1694
71
  },
1695
72
  math: "always",
1696
73
  svg: "always"
1697
- }],
1698
- "vue/max-attributes-per-line": "off",
1699
- "vue/multi-word-component-names": "off",
1700
- "vue/no-constant-condition": "warn",
1701
- "vue/no-dupe-keys": "off",
1702
- "vue/no-duplicate-attr-inheritance": "warn",
1703
- "vue/no-empty-pattern": "error",
1704
- "vue/no-extra-parens": ["error", "functions"],
1705
- "vue/no-irregular-whitespace": "error",
1706
- "vue/no-loss-of-precision": "error",
1707
- "vue/no-required-prop-with-default": "warn",
1708
- "vue/no-restricted-syntax": [
1709
- "error",
1710
- "DebuggerStatement",
1711
- "LabeledStatement",
1712
- "WithStatement"
1713
- ],
1714
- "vue/no-restricted-v-bind": ["error", "/^v-/"],
1715
- "vue/no-setup-props-reactivity-loss": "off",
1716
- "vue/no-sparse-arrays": "error",
1717
- "vue/no-unsupported-features": "warn",
1718
- "vue/no-unused-emit-declarations": "warn",
1719
- "vue/no-unused-refs": "error",
1720
- "vue/no-use-v-else-with-v-for": "error",
1721
- "vue/no-useless-mustaches": "warn",
1722
- "vue/no-useless-v-bind": "error",
1723
- "vue/no-v-html": "off",
1724
- "vue/no-v-text": "warn",
1725
- "vue/object-shorthand": [
1726
- "error",
1727
- "always",
1728
- {
1729
- avoidQuotes: true,
1730
- ignoreConstructors: false
1731
- }
1732
- ],
1733
- "vue/padding-line-between-blocks": ["error", "always"],
1734
- "vue/prefer-define-options": "warn",
1735
- "vue/prefer-separate-static-class": "error",
1736
- "vue/prefer-template": "error",
1737
- "vue/prop-name-casing": ["error", "camelCase"],
1738
- "vue/require-default-prop": "off",
1739
- "vue/require-macro-variable-name": ["warn", {
1740
- defineEmits: "emit",
1741
- defineProps: "props",
1742
- defineSlots: "slots",
1743
- useAttrs: "attrs",
1744
- useSlots: "slots"
1745
- }],
1746
- "vue/require-prop-types": "off",
1747
- "vue/space-infix-ops": "error",
1748
- "vue/space-unary-ops": ["error", {
1749
- nonwords: false,
1750
- words: true
1751
- }],
1752
- "vue/valid-define-options": "warn",
1753
- ...overrides
1754
- }
1755
- }];
1756
- }
1757
-
1758
- //#endregion
1759
- //#region src/configs/yaml.ts
1760
- async function yaml(options = {}) {
1761
- const { files = [GLOB_YAML], overrides = {} } = options;
1762
- const [pluginYaml, parserYaml] = await Promise.all([interopDefault(import("eslint-plugin-yml")), interopDefault(import("yaml-eslint-parser"))]);
1763
- return [
1764
- {
1765
- name: "coderwyd/yaml/setup",
1766
- plugins: { yaml: pluginYaml }
1767
- },
1768
- {
1769
- files,
1770
- languageOptions: { parser: parserYaml },
1771
- name: "coderwyd/yaml/rules",
1772
- rules: {
1773
- "yaml/block-mapping": "error",
1774
- "yaml/block-sequence": "error",
1775
- "yaml/no-empty-key": "error",
1776
- "yaml/no-empty-sequence-entry": "error",
1777
- "yaml/no-irregular-whitespace": "error",
1778
- "yaml/plain-scalar": "error",
1779
- "yaml/vue-custom-block/no-parsing-error": "error",
1780
- ...overrides
1781
- }
1782
- },
1783
- {
1784
- files: ["pnpm-workspace.yaml"],
1785
- name: "coderwyd/yaml/pnpm-workspace",
1786
- rules: { "yaml/sort-keys": [
1787
- "error",
1788
- {
1789
- order: [
1790
- "packages",
1791
- "overrides",
1792
- "patchedDependencies",
1793
- "hoistPattern",
1794
- "catalog",
1795
- "catalogs",
1796
- "allowedDeprecatedVersions",
1797
- "allowNonAppliedPatches",
1798
- "configDependencies",
1799
- "ignoredBuiltDependencies",
1800
- "ignoredOptionalDependencies",
1801
- "neverBuiltDependencies",
1802
- "onlyBuiltDependencies",
1803
- "onlyBuiltDependenciesFile",
1804
- "packageExtensions",
1805
- "peerDependencyRules",
1806
- "supportedArchitectures"
1807
- ],
1808
- pathPattern: "^$"
1809
- },
1810
- {
1811
- order: { type: "asc" },
1812
- pathPattern: ".*"
1813
- }
1814
- ] }
1815
- }
1816
- ];
74
+ }]
75
+ } },
76
+ react: isPackageExists("react") || !!options?.react ? { overrides: {
77
+ "react/no-context-provider": "off",
78
+ "react/no-forward-ref": "off",
79
+ "react/no-use-context": "off",
80
+ "react-hooks/set-state-in-effect": "off",
81
+ "react-hooks-extra/no-direct-set-state-in-use-effect": "error"
82
+ } } : void 0,
83
+ pnpm: false,
84
+ stylistic: false,
85
+ isInEditor: false
86
+ };
87
+ if (!options) return defaults;
88
+ const result = { ...options };
89
+ for (const key of Object.keys(defaults)) {
90
+ const userValue = options[key];
91
+ const defaultValue = defaults[key];
92
+ if (userValue === void 0) result[key] = defaultValue;
93
+ else if (typeof defaultValue === "boolean") {} else if (userValue === true) result[key] = defaultValue;
94
+ else if (typeof userValue === "object" && userValue !== null && defaultValue) result[key] = defuOverrideArray(userValue, defaultValue);
95
+ }
96
+ return result;
1817
97
  }
1818
-
1819
98
  //#endregion
1820
99
  //#region src/index.ts
1821
- const flatConfigProps = [
1822
- "name",
1823
- "languageOptions",
1824
- "linterOptions",
1825
- "processor",
1826
- "plugins",
1827
- "rules",
1828
- "settings"
1829
- ];
1830
- const defaultPluginRenaming = {
1831
- "@eslint-react": "react",
1832
- "@eslint-react/dom": "react-dom",
1833
- "@eslint-react/hooks-extra": "react-hooks-extra",
1834
- "@eslint-react/naming-convention": "react-naming-convention",
1835
- "@typescript-eslint": "ts",
1836
- "import-lite": "import",
1837
- n: "node",
1838
- vitest: "test",
1839
- yml: "yaml"
1840
- };
1841
- /**
1842
- * Construct an array of ESLint flat config items.
1843
- *
1844
- * @param {OptionsConfig & TypedFlatConfigItem} options
1845
- * The options for generating the ESLint configurations.
1846
- * @param {Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[] | Linter.Config[]>[]} userConfigs
1847
- * The user configurations to be merged with the generated configurations.
1848
- * @returns {Promise<TypedFlatConfigItem[]>}
1849
- * The merged ESLint configurations.
1850
- */
1851
- async function defineConfig(options = {}, ...userConfigs) {
1852
- const { autoRenamePlugins = true, componentExts = [], gitignore: enableGitignore = true, perfectionist: enablePerfectionist = true, pnpm: enableCatalogs = false, react: enableReact = false, regexp: enableRegexp = true, svelte: enableSvelte = false, tailwindcss: enableTailwindCSS = false, typescript: enableTypeScript = isUsingTypeScript, unocss: enableUnoCSS = false, vue: enableVue = isUsingVue } = options;
1853
- let isInEditor = options.isInEditor;
1854
- if (isInEditor == null) {
1855
- isInEditor = isInEditorEnv();
1856
- if (isInEditor) console.log("[@coderwyd/eslint-config] Detected running in editor, some rules are disabled.");
1857
- }
1858
- const configs = [];
1859
- if (enableGitignore) if (typeof enableGitignore !== "boolean") configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
1860
- ...enableGitignore,
1861
- name: "coderwyd/gitignore"
1862
- })]));
1863
- else configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
1864
- name: "coderwyd/gitignore",
1865
- strict: false
1866
- })]));
1867
- const typescriptOptions = resolveSubOptions(options, "typescript");
1868
- const tsconfigPath = "tsconfigPath" in typescriptOptions ? typescriptOptions.tsconfigPath : void 0;
1869
- configs.push(ignores(options.ignores, !enableTypeScript), javascript({
1870
- isInEditor,
1871
- overrides: getOverrides(options, "javascript")
1872
- }), comments(), node(), jsdoc(), imports(), unicorn(), command(), deMorgan(), sortPnpmWorkspace());
1873
- if (enablePerfectionist) configs.push(perfectionist());
1874
- if (enableVue) componentExts.push("vue");
1875
- if (enableTypeScript) configs.push(typescript({
1876
- ...typescriptOptions,
1877
- componentExts,
1878
- overrides: getOverrides(options, "typescript")
1879
- }));
1880
- if (enableRegexp) configs.push(regexp(typeof enableRegexp === "boolean" ? {} : enableRegexp));
1881
- if (options.test ?? true) configs.push(test({
1882
- isInEditor,
1883
- overrides: getOverrides(options, "test")
1884
- }));
1885
- if (enableVue) configs.push(vue({
1886
- ...resolveSubOptions(options, "vue"),
1887
- overrides: getOverrides(options, "typescript"),
1888
- typescript: !!enableTypeScript
1889
- }));
1890
- if (enableReact) configs.push(react({
1891
- overrides: getOverrides(options, "react"),
1892
- tsconfigPath
1893
- }));
1894
- if (enableSvelte) configs.push(svelte({
1895
- overrides: getOverrides(options, "svelte"),
1896
- typescript: !!enableTypeScript
1897
- }));
1898
- if (enableUnoCSS) configs.push(unocss({
1899
- ...resolveSubOptions(options, "unocss"),
1900
- overrides: getOverrides(options, "unocss")
1901
- }));
1902
- if (enableTailwindCSS) configs.push(tailwindcss({
1903
- ...resolveSubOptions(options, "tailwindcss"),
1904
- overrides: getOverrides(options, "tailwindcss")
1905
- }));
1906
- if (options.jsonc ?? true) {
1907
- configs.push(jsonc({ overrides: getOverrides(options, "jsonc") }), sortTsconfig());
1908
- if (!isUsingOxfmt) configs.push(sortPackageJson());
100
+ function defineConfig(options, ...userConfigs) {
101
+ const { tailwindcss: enableTailwindcss, ...antfuOptions } = options || {};
102
+ const configs = antfu(mergeOptions(antfuOptions));
103
+ if (enableTailwindcss) {
104
+ const tailwindOptions = typeof enableTailwindcss === "boolean" ? {} : enableTailwindcss;
105
+ configs.append(tailwindcss(tailwindOptions)).renamePlugins({ "better-tailwindcss": "tailwindcss" });
1909
106
  }
1910
- if (enableCatalogs) configs.push(pnpm());
1911
- if (options.yaml ?? true) configs.push(yaml({ overrides: getOverrides(options, "yaml") }));
1912
- configs.push(specials(), prettier());
1913
- if ("files" in options) throw new Error("[@coderwyd/eslint-config] The first argument should not contain the \"files\" property as the options are supposed to be global. Place it in the second or later config instead.");
1914
- const fusedConfig = flatConfigProps.reduce((acc, key) => {
1915
- if (key in options) acc[key] = options[key];
1916
- return acc;
1917
- }, {});
1918
- if (Object.keys(fusedConfig).length > 0) configs.push([fusedConfig]);
1919
- const merged = await combine(...configs, ...userConfigs);
1920
- if (autoRenamePlugins) return renamePluginInConfigs(merged, defaultPluginRenaming);
1921
- return merged;
107
+ configs.append(...userConfigs);
108
+ return configs;
1922
109
  }
1923
-
1924
110
  //#endregion
1925
- export { combine, defaultPluginRenaming, defineConfig, ensurePackages, getOverrides, interopDefault, isInEditorEnv, isInGitHooksOrLintStaged, renamePluginInConfigs, renameRules, resolveSubOptions, toArray };
111
+ export { defineConfig };