@antfu/eslint-config 2.8.2 → 2.9.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 +33 -11
- package/dist/cli.cjs +445 -151
- package/dist/cli.js +445 -151
- package/dist/index.cjs +61 -17
- package/dist/index.d.cts +63 -3
- package/dist/index.d.ts +63 -3
- package/dist/index.js +59 -17
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -1,68 +1,193 @@
|
|
|
1
1
|
// src/cli/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import process5 from "process";
|
|
3
|
+
import c6 from "picocolors";
|
|
4
4
|
import { hideBin } from "yargs/helpers";
|
|
5
5
|
import yargs from "yargs";
|
|
6
|
+
import * as p5 from "@clack/prompts";
|
|
6
7
|
|
|
7
8
|
// src/cli/run.ts
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import c2 from "picocolors";
|
|
14
|
-
import parse from "parse-gitignore";
|
|
9
|
+
import fs3 from "fs";
|
|
10
|
+
import path4 from "path";
|
|
11
|
+
import process4 from "process";
|
|
12
|
+
import c5 from "picocolors";
|
|
13
|
+
import * as p4 from "@clack/prompts";
|
|
15
14
|
|
|
16
15
|
// src/cli/constants.ts
|
|
17
16
|
import c from "picocolors";
|
|
18
17
|
|
|
19
18
|
// package.json
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
19
|
+
var package_default = {
|
|
20
|
+
name: "@antfu/eslint-config",
|
|
21
|
+
type: "module",
|
|
22
|
+
version: "2.9.0",
|
|
23
|
+
packageManager: "pnpm@8.15.4",
|
|
24
|
+
description: "Anthony's ESLint config",
|
|
25
|
+
author: "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
|
26
|
+
license: "MIT",
|
|
27
|
+
funding: "https://github.com/sponsors/antfu",
|
|
28
|
+
homepage: "https://github.com/antfu/eslint-config",
|
|
29
|
+
keywords: [
|
|
30
|
+
"eslint-config"
|
|
31
|
+
],
|
|
32
|
+
exports: {
|
|
33
|
+
".": {
|
|
34
|
+
import: "./dist/index.js",
|
|
35
|
+
require: "./dist/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
main: "./dist/index.js",
|
|
39
|
+
types: "./dist/index.d.ts",
|
|
40
|
+
bin: "./bin/index.js",
|
|
41
|
+
files: [
|
|
42
|
+
"bin",
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
scripts: {
|
|
46
|
+
build: "tsup --format esm,cjs --clean --dts",
|
|
47
|
+
stub: "tsup --format esm",
|
|
48
|
+
dev: "tsup --format esm,cjs --watch & eslint-flat-config-viewer",
|
|
49
|
+
watch: "tsup --format esm,cjs --watch",
|
|
50
|
+
lint: "eslint .",
|
|
51
|
+
prepack: "nr build",
|
|
52
|
+
release: "bumpp && pnpm publish",
|
|
53
|
+
test: "vitest",
|
|
54
|
+
typecheck: "tsc --noEmit",
|
|
55
|
+
prepare: "simple-git-hooks"
|
|
56
|
+
},
|
|
57
|
+
peerDependencies: {
|
|
58
|
+
"@unocss/eslint-plugin": ">=0.50.0",
|
|
59
|
+
"astro-eslint-parser": "^0.16.3",
|
|
60
|
+
eslint: ">=8.40.0",
|
|
61
|
+
"eslint-plugin-astro": "^0.31.4",
|
|
62
|
+
"eslint-plugin-format": ">=0.1.0",
|
|
63
|
+
"eslint-plugin-react": "^7.33.2",
|
|
64
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
65
|
+
"eslint-plugin-react-refresh": "^0.4.4",
|
|
66
|
+
"eslint-plugin-svelte": "^2.34.1",
|
|
67
|
+
"prettier-plugin-astro": "^0.13.0",
|
|
68
|
+
"prettier-plugin-slidev": "^1.0.5",
|
|
69
|
+
"svelte-eslint-parser": "^0.33.1"
|
|
70
|
+
},
|
|
71
|
+
peerDependenciesMeta: {
|
|
72
|
+
"@unocss/eslint-plugin": {
|
|
73
|
+
optional: true
|
|
74
|
+
},
|
|
75
|
+
"astro-eslint-parser": {
|
|
76
|
+
optional: true
|
|
77
|
+
},
|
|
78
|
+
"eslint-plugin-astro": {
|
|
79
|
+
optional: true
|
|
80
|
+
},
|
|
81
|
+
"eslint-plugin-format": {
|
|
82
|
+
optional: true
|
|
83
|
+
},
|
|
84
|
+
"eslint-plugin-react": {
|
|
85
|
+
optional: true
|
|
86
|
+
},
|
|
87
|
+
"eslint-plugin-react-hooks": {
|
|
88
|
+
optional: true
|
|
89
|
+
},
|
|
90
|
+
"eslint-plugin-react-refresh": {
|
|
91
|
+
optional: true
|
|
92
|
+
},
|
|
93
|
+
"eslint-plugin-svelte": {
|
|
94
|
+
optional: true
|
|
95
|
+
},
|
|
96
|
+
"prettier-plugin-astro": {
|
|
97
|
+
optional: true
|
|
98
|
+
},
|
|
99
|
+
"prettier-plugin-slidev": {
|
|
100
|
+
optional: true
|
|
101
|
+
},
|
|
102
|
+
"svelte-eslint-parser": {
|
|
103
|
+
optional: true
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
dependencies: {
|
|
107
|
+
"@antfu/eslint-define-config": "^1.23.0-2",
|
|
108
|
+
"@antfu/install-pkg": "^0.3.1",
|
|
109
|
+
"@clack/prompts": "^0.7.0",
|
|
110
|
+
"@eslint-types/jsdoc": "46.8.2-1",
|
|
111
|
+
"@eslint-types/typescript-eslint": "^7.0.2",
|
|
112
|
+
"@eslint-types/unicorn": "^51.0.1",
|
|
113
|
+
"@stylistic/eslint-plugin": "^1.7.0",
|
|
114
|
+
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
115
|
+
"@typescript-eslint/parser": "^7.2.0",
|
|
116
|
+
"eslint-config-flat-gitignore": "^0.1.3",
|
|
117
|
+
"eslint-merge-processors": "^0.1.0",
|
|
118
|
+
"eslint-plugin-antfu": "^2.1.2",
|
|
119
|
+
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
120
|
+
"eslint-plugin-import-x": "^0.4.1",
|
|
121
|
+
"eslint-plugin-jsdoc": "^48.2.1",
|
|
122
|
+
"eslint-plugin-jsonc": "^2.13.0",
|
|
123
|
+
"eslint-plugin-markdown": "^4.0.1",
|
|
124
|
+
"eslint-plugin-n": "^16.6.2",
|
|
125
|
+
"eslint-plugin-no-only-tests": "^3.1.0",
|
|
126
|
+
"eslint-plugin-perfectionist": "^2.6.0",
|
|
127
|
+
"eslint-plugin-toml": "^0.9.2",
|
|
128
|
+
"eslint-plugin-unicorn": "^51.0.1",
|
|
129
|
+
"eslint-plugin-unused-imports": "^3.1.0",
|
|
130
|
+
"eslint-plugin-vitest": "^0.3.26",
|
|
131
|
+
"eslint-plugin-vue": "^9.23.0",
|
|
132
|
+
"eslint-plugin-yml": "^1.12.2",
|
|
133
|
+
"eslint-processor-vue-blocks": "^0.1.1",
|
|
134
|
+
globals: "^14.0.0",
|
|
135
|
+
"jsonc-eslint-parser": "^2.4.0",
|
|
136
|
+
"local-pkg": "^0.5.0",
|
|
137
|
+
"parse-gitignore": "^2.0.0",
|
|
138
|
+
picocolors: "^1.0.0",
|
|
139
|
+
"toml-eslint-parser": "^0.9.3",
|
|
140
|
+
"vue-eslint-parser": "^9.4.2",
|
|
141
|
+
"yaml-eslint-parser": "^1.2.2",
|
|
142
|
+
yargs: "^17.7.2"
|
|
143
|
+
},
|
|
144
|
+
devDependencies: {
|
|
145
|
+
"@antfu/eslint-config": "workspace:*",
|
|
146
|
+
"@antfu/eslint-plugin-prettier": "^5.0.1-1",
|
|
147
|
+
"@antfu/ni": "^0.21.12",
|
|
148
|
+
"@stylistic/eslint-plugin-migrate": "^1.7.0",
|
|
149
|
+
"@types/eslint": "^8.56.5",
|
|
150
|
+
"@types/fs-extra": "^11.0.4",
|
|
151
|
+
"@types/node": "^20.11.27",
|
|
152
|
+
"@types/prompts": "^2.4.9",
|
|
153
|
+
"@types/yargs": "^17.0.32",
|
|
154
|
+
"@unocss/eslint-plugin": "^0.58.5",
|
|
155
|
+
"astro-eslint-parser": "^0.16.3",
|
|
156
|
+
bumpp: "^9.4.0",
|
|
157
|
+
eslint: "npm:eslint-ts-patch@^8.57.0-0",
|
|
158
|
+
"eslint-flat-config-viewer": "^0.1.11",
|
|
159
|
+
"eslint-plugin-astro": "^0.31.4",
|
|
160
|
+
"eslint-plugin-format": "^0.1.0",
|
|
161
|
+
"eslint-plugin-react": "^7.34.0",
|
|
162
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
163
|
+
"eslint-plugin-react-refresh": "^0.4.6",
|
|
164
|
+
"eslint-plugin-svelte": "^2.35.1",
|
|
165
|
+
"eslint-ts-patch": "^8.57.0-0",
|
|
166
|
+
esno: "^4.7.0",
|
|
167
|
+
execa: "^8.0.1",
|
|
168
|
+
"fast-glob": "^3.3.2",
|
|
169
|
+
"fs-extra": "^11.2.0",
|
|
170
|
+
"lint-staged": "^15.2.2",
|
|
171
|
+
"prettier-plugin-astro": "^0.13.0",
|
|
172
|
+
"prettier-plugin-slidev": "^1.0.5",
|
|
173
|
+
rimraf: "^5.0.5",
|
|
174
|
+
"simple-git-hooks": "^2.10.0",
|
|
175
|
+
svelte: "^4.2.12",
|
|
176
|
+
"svelte-eslint-parser": "^0.33.1",
|
|
177
|
+
tsup: "^8.0.2",
|
|
178
|
+
typescript: "^5.4.2",
|
|
179
|
+
vitest: "^1.3.1",
|
|
180
|
+
vue: "^3.4.21"
|
|
181
|
+
},
|
|
182
|
+
"simple-git-hooks": {
|
|
183
|
+
"pre-commit": "pnpm lint-staged"
|
|
184
|
+
},
|
|
185
|
+
"lint-staged": {
|
|
186
|
+
"*": "eslint --fix"
|
|
187
|
+
}
|
|
58
188
|
};
|
|
59
189
|
|
|
60
190
|
// src/cli/constants.ts
|
|
61
|
-
var ARROW = c.cyan("\u2192");
|
|
62
|
-
var CHECK = c.green("\u2714");
|
|
63
|
-
var CROSS = c.red("\u2718");
|
|
64
|
-
var WARN = c.yellow("\u2139");
|
|
65
|
-
var eslintVersion = devDependencies.eslint;
|
|
66
191
|
var vscodeSettingsString = `
|
|
67
192
|
// Enable the ESlint flat config support
|
|
68
193
|
"eslint.experimental.useFlatConfig": true,
|
|
@@ -107,6 +232,60 @@ var vscodeSettingsString = `
|
|
|
107
232
|
"astro",
|
|
108
233
|
]
|
|
109
234
|
`;
|
|
235
|
+
var frameworkOptions = [
|
|
236
|
+
{
|
|
237
|
+
label: c.green("Vue"),
|
|
238
|
+
value: "vue"
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
label: c.cyan("React"),
|
|
242
|
+
value: "react"
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
label: c.red("Svelte"),
|
|
246
|
+
value: "svelte"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
label: c.magenta("Astro"),
|
|
250
|
+
value: "astro"
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
label: c.blue("Slidev"),
|
|
254
|
+
value: "slidev"
|
|
255
|
+
}
|
|
256
|
+
];
|
|
257
|
+
var frameworks = frameworkOptions.map(({ value }) => value);
|
|
258
|
+
var extraOptions = [
|
|
259
|
+
{
|
|
260
|
+
hint: "Use external formatters (Prettier and/or dprint) to format files that ESLint cannot handle yet (.css, .html, etc)",
|
|
261
|
+
label: c.red("Formatter"),
|
|
262
|
+
value: "formatter"
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
label: c.cyan("UnoCSS"),
|
|
266
|
+
value: "unocss"
|
|
267
|
+
}
|
|
268
|
+
];
|
|
269
|
+
var extra = extraOptions.map(({ value }) => value);
|
|
270
|
+
var dependenciesMap = {
|
|
271
|
+
astro: [
|
|
272
|
+
"eslint-plugin-astro",
|
|
273
|
+
"astro-eslint-parser"
|
|
274
|
+
],
|
|
275
|
+
react: [
|
|
276
|
+
"eslint-plugin-react",
|
|
277
|
+
"eslint-plugin-react-hooks",
|
|
278
|
+
"eslint-plugin-react-refresh"
|
|
279
|
+
],
|
|
280
|
+
slidev: [
|
|
281
|
+
"prettier-plugin-slidev"
|
|
282
|
+
],
|
|
283
|
+
svelte: [
|
|
284
|
+
"eslint-plugin-svelte",
|
|
285
|
+
"svelte-eslint-parser"
|
|
286
|
+
],
|
|
287
|
+
vue: []
|
|
288
|
+
};
|
|
110
289
|
|
|
111
290
|
// src/cli/utils.ts
|
|
112
291
|
import { execSync } from "child_process";
|
|
@@ -118,42 +297,95 @@ function isGitClean() {
|
|
|
118
297
|
return false;
|
|
119
298
|
}
|
|
120
299
|
}
|
|
300
|
+
function getEslintConfigContent(mainConfig, additionalConfigs) {
|
|
301
|
+
return `
|
|
302
|
+
import antfu from '@antfu/eslint-config'
|
|
121
303
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
304
|
+
export default antfu({
|
|
305
|
+
${mainConfig}
|
|
306
|
+
}${additionalConfigs?.map((config) => `,{
|
|
307
|
+
${config}
|
|
308
|
+
}`)})
|
|
309
|
+
`.trimStart();
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// src/cli/stages/update-package-json.ts
|
|
313
|
+
import path from "path";
|
|
314
|
+
import fsp from "fs/promises";
|
|
315
|
+
import process from "process";
|
|
316
|
+
import c2 from "picocolors";
|
|
317
|
+
import * as p from "@clack/prompts";
|
|
318
|
+
async function updatePackageJson(result) {
|
|
319
|
+
var _a;
|
|
126
320
|
const cwd = process.cwd();
|
|
127
|
-
const pathFlatConfig = path.join(cwd, "eslint.config.js");
|
|
128
321
|
const pathPackageJSON = path.join(cwd, "package.json");
|
|
129
|
-
|
|
130
|
-
if (fs.existsSync(pathFlatConfig)) {
|
|
131
|
-
console.log(c2.yellow(`${WARN} eslint.config.js already exists, migration wizard exited.`));
|
|
132
|
-
return process.exit(1);
|
|
133
|
-
}
|
|
134
|
-
if (!SKIP_GIT_CHECK && !isGitClean()) {
|
|
135
|
-
const { confirmed } = await prompts({
|
|
136
|
-
initial: false,
|
|
137
|
-
message: "There are uncommitted changes in the current repository, are you sure to continue?",
|
|
138
|
-
name: "confirmed",
|
|
139
|
-
type: "confirm"
|
|
140
|
-
});
|
|
141
|
-
if (!confirmed)
|
|
142
|
-
return process.exit(1);
|
|
143
|
-
}
|
|
144
|
-
console.log(c2.cyan(`${ARROW} bumping @antfu/eslint-config to v${version}`));
|
|
322
|
+
p.log.step(c2.cyan(`Bumping @antfu/eslint-config to v${package_default.version}`));
|
|
145
323
|
const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
|
|
146
324
|
const pkg = JSON.parse(pkgContent);
|
|
147
325
|
pkg.devDependencies ?? (pkg.devDependencies = {});
|
|
148
|
-
pkg.devDependencies["@antfu/eslint-config"] = `^${version}`;
|
|
149
|
-
|
|
150
|
-
|
|
326
|
+
pkg.devDependencies["@antfu/eslint-config"] = `^${package_default.version}`;
|
|
327
|
+
(_a = pkg.devDependencies).eslint ?? (_a.eslint = package_default.devDependencies.eslint.replace("npm:eslint-ts-patch@", "").replace(/-\d+$/, ""));
|
|
328
|
+
const addedPackages = [];
|
|
329
|
+
if (result.extra.length) {
|
|
330
|
+
result.extra.forEach((item) => {
|
|
331
|
+
switch (item) {
|
|
332
|
+
case "formatter":
|
|
333
|
+
[
|
|
334
|
+
"eslint-plugin-format",
|
|
335
|
+
result.frameworks.includes("astro") ? "prettier-plugin-astro" : null
|
|
336
|
+
].forEach((f) => {
|
|
337
|
+
if (!f)
|
|
338
|
+
return;
|
|
339
|
+
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
340
|
+
addedPackages.push(f);
|
|
341
|
+
});
|
|
342
|
+
break;
|
|
343
|
+
case "unocss":
|
|
344
|
+
[
|
|
345
|
+
"@unocss/eslint-plugin"
|
|
346
|
+
].forEach((f) => {
|
|
347
|
+
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
348
|
+
addedPackages.push(f);
|
|
349
|
+
});
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
for (const framework of result.frameworks) {
|
|
355
|
+
const deps = dependenciesMap[framework];
|
|
356
|
+
if (deps) {
|
|
357
|
+
deps.forEach((f) => {
|
|
358
|
+
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
359
|
+
addedPackages.push(f);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (addedPackages.length)
|
|
364
|
+
p.note(`${c2.dim(addedPackages.join(", "))}`, "Added packages");
|
|
151
365
|
await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
152
|
-
|
|
366
|
+
p.log.success(c2.green(`Changes wrote to package.json`));
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/cli/stages/update-eslint-files.ts
|
|
370
|
+
import fs from "fs";
|
|
371
|
+
import fsp2 from "fs/promises";
|
|
372
|
+
import process2 from "process";
|
|
373
|
+
import path2 from "path";
|
|
374
|
+
import c3 from "picocolors";
|
|
375
|
+
import * as p2 from "@clack/prompts";
|
|
376
|
+
import parse from "parse-gitignore";
|
|
377
|
+
async function updateEslintFiles(result) {
|
|
378
|
+
const cwd = process2.cwd();
|
|
379
|
+
const pathESLintIgnore = path2.join(cwd, ".eslintignore");
|
|
380
|
+
const pathPackageJSON = path2.join(cwd, "package.json");
|
|
381
|
+
const pkgContent = await fsp2.readFile(pathPackageJSON, "utf-8");
|
|
382
|
+
const pkg = JSON.parse(pkgContent);
|
|
383
|
+
const configFileName = pkg.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
384
|
+
const pathFlatConfig = path2.join(cwd, configFileName);
|
|
153
385
|
const eslintIgnores = [];
|
|
154
386
|
if (fs.existsSync(pathESLintIgnore)) {
|
|
155
|
-
|
|
156
|
-
const content = await
|
|
387
|
+
p2.log.step(c3.cyan(`Migrating existing .eslintignore`));
|
|
388
|
+
const content = await fsp2.readFile(pathESLintIgnore, "utf-8");
|
|
157
389
|
const parsed = parse(content);
|
|
158
390
|
const globs = parsed.globs();
|
|
159
391
|
for (const glob of globs) {
|
|
@@ -163,100 +395,162 @@ async function run(options = {}) {
|
|
|
163
395
|
eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
|
|
164
396
|
}
|
|
165
397
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
module.exports = antfu({
|
|
181
|
-
${antfuConfig}
|
|
182
|
-
})
|
|
183
|
-
`.trimStart();
|
|
184
|
-
}
|
|
185
|
-
await fsp.writeFile(pathFlatConfig, eslintConfigContent);
|
|
186
|
-
console.log(c2.green(`${CHECK} created eslint.config.js`));
|
|
398
|
+
const configLines = [];
|
|
399
|
+
if (eslintIgnores.length)
|
|
400
|
+
configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
|
|
401
|
+
if (result.extra.includes("formatter"))
|
|
402
|
+
configLines.push(`formatters: true,`);
|
|
403
|
+
if (result.extra.includes("unocss"))
|
|
404
|
+
configLines.push(`unocss: true,`);
|
|
405
|
+
for (const framework of result.frameworks)
|
|
406
|
+
configLines.push(`${framework}: true,`);
|
|
407
|
+
const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
|
|
408
|
+
const additionalConfig = [];
|
|
409
|
+
const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
|
|
410
|
+
await fsp2.writeFile(pathFlatConfig, eslintConfigContent);
|
|
411
|
+
p2.log.success(c3.green(`Created ${configFileName}`));
|
|
187
412
|
const files = fs.readdirSync(cwd);
|
|
188
413
|
const legacyConfig = [];
|
|
189
414
|
files.forEach((file) => {
|
|
190
|
-
if (/eslint|prettier/.test(file) && !/eslint
|
|
415
|
+
if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file))
|
|
191
416
|
legacyConfig.push(file);
|
|
192
417
|
});
|
|
193
|
-
if (legacyConfig.length)
|
|
194
|
-
|
|
195
|
-
|
|
418
|
+
if (legacyConfig.length)
|
|
419
|
+
p2.note(`${c3.dim(legacyConfig.join(", "))}`, "You can now remove those files manually");
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// src/cli/stages/update-vscode-settings.ts
|
|
423
|
+
import path3 from "path";
|
|
424
|
+
import fsp3 from "fs/promises";
|
|
425
|
+
import fs2 from "fs";
|
|
426
|
+
import process3 from "process";
|
|
427
|
+
import c4 from "picocolors";
|
|
428
|
+
import * as p3 from "@clack/prompts";
|
|
429
|
+
async function updateVscodeSettings(result) {
|
|
430
|
+
const cwd = process3.cwd();
|
|
431
|
+
if (!result.updateVscodeSettings)
|
|
432
|
+
return;
|
|
433
|
+
const dotVscodePath = path3.join(cwd, ".vscode");
|
|
434
|
+
const settingsPath = path3.join(dotVscodePath, "settings.json");
|
|
435
|
+
if (!fs2.existsSync(dotVscodePath))
|
|
436
|
+
await fsp3.mkdir(dotVscodePath, { recursive: true });
|
|
437
|
+
if (!fs2.existsSync(settingsPath)) {
|
|
438
|
+
await fsp3.writeFile(settingsPath, `{${vscodeSettingsString}}
|
|
439
|
+
`, "utf-8");
|
|
440
|
+
p3.log.success(c4.green(`Created .vscode/settings.json`));
|
|
441
|
+
} else {
|
|
442
|
+
let settingsContent = await fsp3.readFile(settingsPath, "utf8");
|
|
443
|
+
settingsContent = settingsContent.trim().replace(/\s*}$/, "");
|
|
444
|
+
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
445
|
+
settingsContent += `${vscodeSettingsString}}
|
|
446
|
+
`;
|
|
447
|
+
await fsp3.writeFile(settingsPath, settingsContent, "utf-8");
|
|
448
|
+
p3.log.success(c4.green(`Updated .vscode/settings.json`));
|
|
196
449
|
}
|
|
197
|
-
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// src/cli/run.ts
|
|
453
|
+
async function run(options = {}) {
|
|
454
|
+
const argSkipPrompt = !!process4.env.SKIP_PROMPT || options.yes;
|
|
455
|
+
const argTemplate = options.frameworks?.map((m) => m.trim());
|
|
456
|
+
const argExtra = options.extra?.map((m) => m.trim());
|
|
457
|
+
if (fs3.existsSync(path4.join(process4.cwd(), "eslint.config.js"))) {
|
|
458
|
+
p4.log.warn(c5.yellow(`eslint.config.js already exists, migration wizard exited.`));
|
|
459
|
+
return process4.exit(1);
|
|
460
|
+
}
|
|
461
|
+
let result = {
|
|
462
|
+
extra: argExtra ?? [],
|
|
463
|
+
frameworks: argTemplate ?? [],
|
|
464
|
+
uncommittedConfirmed: false,
|
|
198
465
|
updateVscodeSettings: true
|
|
199
466
|
};
|
|
200
|
-
if (!
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
467
|
+
if (!argSkipPrompt) {
|
|
468
|
+
result = await p4.group({
|
|
469
|
+
uncommittedConfirmed: () => {
|
|
470
|
+
if (argSkipPrompt || isGitClean())
|
|
471
|
+
return Promise.resolve(true);
|
|
472
|
+
return p4.confirm({
|
|
473
|
+
initialValue: false,
|
|
474
|
+
message: "There are uncommitted changes in the current repository, are you sure to continue?"
|
|
475
|
+
});
|
|
476
|
+
},
|
|
477
|
+
frameworks: ({ results }) => {
|
|
478
|
+
const isArgTemplateValid = typeof argTemplate === "string" && !!frameworks.includes(argTemplate);
|
|
479
|
+
if (!results.uncommittedConfirmed || isArgTemplateValid)
|
|
480
|
+
return;
|
|
481
|
+
const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
|
|
482
|
+
return p4.multiselect({
|
|
483
|
+
message: c5.reset(message),
|
|
484
|
+
options: frameworkOptions
|
|
485
|
+
});
|
|
486
|
+
},
|
|
487
|
+
extra: ({ results }) => {
|
|
488
|
+
const isArgExtraValid = argExtra?.length && !argExtra.filter((element) => !extra.includes(element)).length;
|
|
489
|
+
if (!results.uncommittedConfirmed || isArgExtraValid)
|
|
490
|
+
return;
|
|
491
|
+
const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
|
|
492
|
+
return p4.multiselect({
|
|
493
|
+
message: c5.reset(message),
|
|
494
|
+
options: extraOptions,
|
|
495
|
+
required: false
|
|
496
|
+
});
|
|
497
|
+
},
|
|
498
|
+
updateVscodeSettings: ({ results }) => {
|
|
499
|
+
if (!results.uncommittedConfirmed)
|
|
500
|
+
return;
|
|
501
|
+
return p4.confirm({
|
|
502
|
+
initialValue: true,
|
|
503
|
+
message: "Update .vscode/settings.json for better VS Code experience?"
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
}, {
|
|
507
|
+
onCancel: () => {
|
|
508
|
+
p4.cancel("Operation cancelled.");
|
|
509
|
+
process4.exit(0);
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
if (!result.uncommittedConfirmed)
|
|
513
|
+
return process4.exit(1);
|
|
235
514
|
}
|
|
236
|
-
|
|
237
|
-
|
|
515
|
+
await updatePackageJson(result);
|
|
516
|
+
await updateEslintFiles(result);
|
|
517
|
+
await updateVscodeSettings(result);
|
|
518
|
+
p4.log.success(c5.green(`Setup completed`));
|
|
519
|
+
p4.outro(`Now you can update the dependencies and run ${c5.blue("eslint . --fix")}
|
|
238
520
|
`);
|
|
239
521
|
}
|
|
240
522
|
|
|
241
523
|
// src/cli/index.ts
|
|
242
524
|
function header() {
|
|
243
|
-
console.log(
|
|
244
|
-
|
|
525
|
+
console.log("\n");
|
|
526
|
+
p5.intro(`${c6.green(`@antfu/eslint-config `)}${c6.dim(`v${package_default.version}`)}`);
|
|
245
527
|
}
|
|
246
|
-
var instance = yargs(hideBin(
|
|
528
|
+
var instance = yargs(hideBin(process5.argv)).scriptName("@antfu/eslint-config").usage("").command(
|
|
247
529
|
"*",
|
|
248
530
|
"Run the initialization or migration",
|
|
249
|
-
(args) => args.option("yes", {
|
|
531
|
+
(args) => args.option("yes", {
|
|
532
|
+
alias: "y",
|
|
533
|
+
description: "Skip prompts and use default values",
|
|
534
|
+
type: "boolean"
|
|
535
|
+
}).option("template", {
|
|
536
|
+
alias: "t",
|
|
537
|
+
description: "Use the framework template for optimal customization: vue / react / svelte / astro",
|
|
538
|
+
type: "string"
|
|
539
|
+
}).option("extra", {
|
|
540
|
+
alias: "e",
|
|
541
|
+
array: true,
|
|
542
|
+
description: "Use the extra utils: formatter / perfectionist / unocss",
|
|
543
|
+
type: "string"
|
|
544
|
+
}).help(),
|
|
250
545
|
async (args) => {
|
|
251
546
|
header();
|
|
252
|
-
console.log();
|
|
253
547
|
try {
|
|
254
548
|
await run(args);
|
|
255
549
|
} catch (error) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
550
|
+
p5.log.error(c6.inverse(c6.red(" Failed to migrate ")));
|
|
551
|
+
p5.log.error(c6.red(`\u2718 ${String(error)}`));
|
|
552
|
+
process5.exit(1);
|
|
259
553
|
}
|
|
260
554
|
}
|
|
261
|
-
).showHelpOnFail(false).alias("h", "help").version("version", version).alias("v", "version");
|
|
555
|
+
).showHelpOnFail(false).alias("h", "help").version("version", package_default.version).alias("v", "version");
|
|
262
556
|
instance.help().argv;
|