@infernodesign/eslint-config 1.13.0 → 1.14.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/README.md +3 -3
- package/dist/cli.js +78 -68
- package/dist/index.d.ts +1598 -2106
- package/dist/index.js +386 -126
- package/package.json +102 -91
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Shared ESLint flat config presets for Inferno Design projects.
|
|
|
22
22
|
We provided a CLI tool to help you set up your project, or migrate from the legacy config to the new flat config with one command.
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
|
|
25
|
+
bunx @infernodesign/eslint-config@latest
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
### Manual Install
|
|
@@ -30,7 +30,7 @@ pnpm dlx @infernodesign/eslint-config@latest
|
|
|
30
30
|
If you prefer to set up manually:
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
|
-
|
|
33
|
+
bun add -D eslint @infernodesign/eslint-config
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
And create `eslint.config.mjs` in your project root:
|
|
@@ -716,7 +716,7 @@ If you want to apply lint and auto-fix before every commit, you can add the foll
|
|
|
716
716
|
```json
|
|
717
717
|
{
|
|
718
718
|
"simple-git-hooks": {
|
|
719
|
-
"pre-commit": "
|
|
719
|
+
"pre-commit": "bun lint-staged"
|
|
720
720
|
},
|
|
721
721
|
"lint-staged": {
|
|
722
722
|
"*": "eslint --fix"
|
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import fs$1 from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
1
4
|
import * as p from "@clack/prompts";
|
|
2
5
|
import c, { green } from "ansis";
|
|
3
6
|
import { cac } from "cac";
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import fsp from "node:fs/promises";
|
|
7
7
|
import parse from "parse-gitignore";
|
|
8
8
|
import { execSync } from "node:child_process";
|
|
9
9
|
|
|
10
10
|
//#region package.json
|
|
11
|
-
var version = "1.
|
|
11
|
+
var version = "1.14.0";
|
|
12
12
|
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/cli/constants.ts
|
|
@@ -39,54 +39,63 @@ const vscodeSettingsString = `
|
|
|
39
39
|
|
|
40
40
|
// Enable eslint for all supported languages
|
|
41
41
|
"eslint.validate": [
|
|
42
|
+
"astro",
|
|
43
|
+
"css",
|
|
44
|
+
"github-actions-workflow",
|
|
45
|
+
"gql",
|
|
46
|
+
"graphql",
|
|
47
|
+
"html",
|
|
42
48
|
"javascript",
|
|
43
49
|
"javascriptreact",
|
|
44
|
-
"typescript",
|
|
45
|
-
"typescriptreact",
|
|
46
|
-
"vue",
|
|
47
|
-
"html",
|
|
48
|
-
"markdown",
|
|
49
50
|
"json",
|
|
50
51
|
"json5",
|
|
51
52
|
"jsonc",
|
|
52
|
-
"yaml",
|
|
53
|
-
"toml",
|
|
54
|
-
"xml",
|
|
55
|
-
"gql",
|
|
56
|
-
"graphql",
|
|
57
|
-
"astro",
|
|
58
|
-
"svelte",
|
|
59
|
-
"css",
|
|
60
53
|
"less",
|
|
61
|
-
"
|
|
54
|
+
"markdown",
|
|
62
55
|
"pcss",
|
|
63
|
-
"postcss"
|
|
56
|
+
"postcss",
|
|
57
|
+
"scss",
|
|
58
|
+
"svelte",
|
|
59
|
+
"toml",
|
|
60
|
+
"typescript",
|
|
61
|
+
"typescriptreact",
|
|
62
|
+
"vue",
|
|
63
|
+
"xml",
|
|
64
|
+
"yaml"
|
|
64
65
|
]
|
|
65
66
|
`;
|
|
66
67
|
const frameworkOptions = [
|
|
67
68
|
{
|
|
68
|
-
label: c.
|
|
69
|
-
value: "
|
|
69
|
+
label: c.magenta("Astro"),
|
|
70
|
+
value: "astro"
|
|
70
71
|
},
|
|
71
72
|
{
|
|
72
|
-
label: c.
|
|
73
|
-
value: "
|
|
73
|
+
label: c.yellow("Next.js"),
|
|
74
|
+
value: "nextjs"
|
|
74
75
|
},
|
|
75
76
|
{
|
|
76
|
-
label: c.
|
|
77
|
-
value: "
|
|
77
|
+
label: c.green("Node"),
|
|
78
|
+
value: "node"
|
|
78
79
|
},
|
|
79
80
|
{
|
|
80
|
-
label: c.
|
|
81
|
-
value: "
|
|
81
|
+
label: c.cyan("React"),
|
|
82
|
+
value: "react"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
label: c.blue("Slidev"),
|
|
86
|
+
value: "slidev"
|
|
82
87
|
},
|
|
83
88
|
{
|
|
84
89
|
label: c.cyan("Solid"),
|
|
85
90
|
value: "solid"
|
|
86
91
|
},
|
|
87
92
|
{
|
|
88
|
-
label: c.
|
|
89
|
-
value: "
|
|
93
|
+
label: c.red("Svelte"),
|
|
94
|
+
value: "svelte"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
label: c.green("Vue"),
|
|
98
|
+
value: "vue"
|
|
90
99
|
}
|
|
91
100
|
];
|
|
92
101
|
const frameworks = frameworkOptions.map(({ value }) => value);
|
|
@@ -104,6 +113,7 @@ const dependenciesMap = {
|
|
|
104
113
|
formatter: ["eslint-plugin-format"],
|
|
105
114
|
formatterAstro: ["prettier-plugin-astro"],
|
|
106
115
|
nextjs: ["@next/eslint-plugin-next"],
|
|
116
|
+
node: [],
|
|
107
117
|
react: [
|
|
108
118
|
"@eslint-react/eslint-plugin",
|
|
109
119
|
"eslint-plugin-react-hooks",
|
|
@@ -124,7 +134,7 @@ import { inferno } from '@infernodesign/eslint-config'
|
|
|
124
134
|
|
|
125
135
|
export default inferno({
|
|
126
136
|
${mainConfig}
|
|
127
|
-
}${additionalConfigs?.map((config) => `,{\n${config}\n}`)})
|
|
137
|
+
}${additionalConfigs?.map((config) => `,{\n${config}\n}`).join("")})
|
|
128
138
|
`.trimStart();
|
|
129
139
|
}
|
|
130
140
|
function isGitClean() {
|
|
@@ -142,13 +152,13 @@ async function updateEslintFiles(result) {
|
|
|
142
152
|
const cwd = process.cwd();
|
|
143
153
|
const pathESLintIgnore = path.join(cwd, ".eslintignore");
|
|
144
154
|
const pathPackageJSON = path.join(cwd, "package.json");
|
|
145
|
-
const pkgContent = await
|
|
155
|
+
const pkgContent = await fs.readFile(pathPackageJSON, "utf-8");
|
|
146
156
|
const configFileName = JSON.parse(pkgContent).type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
147
157
|
const pathFlatConfig = path.join(cwd, configFileName);
|
|
148
158
|
const eslintIgnores = [];
|
|
149
|
-
if (fs.existsSync(pathESLintIgnore)) {
|
|
159
|
+
if (fs$1.existsSync(pathESLintIgnore)) {
|
|
150
160
|
p.log.step(c.cyan`Migrating existing .eslintignore`);
|
|
151
|
-
const globs = parse(await
|
|
161
|
+
const globs = parse(await fs.readFile(pathESLintIgnore, "utf-8")).globs();
|
|
152
162
|
for (const glob of globs) if (glob.type === "ignore") eslintIgnores.push(...glob.patterns);
|
|
153
163
|
else if (glob.type === "unignore") eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
|
|
154
164
|
}
|
|
@@ -158,9 +168,9 @@ async function updateEslintFiles(result) {
|
|
|
158
168
|
if (result.extra.includes("unocss")) configLines.push("unocss: true,");
|
|
159
169
|
for (const framework of result.frameworks) configLines.push(`${framework}: true,`);
|
|
160
170
|
const eslintConfigContent = getEslintConfigContent(configLines.map((i) => ` ${i}`).join("\n"), []);
|
|
161
|
-
await
|
|
171
|
+
await fs.writeFile(pathFlatConfig, eslintConfigContent);
|
|
162
172
|
p.log.success(c.green`Created ${configFileName}`);
|
|
163
|
-
const files = fs.readdirSync(cwd);
|
|
173
|
+
const files = fs$1.readdirSync(cwd);
|
|
164
174
|
const legacyConfig = [];
|
|
165
175
|
files.forEach((file) => {
|
|
166
176
|
if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file)) legacyConfig.push(file);
|
|
@@ -171,17 +181,17 @@ async function updateEslintFiles(result) {
|
|
|
171
181
|
//#endregion
|
|
172
182
|
//#region src/cli/constants-generated.ts
|
|
173
183
|
const versionsMap = {
|
|
174
|
-
"@eslint-react/eslint-plugin": "^2.
|
|
175
|
-
"@next/eslint-plugin-next": "^16.1.
|
|
176
|
-
"@unocss/eslint-plugin": "^66.
|
|
184
|
+
"@eslint-react/eslint-plugin": "^2.12.4",
|
|
185
|
+
"@next/eslint-plugin-next": "^16.1.6",
|
|
186
|
+
"@unocss/eslint-plugin": "^66.6.0",
|
|
177
187
|
"astro-eslint-parser": "^1.2.2",
|
|
178
|
-
"eslint": "^
|
|
188
|
+
"eslint": "^10.0.0",
|
|
179
189
|
"eslint-plugin-astro": "^1.5.0",
|
|
180
|
-
"eslint-plugin-format": "^1.
|
|
190
|
+
"eslint-plugin-format": "^1.4.0",
|
|
181
191
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
182
|
-
"eslint-plugin-react-refresh": "^0.
|
|
192
|
+
"eslint-plugin-react-refresh": "^0.5.0",
|
|
183
193
|
"eslint-plugin-solid": "^0.14.5",
|
|
184
|
-
"eslint-plugin-svelte": "^3.
|
|
194
|
+
"eslint-plugin-svelte": "^3.15.0",
|
|
185
195
|
"prettier-plugin-astro": "^0.14.1",
|
|
186
196
|
"prettier-plugin-slidev": "^1.0.5",
|
|
187
197
|
"svelte-eslint-parser": "^1.4.1"
|
|
@@ -193,7 +203,7 @@ async function updatePackageJson(result) {
|
|
|
193
203
|
const cwd = process.cwd();
|
|
194
204
|
const pathPackageJSON = path.join(cwd, "package.json");
|
|
195
205
|
p.log.step(c.cyan`Bumping @infernodesign/eslint-config to v${version}`);
|
|
196
|
-
const pkgContent = await
|
|
206
|
+
const pkgContent = await fs.readFile(pathPackageJSON, "utf-8");
|
|
197
207
|
const pkg = JSON.parse(pkgContent);
|
|
198
208
|
pkg.devDependencies ??= {};
|
|
199
209
|
pkg.devDependencies["@infernodesign/eslint-config"] = `^${version}`;
|
|
@@ -224,7 +234,7 @@ async function updatePackageJson(result) {
|
|
|
224
234
|
});
|
|
225
235
|
}
|
|
226
236
|
if (addedPackages.length) p.note(c.dim(addedPackages.join(", ")), "Added packages");
|
|
227
|
-
await
|
|
237
|
+
await fs.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
228
238
|
p.log.success(c.green`Changes wrote to package.json`);
|
|
229
239
|
}
|
|
230
240
|
|
|
@@ -235,16 +245,16 @@ async function updateVscodeSettings(result) {
|
|
|
235
245
|
if (!result.updateVscodeSettings) return;
|
|
236
246
|
const dotVscodePath = path.join(cwd, ".vscode");
|
|
237
247
|
const settingsPath = path.join(dotVscodePath, "settings.json");
|
|
238
|
-
if (!fs.existsSync(dotVscodePath)) await
|
|
239
|
-
if (!fs.existsSync(settingsPath)) {
|
|
240
|
-
await
|
|
248
|
+
if (!fs$1.existsSync(dotVscodePath)) await fs.mkdir(dotVscodePath, { recursive: true });
|
|
249
|
+
if (!fs$1.existsSync(settingsPath)) {
|
|
250
|
+
await fs.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf-8");
|
|
241
251
|
p.log.success(green`Created .vscode/settings.json`);
|
|
242
252
|
} else {
|
|
243
|
-
let settingsContent = await
|
|
253
|
+
let settingsContent = await fs.readFile(settingsPath, "utf8");
|
|
244
254
|
settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
|
|
245
255
|
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
246
256
|
settingsContent += `${vscodeSettingsString}}\n`;
|
|
247
|
-
await
|
|
257
|
+
await fs.writeFile(settingsPath, settingsContent, "utf-8");
|
|
248
258
|
p.log.success(green`Updated .vscode/settings.json`);
|
|
249
259
|
}
|
|
250
260
|
}
|
|
@@ -255,7 +265,7 @@ async function run(options = {}) {
|
|
|
255
265
|
const argSkipPrompt = !!process.env.SKIP_PROMPT || options.yes;
|
|
256
266
|
const argTemplate = options.frameworks?.map((m) => m?.trim()).filter(Boolean);
|
|
257
267
|
const argExtra = options.extra?.map((m) => m?.trim()).filter(Boolean);
|
|
258
|
-
if (fs.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
|
|
268
|
+
if (fs$1.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
|
|
259
269
|
p.log.warn(c.yellow`eslint.config.js already exists, migration wizard exited.`);
|
|
260
270
|
return process.exit(1);
|
|
261
271
|
}
|
|
@@ -267,34 +277,34 @@ async function run(options = {}) {
|
|
|
267
277
|
};
|
|
268
278
|
if (!argSkipPrompt) {
|
|
269
279
|
result = await p.group({
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
message: c.reset(message),
|
|
276
|
-
options: extraOptions,
|
|
277
|
-
required: false
|
|
280
|
+
uncommittedConfirmed: async () => {
|
|
281
|
+
if (argSkipPrompt || isGitClean()) return Promise.resolve(true);
|
|
282
|
+
return p.confirm({
|
|
283
|
+
initialValue: false,
|
|
284
|
+
message: "There are uncommitted changes in the current repository, are you sure to continue?"
|
|
278
285
|
});
|
|
279
286
|
},
|
|
280
|
-
frameworks: ({ results }) => {
|
|
281
|
-
const isArgTemplateValid =
|
|
287
|
+
frameworks: async ({ results }) => {
|
|
288
|
+
const isArgTemplateValid = !!argTemplate?.length && !argTemplate.some((element) => !frameworks.includes(element));
|
|
282
289
|
if (!results.uncommittedConfirmed || isArgTemplateValid) return;
|
|
283
|
-
const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
|
|
290
|
+
const message = !isArgTemplateValid && argTemplate?.length ? `"${argTemplate.join(", ")}" isn't a valid template. Please choose from below: ` : "Select a framework:";
|
|
284
291
|
return p.multiselect({
|
|
285
292
|
message: c.reset(message),
|
|
286
293
|
options: frameworkOptions,
|
|
287
294
|
required: false
|
|
288
295
|
});
|
|
289
296
|
},
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
297
|
+
extra: async ({ results }) => {
|
|
298
|
+
const isArgExtraValid = !!argExtra?.length && !argExtra.some((element) => !extra.includes(element));
|
|
299
|
+
if (!results.uncommittedConfirmed || isArgExtraValid) return;
|
|
300
|
+
const message = !isArgExtraValid && argExtra?.length ? `"${argExtra.join(", ")}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
|
|
301
|
+
return p.multiselect({
|
|
302
|
+
message: c.reset(message),
|
|
303
|
+
options: extraOptions,
|
|
304
|
+
required: false
|
|
295
305
|
});
|
|
296
306
|
},
|
|
297
|
-
updateVscodeSettings: ({ results }) => {
|
|
307
|
+
updateVscodeSettings: async ({ results }) => {
|
|
298
308
|
if (!results.uncommittedConfirmed) return;
|
|
299
309
|
return p.confirm({
|
|
300
310
|
initialValue: true,
|
|
@@ -311,7 +321,7 @@ async function run(options = {}) {
|
|
|
311
321
|
await updateEslintFiles(result);
|
|
312
322
|
await updateVscodeSettings(result);
|
|
313
323
|
p.log.success(c.green`Setup completed`);
|
|
314
|
-
p.outro(`Now you can update the dependencies by
|
|
324
|
+
p.outro(`Now you can update the dependencies by running ${c.blue("npm install")} and run ${c.blue("eslint --fix")}\n`);
|
|
315
325
|
}
|
|
316
326
|
|
|
317
327
|
//#endregion
|