@antfu/eslint-config 4.2.0 → 4.3.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/cli.js +60 -77
- package/dist/index.d.ts +1056 -389
- package/package.json +24 -25
package/dist/cli.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
// src/cli/index.ts
|
|
2
2
|
import process5 from "node:process";
|
|
3
3
|
import * as p5 from "@clack/prompts";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { hideBin } from "yargs/helpers";
|
|
4
|
+
import c5 from "ansis";
|
|
5
|
+
import { cac } from "cac";
|
|
7
6
|
|
|
8
7
|
// src/cli/constants.ts
|
|
9
|
-
import c from "
|
|
8
|
+
import c from "ansis";
|
|
10
9
|
|
|
11
10
|
// package.json
|
|
12
11
|
var package_default = {
|
|
13
12
|
name: "@antfu/eslint-config",
|
|
14
13
|
type: "module",
|
|
15
|
-
version: "4.
|
|
16
|
-
packageManager: "pnpm@10.
|
|
14
|
+
version: "4.3.0",
|
|
15
|
+
packageManager: "pnpm@10.4.1",
|
|
17
16
|
description: "Anthony's ESLint config",
|
|
18
17
|
author: "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
|
19
18
|
license: "MIT",
|
|
@@ -108,37 +107,37 @@ var package_default = {
|
|
|
108
107
|
"@clack/prompts": "^0.10.0",
|
|
109
108
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
|
|
110
109
|
"@eslint/markdown": "^6.2.2",
|
|
111
|
-
"@stylistic/eslint-plugin": "^4.0.0
|
|
112
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
113
|
-
"@typescript-eslint/parser": "^8.
|
|
114
|
-
"@vitest/eslint-plugin": "^1.1.
|
|
115
|
-
|
|
110
|
+
"@stylistic/eslint-plugin": "^4.0.0",
|
|
111
|
+
"@typescript-eslint/eslint-plugin": "^8.24.1",
|
|
112
|
+
"@typescript-eslint/parser": "^8.24.1",
|
|
113
|
+
"@vitest/eslint-plugin": "^1.1.31",
|
|
114
|
+
ansis: "^3.15.0",
|
|
115
|
+
cac: "^6.7.14",
|
|
116
|
+
"eslint-config-flat-gitignore": "^2.1.0",
|
|
116
117
|
"eslint-flat-config-utils": "^2.0.1",
|
|
117
118
|
"eslint-merge-processors": "^2.0.0",
|
|
118
|
-
"eslint-plugin-antfu": "^3.
|
|
119
|
-
"eslint-plugin-command": "^3.
|
|
119
|
+
"eslint-plugin-antfu": "^3.1.0",
|
|
120
|
+
"eslint-plugin-command": "^3.1.0",
|
|
120
121
|
"eslint-plugin-import-x": "^4.6.1",
|
|
121
122
|
"eslint-plugin-jsdoc": "^50.6.3",
|
|
122
123
|
"eslint-plugin-jsonc": "^2.19.1",
|
|
123
124
|
"eslint-plugin-n": "^17.15.1",
|
|
124
125
|
"eslint-plugin-no-only-tests": "^3.3.0",
|
|
125
|
-
"eslint-plugin-perfectionist": "^4.
|
|
126
|
+
"eslint-plugin-perfectionist": "^4.9.0",
|
|
126
127
|
"eslint-plugin-regexp": "^2.7.0",
|
|
127
128
|
"eslint-plugin-toml": "^0.12.0",
|
|
128
|
-
"eslint-plugin-unicorn": "^
|
|
129
|
+
"eslint-plugin-unicorn": "^57.0.0",
|
|
129
130
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
130
131
|
"eslint-plugin-vue": "^9.32.0",
|
|
131
|
-
"eslint-plugin-yml": "^1.
|
|
132
|
+
"eslint-plugin-yml": "^1.17.0",
|
|
132
133
|
"eslint-processor-vue-blocks": "^2.0.0",
|
|
133
|
-
globals: "^15.
|
|
134
|
+
globals: "^15.15.0",
|
|
134
135
|
"jsonc-eslint-parser": "^2.4.0",
|
|
135
136
|
"local-pkg": "^1.0.0",
|
|
136
137
|
"parse-gitignore": "^2.0.0",
|
|
137
|
-
picocolors: "^1.1.1",
|
|
138
138
|
"toml-eslint-parser": "^0.10.0",
|
|
139
139
|
"vue-eslint-parser": "^9.4.3",
|
|
140
|
-
"yaml-eslint-parser": "^1.2.3"
|
|
141
|
-
yargs: "^17.7.2"
|
|
140
|
+
"yaml-eslint-parser": "^1.2.3"
|
|
142
141
|
},
|
|
143
142
|
devDependencies: {
|
|
144
143
|
"@antfu/eslint-config": "workspace:*",
|
|
@@ -146,15 +145,14 @@ var package_default = {
|
|
|
146
145
|
"@eslint-react/eslint-plugin": "^1.26.2",
|
|
147
146
|
"@eslint/config-inspector": "^1.0.0",
|
|
148
147
|
"@prettier/plugin-xml": "^3.4.1",
|
|
149
|
-
"@stylistic/eslint-plugin-migrate": "^4.0.0
|
|
148
|
+
"@stylistic/eslint-plugin-migrate": "^4.0.0",
|
|
150
149
|
"@types/fs-extra": "^11.0.4",
|
|
151
|
-
"@types/node": "^22.13.
|
|
150
|
+
"@types/node": "^22.13.4",
|
|
152
151
|
"@types/prompts": "^2.4.9",
|
|
153
|
-
"@
|
|
154
|
-
"@unocss/eslint-plugin": "^65.4.3",
|
|
152
|
+
"@unocss/eslint-plugin": "^65.5.0",
|
|
155
153
|
"astro-eslint-parser": "^1.2.1",
|
|
156
|
-
bumpp: "^10.0.
|
|
157
|
-
eslint: "^9.20.
|
|
154
|
+
bumpp: "^10.0.3",
|
|
155
|
+
eslint: "^9.20.1",
|
|
158
156
|
"eslint-plugin-astro": "^1.3.1",
|
|
159
157
|
"eslint-plugin-format": "^1.0.1",
|
|
160
158
|
"eslint-plugin-react-hooks": "^5.1.0",
|
|
@@ -171,7 +169,7 @@ var package_default = {
|
|
|
171
169
|
"prettier-plugin-slidev": "^1.0.5",
|
|
172
170
|
rimraf: "^6.0.1",
|
|
173
171
|
"simple-git-hooks": "^2.11.1",
|
|
174
|
-
svelte: "^5.
|
|
172
|
+
svelte: "^5.20.1",
|
|
175
173
|
"svelte-eslint-parser": "^0.43.0",
|
|
176
174
|
tsup: "^8.3.6",
|
|
177
175
|
tsx: "^4.19.2",
|
|
@@ -181,8 +179,8 @@ var package_default = {
|
|
|
181
179
|
},
|
|
182
180
|
resolutions: {
|
|
183
181
|
"@eslint-community/eslint-utils": "^4.4.1",
|
|
184
|
-
"@typescript-eslint/utils": "^8.
|
|
185
|
-
eslint: "^9.20.
|
|
182
|
+
"@typescript-eslint/utils": "^8.24.1",
|
|
183
|
+
eslint: "^9.20.1",
|
|
186
184
|
tsx: "^4.19.2"
|
|
187
185
|
},
|
|
188
186
|
"simple-git-hooks": {
|
|
@@ -312,7 +310,7 @@ import fs3 from "node:fs";
|
|
|
312
310
|
import path4 from "node:path";
|
|
313
311
|
import process4 from "node:process";
|
|
314
312
|
import * as p4 from "@clack/prompts";
|
|
315
|
-
import
|
|
313
|
+
import c4 from "ansis";
|
|
316
314
|
|
|
317
315
|
// src/cli/stages/update-eslint-files.ts
|
|
318
316
|
import fs from "node:fs";
|
|
@@ -320,8 +318,8 @@ import fsp from "node:fs/promises";
|
|
|
320
318
|
import path from "node:path";
|
|
321
319
|
import process from "node:process";
|
|
322
320
|
import * as p from "@clack/prompts";
|
|
321
|
+
import c2 from "ansis";
|
|
323
322
|
import parse from "parse-gitignore";
|
|
324
|
-
import c2 from "picocolors";
|
|
325
323
|
|
|
326
324
|
// src/cli/utils.ts
|
|
327
325
|
import { execSync } from "node:child_process";
|
|
@@ -356,7 +354,7 @@ async function updateEslintFiles(result) {
|
|
|
356
354
|
const pathFlatConfig = path.join(cwd, configFileName);
|
|
357
355
|
const eslintIgnores = [];
|
|
358
356
|
if (fs.existsSync(pathESLintIgnore)) {
|
|
359
|
-
p.log.step(c2.cyan
|
|
357
|
+
p.log.step(c2.cyan`Migrating existing .eslintignore`);
|
|
360
358
|
const content = await fsp.readFile(pathESLintIgnore, "utf-8");
|
|
361
359
|
const parsed = parse(content);
|
|
362
360
|
const globs = parsed.globs();
|
|
@@ -380,7 +378,7 @@ async function updateEslintFiles(result) {
|
|
|
380
378
|
const additionalConfig = [];
|
|
381
379
|
const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
|
|
382
380
|
await fsp.writeFile(pathFlatConfig, eslintConfigContent);
|
|
383
|
-
p.log.success(c2.green
|
|
381
|
+
p.log.success(c2.green`Created ${configFileName}`);
|
|
384
382
|
const files = fs.readdirSync(cwd);
|
|
385
383
|
const legacyConfig = [];
|
|
386
384
|
files.forEach((file) => {
|
|
@@ -388,7 +386,7 @@ async function updateEslintFiles(result) {
|
|
|
388
386
|
legacyConfig.push(file);
|
|
389
387
|
});
|
|
390
388
|
if (legacyConfig.length)
|
|
391
|
-
p.note(
|
|
389
|
+
p.note(c2.dim(legacyConfig.join(", ")), "You can now remove those files manually");
|
|
392
390
|
}
|
|
393
391
|
|
|
394
392
|
// src/cli/stages/update-package-json.ts
|
|
@@ -396,11 +394,11 @@ import fsp2 from "node:fs/promises";
|
|
|
396
394
|
import path2 from "node:path";
|
|
397
395
|
import process2 from "node:process";
|
|
398
396
|
import * as p2 from "@clack/prompts";
|
|
399
|
-
import c3 from "
|
|
397
|
+
import c3 from "ansis";
|
|
400
398
|
async function updatePackageJson(result) {
|
|
401
399
|
const cwd = process2.cwd();
|
|
402
400
|
const pathPackageJSON = path2.join(cwd, "package.json");
|
|
403
|
-
p2.log.step(c3.cyan
|
|
401
|
+
p2.log.step(c3.cyan`Bumping @antfu/eslint-config to v${package_default.version}`);
|
|
404
402
|
const pkgContent = await fsp2.readFile(pathPackageJSON, "utf-8");
|
|
405
403
|
const pkg = JSON.parse(pkgContent);
|
|
406
404
|
pkg.devDependencies ??= {};
|
|
@@ -442,9 +440,9 @@ async function updatePackageJson(result) {
|
|
|
442
440
|
}
|
|
443
441
|
}
|
|
444
442
|
if (addedPackages.length)
|
|
445
|
-
p2.note(
|
|
443
|
+
p2.note(c3.dim(addedPackages.join(", ")), "Added packages");
|
|
446
444
|
await fsp2.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
447
|
-
p2.log.success(c3.green
|
|
445
|
+
p2.log.success(c3.green`Changes wrote to package.json`);
|
|
448
446
|
}
|
|
449
447
|
|
|
450
448
|
// src/cli/stages/update-vscode-settings.ts
|
|
@@ -453,7 +451,7 @@ import fsp3 from "node:fs/promises";
|
|
|
453
451
|
import path3 from "node:path";
|
|
454
452
|
import process3 from "node:process";
|
|
455
453
|
import * as p3 from "@clack/prompts";
|
|
456
|
-
import
|
|
454
|
+
import { green } from "ansis";
|
|
457
455
|
async function updateVscodeSettings(result) {
|
|
458
456
|
const cwd = process3.cwd();
|
|
459
457
|
if (!result.updateVscodeSettings)
|
|
@@ -465,7 +463,7 @@ async function updateVscodeSettings(result) {
|
|
|
465
463
|
if (!fs2.existsSync(settingsPath)) {
|
|
466
464
|
await fsp3.writeFile(settingsPath, `{${vscodeSettingsString}}
|
|
467
465
|
`, "utf-8");
|
|
468
|
-
p3.log.success(
|
|
466
|
+
p3.log.success(green`Created .vscode/settings.json`);
|
|
469
467
|
} else {
|
|
470
468
|
let settingsContent = await fsp3.readFile(settingsPath, "utf8");
|
|
471
469
|
settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
|
|
@@ -473,17 +471,17 @@ async function updateVscodeSettings(result) {
|
|
|
473
471
|
settingsContent += `${vscodeSettingsString}}
|
|
474
472
|
`;
|
|
475
473
|
await fsp3.writeFile(settingsPath, settingsContent, "utf-8");
|
|
476
|
-
p3.log.success(
|
|
474
|
+
p3.log.success(green`Updated .vscode/settings.json`);
|
|
477
475
|
}
|
|
478
476
|
}
|
|
479
477
|
|
|
480
478
|
// src/cli/run.ts
|
|
481
479
|
async function run(options = {}) {
|
|
482
480
|
const argSkipPrompt = !!process4.env.SKIP_PROMPT || options.yes;
|
|
483
|
-
const argTemplate = options.frameworks?.map((m) => m
|
|
484
|
-
const argExtra = options.extra?.map((m) => m
|
|
481
|
+
const argTemplate = options.frameworks?.map((m) => m?.trim()).filter(Boolean);
|
|
482
|
+
const argExtra = options.extra?.map((m) => m?.trim()).filter(Boolean);
|
|
485
483
|
if (fs3.existsSync(path4.join(process4.cwd(), "eslint.config.js"))) {
|
|
486
|
-
p4.log.warn(
|
|
484
|
+
p4.log.warn(c4.yellow`eslint.config.js already exists, migration wizard exited.`);
|
|
487
485
|
return process4.exit(1);
|
|
488
486
|
}
|
|
489
487
|
let result = {
|
|
@@ -508,7 +506,7 @@ async function run(options = {}) {
|
|
|
508
506
|
return;
|
|
509
507
|
const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
|
|
510
508
|
return p4.multiselect({
|
|
511
|
-
message:
|
|
509
|
+
message: c4.reset(message),
|
|
512
510
|
options: frameworkOptions,
|
|
513
511
|
required: false
|
|
514
512
|
});
|
|
@@ -519,7 +517,7 @@ async function run(options = {}) {
|
|
|
519
517
|
return;
|
|
520
518
|
const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
|
|
521
519
|
return p4.multiselect({
|
|
522
|
-
message:
|
|
520
|
+
message: c4.reset(message),
|
|
523
521
|
options: extraOptions,
|
|
524
522
|
required: false
|
|
525
523
|
});
|
|
@@ -544,42 +542,27 @@ async function run(options = {}) {
|
|
|
544
542
|
await updatePackageJson(result);
|
|
545
543
|
await updateEslintFiles(result);
|
|
546
544
|
await updateVscodeSettings(result);
|
|
547
|
-
p4.log.success(
|
|
548
|
-
p4.outro(`Now you can update the dependencies by run ${
|
|
545
|
+
p4.log.success(c4.green`Setup completed`);
|
|
546
|
+
p4.outro(`Now you can update the dependencies by run ${c4.blue("pnpm install")} and run ${c4.blue("eslint . --fix")}
|
|
549
547
|
`);
|
|
550
548
|
}
|
|
551
549
|
|
|
552
550
|
// src/cli/index.ts
|
|
553
551
|
function header() {
|
|
554
552
|
console.log("\n");
|
|
555
|
-
p5.intro(`${
|
|
553
|
+
p5.intro(`${c5.green`@antfu/eslint-config `}${c5.dim`v${package_default.version}`}`);
|
|
556
554
|
}
|
|
557
|
-
var
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
description: "Use the framework template for optimal customization: vue / react / svelte / astro",
|
|
567
|
-
type: "string"
|
|
568
|
-
}).option("extra", {
|
|
569
|
-
alias: "e",
|
|
570
|
-
array: true,
|
|
571
|
-
description: "Use the extra utils: formatter / perfectionist / unocss",
|
|
572
|
-
type: "string"
|
|
573
|
-
}).help(),
|
|
574
|
-
async (args) => {
|
|
575
|
-
header();
|
|
576
|
-
try {
|
|
577
|
-
await run(args);
|
|
578
|
-
} catch (error) {
|
|
579
|
-
p5.log.error(c6.inverse(c6.red(" Failed to migrate ")));
|
|
580
|
-
p5.log.error(c6.red(`\u2718 ${String(error)}`));
|
|
581
|
-
process5.exit(1);
|
|
582
|
-
}
|
|
555
|
+
var cli = cac("@antfu/eslint-config");
|
|
556
|
+
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) => {
|
|
557
|
+
header();
|
|
558
|
+
try {
|
|
559
|
+
await run(args);
|
|
560
|
+
} catch (error) {
|
|
561
|
+
p5.log.error(c5.inverse.red(" Failed to migrate "));
|
|
562
|
+
p5.log.error(c5.red`✘ ${String(error)}`);
|
|
563
|
+
process5.exit(1);
|
|
583
564
|
}
|
|
584
|
-
)
|
|
585
|
-
|
|
565
|
+
});
|
|
566
|
+
cli.help();
|
|
567
|
+
cli.version(package_default.version);
|
|
568
|
+
cli.parse();
|