@infernodesign/eslint-config 1.2.2 → 1.2.3

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/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.js ADDED
@@ -0,0 +1,340 @@
1
+ import process from "node:process";
2
+ import * as p from "@clack/prompts";
3
+ import c, { green } from "ansis";
4
+ import { cac } from "cac";
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import fsp from "node:fs/promises";
8
+ import parse from "parse-gitignore";
9
+ import { execSync } from "node:child_process";
10
+
11
+ //#region package.json
12
+ var version = "1.2.3";
13
+
14
+ //#endregion
15
+ //#region src/cli/constants.ts
16
+ const vscodeSettingsString = `
17
+ // Disable the default formatter, use eslint instead
18
+ "prettier.enable": false,
19
+ "editor.formatOnSave": false,
20
+
21
+ // Auto fix
22
+ "editor.codeActionsOnSave": {
23
+ "source.fixAll.eslint": "explicit",
24
+ "source.organizeImports": "never"
25
+ },
26
+
27
+ // Silent the stylistic rules in you IDE, but still auto fix them
28
+ "eslint.rules.customizations": [
29
+ { "rule": "style/*", "severity": "off", "fixable": true },
30
+ { "rule": "format/*", "severity": "off", "fixable": true },
31
+ { "rule": "*-indent", "severity": "off", "fixable": true },
32
+ { "rule": "*-spacing", "severity": "off", "fixable": true },
33
+ { "rule": "*-spaces", "severity": "off", "fixable": true },
34
+ { "rule": "*-order", "severity": "off", "fixable": true },
35
+ { "rule": "*-dangle", "severity": "off", "fixable": true },
36
+ { "rule": "*-newline", "severity": "off", "fixable": true },
37
+ { "rule": "*quotes", "severity": "off", "fixable": true },
38
+ { "rule": "*semi", "severity": "off", "fixable": true }
39
+ ],
40
+
41
+ // Enable eslint for all supported languages
42
+ "eslint.validate": [
43
+ "javascript",
44
+ "javascriptreact",
45
+ "typescript",
46
+ "typescriptreact",
47
+ "vue",
48
+ "html",
49
+ "markdown",
50
+ "json",
51
+ "json5",
52
+ "jsonc",
53
+ "yaml",
54
+ "toml",
55
+ "xml",
56
+ "gql",
57
+ "graphql",
58
+ "astro",
59
+ "svelte",
60
+ "css",
61
+ "less",
62
+ "scss",
63
+ "pcss",
64
+ "postcss"
65
+ ]
66
+ `;
67
+ const frameworkOptions = [
68
+ {
69
+ label: c.green("Vue"),
70
+ value: "vue"
71
+ },
72
+ {
73
+ label: c.cyan("React"),
74
+ value: "react"
75
+ },
76
+ {
77
+ label: c.red("Svelte"),
78
+ value: "svelte"
79
+ },
80
+ {
81
+ label: c.magenta("Astro"),
82
+ value: "astro"
83
+ },
84
+ {
85
+ label: c.cyan("Solid"),
86
+ value: "solid"
87
+ },
88
+ {
89
+ label: c.blue("Slidev"),
90
+ value: "slidev"
91
+ }
92
+ ];
93
+ const frameworks = frameworkOptions.map(({ value }) => value);
94
+ const extraOptions = [{
95
+ hint: "Use external formatters (Prettier and/or dprint) to format files that ESLint cannot handle yet (.css, .html, etc)",
96
+ label: c.red("Formatter"),
97
+ value: "formatter"
98
+ }, {
99
+ label: c.cyan("UnoCSS"),
100
+ value: "unocss"
101
+ }];
102
+ const extra = extraOptions.map(({ value }) => value);
103
+ const dependenciesMap = {
104
+ astro: ["eslint-plugin-astro", "astro-eslint-parser"],
105
+ formatter: ["eslint-plugin-format"],
106
+ formatterAstro: ["prettier-plugin-astro"],
107
+ nextjs: ["@next/eslint-plugin-next"],
108
+ react: [
109
+ "@eslint-react/eslint-plugin",
110
+ "eslint-plugin-react-hooks",
111
+ "eslint-plugin-react-refresh"
112
+ ],
113
+ slidev: ["prettier-plugin-slidev"],
114
+ solid: ["eslint-plugin-solid"],
115
+ svelte: ["eslint-plugin-svelte", "svelte-eslint-parser"],
116
+ unocss: ["@unocss/eslint-plugin"],
117
+ vue: []
118
+ };
119
+
120
+ //#endregion
121
+ //#region src/cli/utils.ts
122
+ function getEslintConfigContent(mainConfig, additionalConfigs) {
123
+ return `
124
+ import antfu from '@infernodesign/eslint-config'
125
+
126
+ export default antfu({
127
+ ${mainConfig}
128
+ }${additionalConfigs?.map((config) => `,{\n${config}\n}`)})
129
+ `.trimStart();
130
+ }
131
+ function isGitClean() {
132
+ try {
133
+ execSync("git diff-index --quiet HEAD --");
134
+ return true;
135
+ } catch {
136
+ return false;
137
+ }
138
+ }
139
+
140
+ //#endregion
141
+ //#region src/cli/stages/update-eslint-files.ts
142
+ async function updateEslintFiles(result) {
143
+ const cwd = process.cwd();
144
+ const pathESLintIgnore = path.join(cwd, ".eslintignore");
145
+ const pathPackageJSON = path.join(cwd, "package.json");
146
+ const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
147
+ const configFileName = JSON.parse(pkgContent).type === "module" ? "eslint.config.js" : "eslint.config.mjs";
148
+ const pathFlatConfig = path.join(cwd, configFileName);
149
+ const eslintIgnores = [];
150
+ if (fs.existsSync(pathESLintIgnore)) {
151
+ p.log.step(c.cyan`Migrating existing .eslintignore`);
152
+ const globs = parse(await fsp.readFile(pathESLintIgnore, "utf-8")).globs();
153
+ for (const glob of globs) if (glob.type === "ignore") eslintIgnores.push(...glob.patterns);
154
+ else if (glob.type === "unignore") eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
155
+ }
156
+ const configLines = [];
157
+ if (eslintIgnores.length) configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
158
+ if (result.extra.includes("formatter")) configLines.push("formatters: true,");
159
+ if (result.extra.includes("unocss")) configLines.push("unocss: true,");
160
+ for (const framework of result.frameworks) configLines.push(`${framework}: true,`);
161
+ const eslintConfigContent = getEslintConfigContent(configLines.map((i) => ` ${i}`).join("\n"), []);
162
+ await fsp.writeFile(pathFlatConfig, eslintConfigContent);
163
+ p.log.success(c.green`Created ${configFileName}`);
164
+ const files = fs.readdirSync(cwd);
165
+ const legacyConfig = [];
166
+ files.forEach((file) => {
167
+ if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file)) legacyConfig.push(file);
168
+ });
169
+ if (legacyConfig.length) p.note(c.dim(legacyConfig.join(", ")), "You can now remove those files manually");
170
+ }
171
+
172
+ //#endregion
173
+ //#region src/cli/constants-generated.ts
174
+ const versionsMap = {
175
+ "@eslint-react/eslint-plugin": "^2.2.2",
176
+ "@next/eslint-plugin-next": "^15.5.5",
177
+ "@unocss/eslint-plugin": "^66.5.3",
178
+ "astro-eslint-parser": "^1.2.2",
179
+ "eslint": "^9.37.0",
180
+ "eslint-plugin-astro": "^1.3.1",
181
+ "eslint-plugin-format": "^1.0.2",
182
+ "eslint-plugin-react-hooks": "^7.0.0",
183
+ "eslint-plugin-react-refresh": "^0.4.23",
184
+ "eslint-plugin-solid": "^0.14.5",
185
+ "eslint-plugin-svelte": "^3.12.4",
186
+ "prettier-plugin-astro": "^0.14.1",
187
+ "prettier-plugin-slidev": "^1.0.5",
188
+ "svelte-eslint-parser": "^1.3.3"
189
+ };
190
+
191
+ //#endregion
192
+ //#region src/cli/stages/update-package-json.ts
193
+ async function updatePackageJson(result) {
194
+ const cwd = process.cwd();
195
+ const pathPackageJSON = path.join(cwd, "package.json");
196
+ p.log.step(c.cyan`Bumping @infernodesign/eslint-config to v${version}`);
197
+ const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
198
+ const pkg = JSON.parse(pkgContent);
199
+ pkg.devDependencies ??= {};
200
+ pkg.devDependencies["@infernodesign/eslint-config"] = `^${version}`;
201
+ pkg.devDependencies.eslint ??= versionsMap.eslint;
202
+ const addedPackages = [];
203
+ if (result.extra.length) result.extra.forEach((item) => {
204
+ switch (item) {
205
+ case "formatter":
206
+ [...dependenciesMap.formatter, ...result.frameworks.includes("astro") ? dependenciesMap.formatterAstro : []].forEach((f) => {
207
+ if (!f) return;
208
+ pkg.devDependencies[f] = versionsMap[f];
209
+ addedPackages.push(f);
210
+ });
211
+ break;
212
+ case "unocss":
213
+ dependenciesMap.unocss.forEach((f) => {
214
+ pkg.devDependencies[f] = versionsMap[f];
215
+ addedPackages.push(f);
216
+ });
217
+ break;
218
+ }
219
+ });
220
+ for (const framework of result.frameworks) {
221
+ const deps = dependenciesMap[framework];
222
+ if (deps) deps.forEach((f) => {
223
+ pkg.devDependencies[f] = versionsMap[f];
224
+ addedPackages.push(f);
225
+ });
226
+ }
227
+ if (addedPackages.length) p.note(c.dim(addedPackages.join(", ")), "Added packages");
228
+ await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
229
+ p.log.success(c.green`Changes wrote to package.json`);
230
+ }
231
+
232
+ //#endregion
233
+ //#region src/cli/stages/update-vscode-settings.ts
234
+ async function updateVscodeSettings(result) {
235
+ const cwd = process.cwd();
236
+ if (!result.updateVscodeSettings) return;
237
+ const dotVscodePath = path.join(cwd, ".vscode");
238
+ const settingsPath = path.join(dotVscodePath, "settings.json");
239
+ if (!fs.existsSync(dotVscodePath)) await fsp.mkdir(dotVscodePath, { recursive: true });
240
+ if (!fs.existsSync(settingsPath)) {
241
+ await fsp.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf-8");
242
+ p.log.success(green`Created .vscode/settings.json`);
243
+ } else {
244
+ let settingsContent = await fsp.readFile(settingsPath, "utf8");
245
+ settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
246
+ settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
247
+ settingsContent += `${vscodeSettingsString}}\n`;
248
+ await fsp.writeFile(settingsPath, settingsContent, "utf-8");
249
+ p.log.success(green`Updated .vscode/settings.json`);
250
+ }
251
+ }
252
+
253
+ //#endregion
254
+ //#region src/cli/run.ts
255
+ async function run(options = {}) {
256
+ const argSkipPrompt = !!process.env.SKIP_PROMPT || options.yes;
257
+ const argTemplate = options.frameworks?.map((m) => m?.trim()).filter(Boolean);
258
+ const argExtra = options.extra?.map((m) => m?.trim()).filter(Boolean);
259
+ if (fs.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
260
+ p.log.warn(c.yellow`eslint.config.js already exists, migration wizard exited.`);
261
+ return process.exit(1);
262
+ }
263
+ let result = {
264
+ extra: argExtra ?? [],
265
+ frameworks: argTemplate ?? [],
266
+ uncommittedConfirmed: false,
267
+ updateVscodeSettings: true
268
+ };
269
+ if (!argSkipPrompt) {
270
+ result = await p.group({
271
+ uncommittedConfirmed: () => {
272
+ if (argSkipPrompt || isGitClean()) return Promise.resolve(true);
273
+ return p.confirm({
274
+ initialValue: false,
275
+ message: "There are uncommitted changes in the current repository, are you sure to continue?"
276
+ });
277
+ },
278
+ frameworks: ({ results }) => {
279
+ const isArgTemplateValid = typeof argTemplate === "string" && !!frameworks.includes(argTemplate);
280
+ if (!results.uncommittedConfirmed || isArgTemplateValid) return;
281
+ const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
282
+ return p.multiselect({
283
+ message: c.reset(message),
284
+ options: frameworkOptions,
285
+ required: false
286
+ });
287
+ },
288
+ extra: ({ results }) => {
289
+ const isArgExtraValid = argExtra?.length && !argExtra.filter((element) => !extra.includes(element)).length;
290
+ if (!results.uncommittedConfirmed || isArgExtraValid) return;
291
+ const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
292
+ return p.multiselect({
293
+ message: c.reset(message),
294
+ options: extraOptions,
295
+ required: false
296
+ });
297
+ },
298
+ updateVscodeSettings: ({ results }) => {
299
+ if (!results.uncommittedConfirmed) return;
300
+ return p.confirm({
301
+ initialValue: true,
302
+ message: "Update .vscode/settings.json for better VS Code experience?"
303
+ });
304
+ }
305
+ }, { onCancel: () => {
306
+ p.cancel("Operation cancelled.");
307
+ process.exit(0);
308
+ } });
309
+ if (!result.uncommittedConfirmed) return process.exit(1);
310
+ }
311
+ await updatePackageJson(result);
312
+ await updateEslintFiles(result);
313
+ await updateVscodeSettings(result);
314
+ p.log.success(c.green`Setup completed`);
315
+ p.outro(`Now you can update the dependencies by run ${c.blue("pnpm install")} and run ${c.blue("eslint --fix")}\n`);
316
+ }
317
+
318
+ //#endregion
319
+ //#region src/cli/index.ts
320
+ function header() {
321
+ console.log("\n");
322
+ p.intro(`${c.green`@infernodesign/eslint-config `}${c.dim`v${version}`}`);
323
+ }
324
+ const cli = cac("@infernodesign/eslint-config");
325
+ cli.command("", "Run the initialization or migration").option("--yes, -y", "Skip prompts and use default values", { default: false }).option("--template, -t <template>", "Use the framework template for optimal customization: vue / react / svelte / astro", { type: [] }).option("--extra, -e <extra>", "Use the extra utils: formatter / perfectionist / unocss", { type: [] }).action(async (args) => {
326
+ header();
327
+ try {
328
+ await run(args);
329
+ } catch (error) {
330
+ p.log.error(c.inverse.red(" Failed to migrate "));
331
+ p.log.error(c.red`✘ ${String(error)}`);
332
+ process.exit(1);
333
+ }
334
+ });
335
+ cli.help();
336
+ cli.version(version);
337
+ cli.parse();
338
+
339
+ //#endregion
340
+ export { };
package/dist/index.d.ts CHANGED
@@ -5261,7 +5261,7 @@ interface RuleOptions {
5261
5261
  */
5262
5262
  'template-tag-spacing'?: Linter.RuleEntry<TemplateTagSpacing>;
5263
5263
  /**
5264
- * require .spec test file pattern
5264
+ * require test file pattern
5265
5265
  * @see https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/consistent-test-filename.md
5266
5266
  */
5267
5267
  'test/consistent-test-filename'?: Linter.RuleEntry<TestConsistentTestFilename>;
@@ -13412,7 +13412,6 @@ type ReactNoForbiddenProps = [] | [{
13412
13412
  includedNodes?: string[];
13413
13413
  prop: string;
13414
13414
  })[];
13415
- [k: string]: unknown | undefined;
13416
13415
  }];
13417
13416
  // ----- react/no-useless-fragment -----
13418
13417
  type ReactNoUselessFragment = [] | [{
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
+ import process from "node:process";
1
2
  import { FlatConfigComposer } from "eslint-flat-config-utils";
2
3
  import { isPackageExists } from "local-pkg";
3
- import process from "node:process";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import createCommand from "eslint-plugin-command/config";
6
6
  import pluginComments from "@eslint-community/eslint-plugin-eslint-comments";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@infernodesign/eslint-config",
3
3
  "description": "ESLint config for Inferno Design.",
4
- "version": "1.2.2",
4
+ "version": "1.2.3",
5
5
  "type": "module",
6
6
  "author": "Inferno Design <support@infernodesign.com>",
7
7
  "license": "MIT",
@@ -40,9 +40,9 @@
40
40
  "@eslint-community/eslint-plugin-eslint-comments": "^4.5.0",
41
41
  "@eslint/markdown": "^7.4.0",
42
42
  "@stylistic/eslint-plugin": "^5.4.0",
43
- "@typescript-eslint/eslint-plugin": "^8.46.0",
44
- "@typescript-eslint/parser": "^8.46.0",
45
- "@vitest/eslint-plugin": "^1.3.17",
43
+ "@typescript-eslint/eslint-plugin": "^8.46.1",
44
+ "@typescript-eslint/parser": "^8.46.1",
45
+ "@vitest/eslint-plugin": "^1.3.20",
46
46
  "ansis": "^4.2.0",
47
47
  "cac": "^6.7.14",
48
48
  "eslint-config-flat-gitignore": "^2.1.0",
@@ -51,7 +51,7 @@
51
51
  "eslint-plugin-antfu": "^3.1.1",
52
52
  "eslint-plugin-command": "^3.3.1",
53
53
  "eslint-plugin-import-lite": "^0.3.0",
54
- "eslint-plugin-jsdoc": "^61.1.1",
54
+ "eslint-plugin-jsdoc": "^61.1.2",
55
55
  "eslint-plugin-jsonc": "^2.21.0",
56
56
  "eslint-plugin-n": "^17.23.1",
57
57
  "eslint-plugin-no-only-tests": "^3.3.0",
@@ -73,9 +73,9 @@
73
73
  "yaml-eslint-parser": "^1.3.0"
74
74
  },
75
75
  "devDependencies": {
76
- "@eslint-react/eslint-plugin": "^2.0.6",
76
+ "@eslint-react/eslint-plugin": "^2.2.2",
77
77
  "@eslint/config-inspector": "^1.3.0",
78
- "@next/eslint-plugin-next": "^15.5.4",
78
+ "@next/eslint-plugin-next": "^15.5.5",
79
79
  "@prettier/plugin-xml": "^3.4.2",
80
80
  "@types/eslint-plugin-jsx-a11y": "^6.10.1",
81
81
  "@types/node": "^24.7.2",
@@ -100,19 +100,19 @@
100
100
  "prettier-plugin-astro": "^0.14.1",
101
101
  "prettier-plugin-slidev": "^1.0.5",
102
102
  "simple-git-hooks": "^2.13.1",
103
- "svelte": "^5.39.11",
103
+ "svelte": "^5.40.0",
104
104
  "svelte-eslint-parser": "^1.3.3",
105
105
  "tinyglobby": "^0.2.15",
106
- "tsdown": "^0.15.6",
106
+ "tsdown": "^0.15.7",
107
107
  "tsx": "^4.20.6",
108
108
  "typescript": "^5.9.3",
109
109
  "vitest": "^3.2.4",
110
110
  "vue": "^3.5.22",
111
- "@infernodesign/typescript-config": "1.0.0"
111
+ "@infernodesign/typescript-config": "1.1.0"
112
112
  },
113
113
  "peerDependencies": {
114
- "@eslint-react/eslint-plugin": "^2.0.6",
115
- "@next/eslint-plugin-next": "^15.5.4",
114
+ "@eslint-react/eslint-plugin": "^2.2.2",
115
+ "@next/eslint-plugin-next": "^15.5.5",
116
116
  "@prettier/plugin-xml": "^3.4.2",
117
117
  "@unocss/eslint-plugin": "^66.5.3",
118
118
  "astro-eslint-parser": "^1.2.2",