@coderwyd/eslint-config 4.3.0 → 4.4.1

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.
Files changed (4) hide show
  1. package/dist/cli.js +11 -12
  2. package/dist/index.d.ts +189 -517
  3. package/dist/index.js +116 -117
  4. package/package.json +23 -25
package/dist/index.js CHANGED
@@ -3,14 +3,13 @@ import createCommand from "eslint-plugin-command/config";
3
3
  import pluginComments from "@eslint-community/eslint-plugin-eslint-comments";
4
4
  import pluginAntfu from "eslint-plugin-antfu";
5
5
  import pluginDeMorgan from "eslint-plugin-de-morgan";
6
- import * as pluginImport from "eslint-plugin-import-x";
7
6
  import pluginNode from "eslint-plugin-n";
8
7
  import pluginPerfectionist from "eslint-plugin-perfectionist";
9
8
  import pluginUnicorn from "eslint-plugin-unicorn";
10
9
  import pluginUnusedImports from "eslint-plugin-unused-imports";
11
- import globals from "globals";
12
10
  import { fileURLToPath } from "node:url";
13
11
  import { getPackageInfoSync, isPackageExists } from "local-pkg";
12
+ import globals from "globals";
14
13
  import prettierRules from "eslint-config-prettier";
15
14
  import { configs } from "eslint-plugin-regexp";
16
15
 
@@ -116,9 +115,113 @@ function ignores(userIgnores = []) {
116
115
  }];
117
116
  }
118
117
 
118
+ //#endregion
119
+ //#region src/shared/index.ts
120
+ const scopeUrl = fileURLToPath(new URL(".", import.meta.url));
121
+ const isCwdInScope = isPackageExists("@coderwyd/eslint-config");
122
+ /**
123
+ * Combine array and non-array configs into a single array.
124
+ */
125
+ async function combine(...configs$1) {
126
+ const resolved = await Promise.all(configs$1);
127
+ return resolved.flat();
128
+ }
129
+ /**
130
+ * Rename plugin prefixes in a rule object.
131
+ * Accepts a map of prefixes to rename.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * import { renameRules } from '@coderwyd/eslint-config'
136
+ *
137
+ * export default [{
138
+ * rules: renameRules(
139
+ * {
140
+ * '@typescript-eslint/indent': 'error'
141
+ * },
142
+ * { '@typescript-eslint': 'ts' }
143
+ * )
144
+ * }]
145
+ * ```
146
+ */
147
+ function renameRules(rules, map) {
148
+ return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
149
+ for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
150
+ return [key, value];
151
+ }));
152
+ }
153
+ /**
154
+ * Rename plugin names a flat configs array
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * import { renamePluginInConfigs } from '@antfu/eslint-config'
159
+ * import someConfigs from './some-configs'
160
+ *
161
+ * export default renamePluginInConfigs(someConfigs, {
162
+ * '@typescript-eslint': 'ts',
163
+ * 'import-x': 'import',
164
+ * })
165
+ * ```
166
+ */
167
+ function renamePluginInConfigs(configs$1, map) {
168
+ return configs$1.map((i) => {
169
+ const clone = { ...i };
170
+ if (clone.rules) clone.rules = renameRules(clone.rules, map);
171
+ if (clone.plugins) clone.plugins = Object.fromEntries(Object.entries(clone.plugins).map(([key, value]) => {
172
+ if (key in map) return [map[key], value];
173
+ return [key, value];
174
+ }));
175
+ return clone;
176
+ });
177
+ }
178
+ function getVueVersion() {
179
+ const pkg = getPackageInfoSync("vue", { paths: [process.cwd()] });
180
+ if (pkg && typeof pkg.version === "string" && !Number.isNaN(+pkg.version[0])) return +pkg.version[0];
181
+ return 3;
182
+ }
183
+ function toArray(value) {
184
+ return Array.isArray(value) ? value : [value];
185
+ }
186
+ async function interopDefault(m) {
187
+ const resolved = await m;
188
+ return resolved.default || resolved;
189
+ }
190
+ function isPackageInScope(name) {
191
+ return isPackageExists(name, { paths: [scopeUrl] });
192
+ }
193
+ async function ensurePackages(packages) {
194
+ if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false) return;
195
+ const nonExistingPackages = packages.filter((i) => !isPackageInScope(i));
196
+ if (nonExistingPackages.length === 0) return;
197
+ const { default: prompts } = await import("prompts");
198
+ const { result } = await prompts([{
199
+ message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(", ")}. Do you want to install them?`,
200
+ name: "result",
201
+ type: "confirm"
202
+ }]);
203
+ if (result) await import("@antfu/install-pkg").then((i) => i.installPackage(nonExistingPackages, { dev: true }));
204
+ }
205
+ function resolveSubOptions(options, key) {
206
+ return typeof options[key] === "boolean" ? {} : options[key] || {};
207
+ }
208
+ function getOverrides(options, key) {
209
+ const subOptions = resolveSubOptions(options, key);
210
+ return { ..."overrides" in subOptions && subOptions.overrides ? subOptions.overrides : {} };
211
+ }
212
+ function isInEditorEnv() {
213
+ if (process.env.CI) return false;
214
+ if (isInGitHooksOrLintStaged()) return false;
215
+ return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM || false);
216
+ }
217
+ function isInGitHooksOrLintStaged() {
218
+ 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);
219
+ }
220
+
119
221
  //#endregion
120
222
  //#region src/configs/imports.ts
121
- function imports() {
223
+ async function imports() {
224
+ const pluginImport = await interopDefault(import("eslint-plugin-import-lite"));
122
225
  return [{
123
226
  name: "coderwyd/imports/rules",
124
227
  plugins: {
@@ -134,9 +237,7 @@ function imports() {
134
237
  "import/newline-after-import": ["error", { count: 1 }],
135
238
  "import/no-duplicates": "error",
136
239
  "import/no-mutable-exports": "error",
137
- "import/no-named-default": "error",
138
- "import/no-self-import": "error",
139
- "import/no-webpack-loader-syntax": "error"
240
+ "import/no-named-default": "error"
140
241
  }
141
242
  }];
142
243
  }
@@ -365,109 +466,6 @@ function javascript(options = {}) {
365
466
  }];
366
467
  }
367
468
 
368
- //#endregion
369
- //#region src/shared/index.ts
370
- const scopeUrl = fileURLToPath(new URL(".", import.meta.url));
371
- const isCwdInScope = isPackageExists("@coderwyd/eslint-config");
372
- /**
373
- * Combine array and non-array configs into a single array.
374
- */
375
- async function combine(...configs$1) {
376
- const resolved = await Promise.all(configs$1);
377
- return resolved.flat();
378
- }
379
- /**
380
- * Rename plugin prefixes in a rule object.
381
- * Accepts a map of prefixes to rename.
382
- *
383
- * @example
384
- * ```ts
385
- * import { renameRules } from '@coderwyd/eslint-config'
386
- *
387
- * export default [{
388
- * rules: renameRules(
389
- * {
390
- * '@typescript-eslint/indent': 'error'
391
- * },
392
- * { '@typescript-eslint': 'ts' }
393
- * )
394
- * }]
395
- * ```
396
- */
397
- function renameRules(rules, map) {
398
- return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
399
- for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
400
- return [key, value];
401
- }));
402
- }
403
- /**
404
- * Rename plugin names a flat configs array
405
- *
406
- * @example
407
- * ```ts
408
- * import { renamePluginInConfigs } from '@antfu/eslint-config'
409
- * import someConfigs from './some-configs'
410
- *
411
- * export default renamePluginInConfigs(someConfigs, {
412
- * '@typescript-eslint': 'ts',
413
- * 'import-x': 'import',
414
- * })
415
- * ```
416
- */
417
- function renamePluginInConfigs(configs$1, map) {
418
- return configs$1.map((i) => {
419
- const clone = { ...i };
420
- if (clone.rules) clone.rules = renameRules(clone.rules, map);
421
- if (clone.plugins) clone.plugins = Object.fromEntries(Object.entries(clone.plugins).map(([key, value]) => {
422
- if (key in map) return [map[key], value];
423
- return [key, value];
424
- }));
425
- return clone;
426
- });
427
- }
428
- function getVueVersion() {
429
- const pkg = getPackageInfoSync("vue", { paths: [process.cwd()] });
430
- if (pkg && typeof pkg.version === "string" && !Number.isNaN(+pkg.version[0])) return +pkg.version[0];
431
- return 3;
432
- }
433
- function toArray(value) {
434
- return Array.isArray(value) ? value : [value];
435
- }
436
- async function interopDefault(m) {
437
- const resolved = await m;
438
- return resolved.default || resolved;
439
- }
440
- function isPackageInScope(name) {
441
- return isPackageExists(name, { paths: [scopeUrl] });
442
- }
443
- async function ensurePackages(packages) {
444
- if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false) return;
445
- const nonExistingPackages = packages.filter((i) => !isPackageInScope(i));
446
- if (nonExistingPackages.length === 0) return;
447
- const { default: prompts } = await import("prompts");
448
- const { result } = await prompts([{
449
- message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(", ")}. Do you want to install them?`,
450
- name: "result",
451
- type: "confirm"
452
- }]);
453
- if (result) await import("@antfu/install-pkg").then((i) => i.installPackage(nonExistingPackages, { dev: true }));
454
- }
455
- function resolveSubOptions(options, key) {
456
- return typeof options[key] === "boolean" ? {} : options[key] || {};
457
- }
458
- function getOverrides(options, key) {
459
- const subOptions = resolveSubOptions(options, key);
460
- return { ..."overrides" in subOptions && subOptions.overrides ? subOptions.overrides : {} };
461
- }
462
- function isInEditorEnv() {
463
- if (process.env.CI) return false;
464
- if (isInGitHooksOrLintStaged()) return false;
465
- return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM || false);
466
- }
467
- function isInGitHooksOrLintStaged() {
468
- 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);
469
- }
470
-
471
469
  //#endregion
472
470
  //#region src/configs/jsdoc.ts
473
471
  async function jsdoc() {
@@ -677,11 +675,10 @@ async function react(options = {}) {
677
675
  ]);
678
676
  const isTypeAware = !!tsconfigPath;
679
677
  const typeAwareRules = { "react/no-leaked-conditional-rendering": "warn" };
680
- const [pluginReact, pluginReactHooks, pluginReactRefresh, pluginReactCompiler] = await Promise.all([
678
+ const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all([
681
679
  interopDefault(import("@eslint-react/eslint-plugin")),
682
680
  interopDefault(import("eslint-plugin-react-hooks")),
683
- interopDefault(import("eslint-plugin-react-refresh")),
684
- interopDefault(import("eslint-plugin-react-compiler"))
681
+ interopDefault(import("eslint-plugin-react-refresh"))
685
682
  ]);
686
683
  const plugins = pluginReact.configs.all.plugins;
687
684
  return [
@@ -689,7 +686,6 @@ async function react(options = {}) {
689
686
  name: "coderwyd/react/setup",
690
687
  plugins: {
691
688
  react: plugins["@eslint-react"],
692
- "react-compiler": pluginReactCompiler,
693
689
  "react-dom": plugins["@eslint-react/dom"],
694
690
  "react-hooks": pluginReactHooks,
695
691
  "react-hooks-extra": plugins["@eslint-react/hooks-extra"],
@@ -706,7 +702,6 @@ async function react(options = {}) {
706
702
  },
707
703
  name: "coderwyd/react/rules",
708
704
  rules: {
709
- "react-compiler/react-compiler": "warn",
710
705
  "react/no-access-state-in-setstate": "error",
711
706
  "react/no-array-index-key": "warn",
712
707
  "react/no-children-count": "warn",
@@ -762,6 +757,7 @@ async function react(options = {}) {
762
757
  "react-dom/no-void-elements-with-children": "error",
763
758
  "react-hooks/exhaustive-deps": "warn",
764
759
  "react-hooks/rules-of-hooks": "error",
760
+ "react-hooks/react-compiler": "warn",
765
761
  "react-hooks-extra/no-direct-set-state-in-use-effect": "warn",
766
762
  "react-hooks-extra/no-unnecessary-use-prefix": "warn",
767
763
  "react-web-api/no-leaked-event-listener": "warn",
@@ -859,6 +855,7 @@ function sortPackageJson() {
859
855
  "keywords",
860
856
  "categories",
861
857
  "sideEffects",
858
+ "imports",
862
859
  "exports",
863
860
  "main",
864
861
  "module",
@@ -1354,7 +1351,8 @@ async function typescript(options = {}) {
1354
1351
 
1355
1352
  //#endregion
1356
1353
  //#region src/configs/unicorn.ts
1357
- function unicorn() {
1354
+ function unicorn(options = {}) {
1355
+ const { overrides = {} } = options;
1358
1356
  return [{
1359
1357
  name: "coderwyd/unicorn/rules",
1360
1358
  plugins: { unicorn: pluginUnicorn },
@@ -1415,7 +1413,8 @@ function unicorn() {
1415
1413
  "unicorn/prefer-string-starts-ends-with": "error",
1416
1414
  "unicorn/prefer-string-trim-start-end": "error",
1417
1415
  "unicorn/prefer-type-error": "error",
1418
- "unicorn/throw-new-error": "error"
1416
+ "unicorn/throw-new-error": "error",
1417
+ ...overrides
1419
1418
  }
1420
1419
  }];
1421
1420
  }
@@ -1645,7 +1644,7 @@ const defaultPluginRenaming = {
1645
1644
  "@eslint-react/hooks-extra": "react-hooks-extra",
1646
1645
  "@eslint-react/naming-convention": "react-naming-convention",
1647
1646
  "@typescript-eslint": "ts",
1648
- "import-x": "import",
1647
+ "import-lite": "import",
1649
1648
  n: "node",
1650
1649
  vitest: "test",
1651
1650
  yml: "yaml"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coderwyd/eslint-config",
3
3
  "type": "module",
4
- "version": "4.3.0",
4
+ "version": "4.4.1",
5
5
  "description": "Donny's ESLint config",
6
6
  "author": "Donny Wang <donny526@outlook.com> (https://github.com/coderwyd/)",
7
7
  "license": "MIT",
@@ -36,7 +36,6 @@
36
36
  "@eslint-react/eslint-plugin": "^1.5.8",
37
37
  "@unocss/eslint-plugin": ">=0.50.0",
38
38
  "eslint": "^9.5.0",
39
- "eslint-plugin-react-compiler": "^19.0.0-beta-decd7b8-20250118",
40
39
  "eslint-plugin-react-hooks": "^4.6.0 || ^5.0.0",
41
40
  "eslint-plugin-react-refresh": "^0.4.4",
42
41
  "eslint-plugin-svelte": ">=2.35.1",
@@ -72,25 +71,25 @@
72
71
  "dependencies": {
73
72
  "@antfu/install-pkg": "^1.1.0",
74
73
  "@eslint-community/eslint-plugin-eslint-comments": "^4.5.0",
75
- "@typescript-eslint/eslint-plugin": "^8.33.0",
76
- "@typescript-eslint/parser": "^8.33.0",
77
- "@vitest/eslint-plugin": "^1.2.1",
74
+ "@typescript-eslint/eslint-plugin": "^8.34.1",
75
+ "@typescript-eslint/parser": "^8.34.1",
76
+ "@vitest/eslint-plugin": "^1.2.7",
78
77
  "eslint-config-flat-gitignore": "^2.1.0",
79
78
  "eslint-config-prettier": "^10.1.5",
80
79
  "eslint-plugin-antfu": "^3.1.1",
81
- "eslint-plugin-command": "^3.2.1",
82
- "eslint-plugin-de-morgan": "^1.2.1",
80
+ "eslint-plugin-command": "^3.3.1",
81
+ "eslint-plugin-de-morgan": "^1.3.0",
83
82
  "eslint-plugin-eslint-comments": "^3.2.0",
84
- "eslint-plugin-import-x": "^4.13.3",
85
- "eslint-plugin-jsdoc": "^50.6.17",
83
+ "eslint-plugin-import-lite": "^0.3.0",
84
+ "eslint-plugin-jsdoc": "^51.2.1",
86
85
  "eslint-plugin-jsonc": "^2.20.1",
87
- "eslint-plugin-n": "^17.18.0",
86
+ "eslint-plugin-n": "^17.20.0",
88
87
  "eslint-plugin-no-only-tests": "^3.3.0",
89
- "eslint-plugin-perfectionist": "^4.13.0",
90
- "eslint-plugin-regexp": "^2.7.0",
88
+ "eslint-plugin-perfectionist": "^4.15.0",
89
+ "eslint-plugin-regexp": "^2.9.0",
91
90
  "eslint-plugin-unicorn": "^59.0.1",
92
91
  "eslint-plugin-unused-imports": "^4.1.4",
93
- "eslint-plugin-vue": "^10.1.0",
92
+ "eslint-plugin-vue": "^10.2.0",
94
93
  "eslint-plugin-yml": "^1.18.0",
95
94
  "eslint-typegen": "^2.2.0",
96
95
  "globals": "^16.2.0",
@@ -98,7 +97,7 @@
98
97
  "local-pkg": "^1.1.1",
99
98
  "parse-gitignore": "^2.0.0",
100
99
  "picocolors": "^1.1.1",
101
- "prettier": "^3.5.3",
100
+ "prettier": "^3.6.0",
102
101
  "prompts": "^2.4.2",
103
102
  "vue-eslint-parser": "^10.1.3",
104
103
  "yaml-eslint-parser": "^1.3.0",
@@ -106,26 +105,25 @@
106
105
  },
107
106
  "devDependencies": {
108
107
  "@antfu/ni": "^25.0.0",
109
- "@eslint-react/eslint-plugin": "^1.50.0",
110
- "@eslint/config-inspector": "^1.0.2",
108
+ "@eslint-react/eslint-plugin": "^1.52.2",
109
+ "@eslint/config-inspector": "^1.1.0",
111
110
  "@types/eslint-config-prettier": "^6.11.3",
112
- "@types/node": "^22.15.23",
111
+ "@types/node": "^24.0.3",
113
112
  "@types/prompts": "^2.4.9",
114
113
  "@types/yargs": "^17.0.33",
115
- "@unocss/eslint-plugin": "^66.1.2",
116
- "bumpp": "^10.1.1",
117
- "eslint": "^9.27.0",
118
- "eslint-plugin-react-compiler": "19.0.0-beta-ebf51a3-20250411",
119
- "eslint-plugin-react-hooks": "^5.2.0",
114
+ "@unocss/eslint-plugin": "^66.2.3",
115
+ "bumpp": "^10.2.0",
116
+ "eslint": "^9.29.0",
117
+ "eslint-plugin-react-hooks": "6.0.0-rc1",
120
118
  "eslint-plugin-react-refresh": "^0.4.20",
121
- "eslint-plugin-svelte": "^3.9.0",
119
+ "eslint-plugin-svelte": "^3.9.3",
122
120
  "eslint-plugin-tailwindcss": "^3.18.0",
123
121
  "jiti": "^2.4.2",
124
122
  "nano-staged": "^0.8.0",
125
123
  "simple-git-hooks": "^2.13.0",
126
- "svelte": "^5.33.4",
124
+ "svelte": "^5.34.7",
127
125
  "svelte-eslint-parser": "^1.2.0",
128
- "tsdown": "0.12.3",
126
+ "tsdown": "^0.12.8",
129
127
  "typescript": "^5.8.3"
130
128
  },
131
129
  "simple-git-hooks": {