@antfu/eslint-config 4.13.0 → 4.13.2

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 CHANGED
@@ -28,6 +28,9 @@
28
28
  >
29
29
  > If you are using this config directly, I suggest you **review the changes every time you update**. Or if you want more control over the rules, always feel free to fork it. Thanks!
30
30
 
31
+ > [!TIP]
32
+ > If you are interested in the tooling and the philosophy behind this config, I gave a talk about ESLint flat config at [JSNation 2024 - ESLint One for All Made Easy](https://gitnation.com/contents/eslint-one-for-all-made-easy), slides are [here](https://talks.antfu.me/2024/jsnation).
33
+
31
34
  ## Usage
32
35
 
33
36
  ### Starter Wizard
package/dist/cli.d.ts CHANGED
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ export { };
package/dist/cli.js CHANGED
@@ -1,22 +1,23 @@
1
- // src/cli/index.ts
2
- import process5 from "node:process";
3
- import * as p5 from "@clack/prompts";
4
- import c5 from "ansis";
1
+ import process from "node:process";
2
+ import * as p$4 from "@clack/prompts";
3
+ import * as p$3 from "@clack/prompts";
4
+ import * as p$2 from "@clack/prompts";
5
+ import * as p$1 from "@clack/prompts";
6
+ import * as p from "@clack/prompts";
7
+ import c, { green } from "ansis";
5
8
  import { cac } from "cac";
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+ import fsp from "node:fs/promises";
12
+ import parse from "parse-gitignore";
13
+ import { execSync } from "node:child_process";
6
14
 
7
- // package.json
8
- var version = "4.13.0";
9
-
10
- // src/cli/run.ts
11
- import fs3 from "node:fs";
12
- import path4 from "node:path";
13
- import process4 from "node:process";
14
- import * as p4 from "@clack/prompts";
15
- import c4 from "ansis";
15
+ //#region package.json
16
+ var version = "4.13.2";
16
17
 
17
- // src/cli/constants.ts
18
- import c from "ansis";
19
- var vscodeSettingsString = `
18
+ //#endregion
19
+ //#region src/cli/constants.ts
20
+ const vscodeSettingsString = `
20
21
  // Disable the default formatter, use eslint instead
21
22
  "prettier.enable": false,
22
23
  "editor.formatOnSave": false,
@@ -67,345 +68,279 @@ var vscodeSettingsString = `
67
68
  "postcss"
68
69
  ]
69
70
  `;
70
- var frameworkOptions = [
71
- {
72
- label: c.green("Vue"),
73
- value: "vue"
74
- },
75
- {
76
- label: c.cyan("React"),
77
- value: "react"
78
- },
79
- {
80
- label: c.red("Svelte"),
81
- value: "svelte"
82
- },
83
- {
84
- label: c.magenta("Astro"),
85
- value: "astro"
86
- },
87
- {
88
- label: c.cyan("Solid"),
89
- value: "solid"
90
- },
91
- {
92
- label: c.blue("Slidev"),
93
- value: "slidev"
94
- }
71
+ const frameworkOptions = [
72
+ {
73
+ label: c.green("Vue"),
74
+ value: "vue"
75
+ },
76
+ {
77
+ label: c.cyan("React"),
78
+ value: "react"
79
+ },
80
+ {
81
+ label: c.red("Svelte"),
82
+ value: "svelte"
83
+ },
84
+ {
85
+ label: c.magenta("Astro"),
86
+ value: "astro"
87
+ },
88
+ {
89
+ label: c.cyan("Solid"),
90
+ value: "solid"
91
+ },
92
+ {
93
+ label: c.blue("Slidev"),
94
+ value: "slidev"
95
+ }
95
96
  ];
96
- var frameworks = frameworkOptions.map(({ value }) => value);
97
- var extraOptions = [
98
- {
99
- hint: "Use external formatters (Prettier and/or dprint) to format files that ESLint cannot handle yet (.css, .html, etc)",
100
- label: c.red("Formatter"),
101
- value: "formatter"
102
- },
103
- {
104
- label: c.cyan("UnoCSS"),
105
- value: "unocss"
106
- }
107
- ];
108
- var extra = extraOptions.map(({ value }) => value);
109
- var dependenciesMap = {
110
- astro: [
111
- "eslint-plugin-astro",
112
- "astro-eslint-parser"
113
- ],
114
- formatter: [
115
- "eslint-plugin-format"
116
- ],
117
- formatterAstro: [
118
- "prettier-plugin-astro"
119
- ],
120
- react: [
121
- "@eslint-react/eslint-plugin",
122
- "eslint-plugin-react-hooks",
123
- "eslint-plugin-react-refresh"
124
- ],
125
- slidev: [
126
- "prettier-plugin-slidev"
127
- ],
128
- solid: [
129
- "eslint-plugin-solid"
130
- ],
131
- svelte: [
132
- "eslint-plugin-svelte",
133
- "svelte-eslint-parser"
134
- ],
135
- unocss: [
136
- "@unocss/eslint-plugin"
137
- ],
138
- vue: []
97
+ const frameworks = frameworkOptions.map(({ value }) => value);
98
+ const extraOptions = [{
99
+ hint: "Use external formatters (Prettier and/or dprint) to format files that ESLint cannot handle yet (.css, .html, etc)",
100
+ label: c.red("Formatter"),
101
+ value: "formatter"
102
+ }, {
103
+ label: c.cyan("UnoCSS"),
104
+ value: "unocss"
105
+ }];
106
+ const extra = extraOptions.map(({ value }) => value);
107
+ const dependenciesMap = {
108
+ astro: ["eslint-plugin-astro", "astro-eslint-parser"],
109
+ formatter: ["eslint-plugin-format"],
110
+ formatterAstro: ["prettier-plugin-astro"],
111
+ react: [
112
+ "@eslint-react/eslint-plugin",
113
+ "eslint-plugin-react-hooks",
114
+ "eslint-plugin-react-refresh"
115
+ ],
116
+ slidev: ["prettier-plugin-slidev"],
117
+ solid: ["eslint-plugin-solid"],
118
+ svelte: ["eslint-plugin-svelte", "svelte-eslint-parser"],
119
+ unocss: ["@unocss/eslint-plugin"],
120
+ vue: []
139
121
  };
140
122
 
141
- // src/cli/stages/update-eslint-files.ts
142
- import fs from "node:fs";
143
- import fsp from "node:fs/promises";
144
- import path from "node:path";
145
- import process from "node:process";
146
- import * as p from "@clack/prompts";
147
- import c2 from "ansis";
148
- import parse from "parse-gitignore";
149
-
150
- // src/cli/utils.ts
151
- import { execSync } from "node:child_process";
123
+ //#endregion
124
+ //#region src/cli/utils.ts
152
125
  function isGitClean() {
153
- try {
154
- execSync("git diff-index --quiet HEAD --");
155
- return true;
156
- } catch {
157
- return false;
158
- }
126
+ try {
127
+ execSync("git diff-index --quiet HEAD --");
128
+ return true;
129
+ } catch {
130
+ return false;
131
+ }
159
132
  }
160
133
  function getEslintConfigContent(mainConfig, additionalConfigs) {
161
- return `
134
+ return `
162
135
  import antfu from '@antfu/eslint-config'
163
136
 
164
137
  export default antfu({
165
138
  ${mainConfig}
166
- }${additionalConfigs?.map((config) => `,{
167
- ${config}
168
- }`)})
139
+ }${additionalConfigs?.map((config) => `,{\n${config}\n}`)})
169
140
  `.trimStart();
170
141
  }
171
142
 
172
- // src/cli/stages/update-eslint-files.ts
143
+ //#endregion
144
+ //#region src/cli/stages/update-eslint-files.ts
173
145
  async function updateEslintFiles(result) {
174
- const cwd = process.cwd();
175
- const pathESLintIgnore = path.join(cwd, ".eslintignore");
176
- const pathPackageJSON = path.join(cwd, "package.json");
177
- const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
178
- const pkg = JSON.parse(pkgContent);
179
- const configFileName = pkg.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
180
- const pathFlatConfig = path.join(cwd, configFileName);
181
- const eslintIgnores = [];
182
- if (fs.existsSync(pathESLintIgnore)) {
183
- p.log.step(c2.cyan`Migrating existing .eslintignore`);
184
- const content = await fsp.readFile(pathESLintIgnore, "utf-8");
185
- const parsed = parse(content);
186
- const globs = parsed.globs();
187
- for (const glob of globs) {
188
- if (glob.type === "ignore")
189
- eslintIgnores.push(...glob.patterns);
190
- else if (glob.type === "unignore")
191
- eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
192
- }
193
- }
194
- const configLines = [];
195
- if (eslintIgnores.length)
196
- configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
197
- if (result.extra.includes("formatter"))
198
- configLines.push(`formatters: true,`);
199
- if (result.extra.includes("unocss"))
200
- configLines.push(`unocss: true,`);
201
- for (const framework of result.frameworks)
202
- configLines.push(`${framework}: true,`);
203
- const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
204
- const additionalConfig = [];
205
- const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
206
- await fsp.writeFile(pathFlatConfig, eslintConfigContent);
207
- p.log.success(c2.green`Created ${configFileName}`);
208
- const files = fs.readdirSync(cwd);
209
- const legacyConfig = [];
210
- files.forEach((file) => {
211
- if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file))
212
- legacyConfig.push(file);
213
- });
214
- if (legacyConfig.length)
215
- p.note(c2.dim(legacyConfig.join(", ")), "You can now remove those files manually");
146
+ const cwd = process.cwd();
147
+ const pathESLintIgnore = path.join(cwd, ".eslintignore");
148
+ const pathPackageJSON = path.join(cwd, "package.json");
149
+ const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
150
+ const pkg = JSON.parse(pkgContent);
151
+ const configFileName = pkg.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
152
+ const pathFlatConfig = path.join(cwd, configFileName);
153
+ const eslintIgnores = [];
154
+ if (fs.existsSync(pathESLintIgnore)) {
155
+ p$4.log.step(c.cyan`Migrating existing .eslintignore`);
156
+ const content = await fsp.readFile(pathESLintIgnore, "utf-8");
157
+ const parsed = parse(content);
158
+ const globs = parsed.globs();
159
+ for (const glob of globs) if (glob.type === "ignore") eslintIgnores.push(...glob.patterns);
160
+ else if (glob.type === "unignore") eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
161
+ }
162
+ const configLines = [];
163
+ if (eslintIgnores.length) configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
164
+ if (result.extra.includes("formatter")) configLines.push(`formatters: true,`);
165
+ if (result.extra.includes("unocss")) configLines.push(`unocss: true,`);
166
+ for (const framework of result.frameworks) configLines.push(`${framework}: true,`);
167
+ const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
168
+ const additionalConfig = [];
169
+ const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
170
+ await fsp.writeFile(pathFlatConfig, eslintConfigContent);
171
+ p$4.log.success(c.green`Created ${configFileName}`);
172
+ const files = fs.readdirSync(cwd);
173
+ const legacyConfig = [];
174
+ files.forEach((file) => {
175
+ if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file)) legacyConfig.push(file);
176
+ });
177
+ if (legacyConfig.length) p$4.note(c.dim(legacyConfig.join(", ")), "You can now remove those files manually");
216
178
  }
217
179
 
218
- // src/cli/stages/update-package-json.ts
219
- import fsp2 from "node:fs/promises";
220
- import path2 from "node:path";
221
- import process2 from "node:process";
222
- import * as p2 from "@clack/prompts";
223
- import c3 from "ansis";
224
-
225
- // src/cli/constants-generated.ts
226
- var versionsMap = {
227
- "@eslint-react/eslint-plugin": "^1.49.0",
228
- "@unocss/eslint-plugin": "^66.1.0",
229
- "astro-eslint-parser": "^1.2.2",
230
- "eslint": "^9.26.0",
231
- "eslint-plugin-astro": "^1.3.1",
232
- "eslint-plugin-format": "^1.0.1",
233
- "eslint-plugin-react-hooks": "^5.2.0",
234
- "eslint-plugin-react-refresh": "^0.4.20",
235
- "eslint-plugin-solid": "^0.14.5",
236
- "eslint-plugin-svelte": "^3.5.1",
237
- "prettier-plugin-astro": "^0.14.1",
238
- "prettier-plugin-slidev": "^1.0.5",
239
- "svelte-eslint-parser": "^1.1.3"
180
+ //#endregion
181
+ //#region src/cli/constants-generated.ts
182
+ const versionsMap = {
183
+ "@eslint-react/eslint-plugin": "^1.49.0",
184
+ "@unocss/eslint-plugin": "^66.1.2",
185
+ "astro-eslint-parser": "^1.2.2",
186
+ "eslint": "^9.27.0",
187
+ "eslint-plugin-astro": "^1.3.1",
188
+ "eslint-plugin-format": "^1.0.1",
189
+ "eslint-plugin-react-hooks": "^5.2.0",
190
+ "eslint-plugin-react-refresh": "^0.4.20",
191
+ "eslint-plugin-solid": "^0.14.5",
192
+ "eslint-plugin-svelte": "^3.8.2",
193
+ "prettier-plugin-astro": "^0.14.1",
194
+ "prettier-plugin-slidev": "^1.0.5",
195
+ "svelte-eslint-parser": "^1.2.0"
240
196
  };
241
197
 
242
- // src/cli/stages/update-package-json.ts
198
+ //#endregion
199
+ //#region src/cli/stages/update-package-json.ts
243
200
  async function updatePackageJson(result) {
244
- const cwd = process2.cwd();
245
- const pathPackageJSON = path2.join(cwd, "package.json");
246
- p2.log.step(c3.cyan`Bumping @antfu/eslint-config to v${version}`);
247
- const pkgContent = await fsp2.readFile(pathPackageJSON, "utf-8");
248
- const pkg = JSON.parse(pkgContent);
249
- pkg.devDependencies ??= {};
250
- pkg.devDependencies["@antfu/eslint-config"] = `^${version}`;
251
- pkg.devDependencies.eslint ??= versionsMap.eslint;
252
- const addedPackages = [];
253
- if (result.extra.length) {
254
- result.extra.forEach((item) => {
255
- switch (item) {
256
- case "formatter":
257
- [
258
- ...dependenciesMap.formatter,
259
- ...result.frameworks.includes("astro") ? dependenciesMap.formatterAstro : []
260
- ].forEach((f) => {
261
- if (!f)
262
- return;
263
- pkg.devDependencies[f] = versionsMap[f];
264
- addedPackages.push(f);
265
- });
266
- break;
267
- case "unocss":
268
- dependenciesMap.unocss.forEach((f) => {
269
- pkg.devDependencies[f] = versionsMap[f];
270
- addedPackages.push(f);
271
- });
272
- break;
273
- }
274
- });
275
- }
276
- for (const framework of result.frameworks) {
277
- const deps = dependenciesMap[framework];
278
- if (deps) {
279
- deps.forEach((f) => {
280
- pkg.devDependencies[f] = versionsMap[f];
281
- addedPackages.push(f);
282
- });
283
- }
284
- }
285
- if (addedPackages.length)
286
- p2.note(c3.dim(addedPackages.join(", ")), "Added packages");
287
- await fsp2.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
288
- p2.log.success(c3.green`Changes wrote to package.json`);
201
+ const cwd = process.cwd();
202
+ const pathPackageJSON = path.join(cwd, "package.json");
203
+ p$3.log.step(c.cyan`Bumping @antfu/eslint-config to v${version}`);
204
+ const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
205
+ const pkg = JSON.parse(pkgContent);
206
+ pkg.devDependencies ??= {};
207
+ pkg.devDependencies["@antfu/eslint-config"] = `^${version}`;
208
+ pkg.devDependencies.eslint ??= versionsMap.eslint;
209
+ const addedPackages = [];
210
+ if (result.extra.length) result.extra.forEach((item) => {
211
+ switch (item) {
212
+ case "formatter":
213
+ [...dependenciesMap.formatter, ...result.frameworks.includes("astro") ? dependenciesMap.formatterAstro : []].forEach((f) => {
214
+ if (!f) return;
215
+ pkg.devDependencies[f] = versionsMap[f];
216
+ addedPackages.push(f);
217
+ });
218
+ break;
219
+ case "unocss":
220
+ dependenciesMap.unocss.forEach((f) => {
221
+ pkg.devDependencies[f] = versionsMap[f];
222
+ addedPackages.push(f);
223
+ });
224
+ break;
225
+ }
226
+ });
227
+ for (const framework of result.frameworks) {
228
+ const deps = dependenciesMap[framework];
229
+ if (deps) deps.forEach((f) => {
230
+ pkg.devDependencies[f] = versionsMap[f];
231
+ addedPackages.push(f);
232
+ });
233
+ }
234
+ if (addedPackages.length) p$3.note(c.dim(addedPackages.join(", ")), "Added packages");
235
+ await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
236
+ p$3.log.success(c.green`Changes wrote to package.json`);
289
237
  }
290
238
 
291
- // src/cli/stages/update-vscode-settings.ts
292
- import fs2 from "node:fs";
293
- import fsp3 from "node:fs/promises";
294
- import path3 from "node:path";
295
- import process3 from "node:process";
296
- import * as p3 from "@clack/prompts";
297
- import { green } from "ansis";
239
+ //#endregion
240
+ //#region src/cli/stages/update-vscode-settings.ts
298
241
  async function updateVscodeSettings(result) {
299
- const cwd = process3.cwd();
300
- if (!result.updateVscodeSettings)
301
- return;
302
- const dotVscodePath = path3.join(cwd, ".vscode");
303
- const settingsPath = path3.join(dotVscodePath, "settings.json");
304
- if (!fs2.existsSync(dotVscodePath))
305
- await fsp3.mkdir(dotVscodePath, { recursive: true });
306
- if (!fs2.existsSync(settingsPath)) {
307
- await fsp3.writeFile(settingsPath, `{${vscodeSettingsString}}
308
- `, "utf-8");
309
- p3.log.success(green`Created .vscode/settings.json`);
310
- } else {
311
- let settingsContent = await fsp3.readFile(settingsPath, "utf8");
312
- settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
313
- settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
314
- settingsContent += `${vscodeSettingsString}}
315
- `;
316
- await fsp3.writeFile(settingsPath, settingsContent, "utf-8");
317
- p3.log.success(green`Updated .vscode/settings.json`);
318
- }
242
+ const cwd = process.cwd();
243
+ if (!result.updateVscodeSettings) return;
244
+ const dotVscodePath = path.join(cwd, ".vscode");
245
+ const settingsPath = path.join(dotVscodePath, "settings.json");
246
+ if (!fs.existsSync(dotVscodePath)) await fsp.mkdir(dotVscodePath, { recursive: true });
247
+ if (!fs.existsSync(settingsPath)) {
248
+ await fsp.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf-8");
249
+ p$2.log.success(green`Created .vscode/settings.json`);
250
+ } else {
251
+ let settingsContent = await fsp.readFile(settingsPath, "utf8");
252
+ settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
253
+ settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
254
+ settingsContent += `${vscodeSettingsString}}\n`;
255
+ await fsp.writeFile(settingsPath, settingsContent, "utf-8");
256
+ p$2.log.success(green`Updated .vscode/settings.json`);
257
+ }
319
258
  }
320
259
 
321
- // src/cli/run.ts
260
+ //#endregion
261
+ //#region src/cli/run.ts
322
262
  async function run(options = {}) {
323
- const argSkipPrompt = !!process4.env.SKIP_PROMPT || options.yes;
324
- const argTemplate = options.frameworks?.map((m) => m?.trim()).filter(Boolean);
325
- const argExtra = options.extra?.map((m) => m?.trim()).filter(Boolean);
326
- if (fs3.existsSync(path4.join(process4.cwd(), "eslint.config.js"))) {
327
- p4.log.warn(c4.yellow`eslint.config.js already exists, migration wizard exited.`);
328
- return process4.exit(1);
329
- }
330
- let result = {
331
- extra: argExtra ?? [],
332
- frameworks: argTemplate ?? [],
333
- uncommittedConfirmed: false,
334
- updateVscodeSettings: true
335
- };
336
- if (!argSkipPrompt) {
337
- result = await p4.group({
338
- uncommittedConfirmed: () => {
339
- if (argSkipPrompt || isGitClean())
340
- return Promise.resolve(true);
341
- return p4.confirm({
342
- initialValue: false,
343
- message: "There are uncommitted changes in the current repository, are you sure to continue?"
344
- });
345
- },
346
- frameworks: ({ results }) => {
347
- const isArgTemplateValid = typeof argTemplate === "string" && !!frameworks.includes(argTemplate);
348
- if (!results.uncommittedConfirmed || isArgTemplateValid)
349
- return;
350
- const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
351
- return p4.multiselect({
352
- message: c4.reset(message),
353
- options: frameworkOptions,
354
- required: false
355
- });
356
- },
357
- extra: ({ results }) => {
358
- const isArgExtraValid = argExtra?.length && !argExtra.filter((element) => !extra.includes(element)).length;
359
- if (!results.uncommittedConfirmed || isArgExtraValid)
360
- return;
361
- const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
362
- return p4.multiselect({
363
- message: c4.reset(message),
364
- options: extraOptions,
365
- required: false
366
- });
367
- },
368
- updateVscodeSettings: ({ results }) => {
369
- if (!results.uncommittedConfirmed)
370
- return;
371
- return p4.confirm({
372
- initialValue: true,
373
- message: "Update .vscode/settings.json for better VS Code experience?"
374
- });
375
- }
376
- }, {
377
- onCancel: () => {
378
- p4.cancel("Operation cancelled.");
379
- process4.exit(0);
380
- }
381
- });
382
- if (!result.uncommittedConfirmed)
383
- return process4.exit(1);
384
- }
385
- await updatePackageJson(result);
386
- await updateEslintFiles(result);
387
- await updateVscodeSettings(result);
388
- p4.log.success(c4.green`Setup completed`);
389
- p4.outro(`Now you can update the dependencies by run ${c4.blue("pnpm install")} and run ${c4.blue("eslint --fix")}
390
- `);
263
+ const argSkipPrompt = !!process.env.SKIP_PROMPT || options.yes;
264
+ const argTemplate = options.frameworks?.map((m) => m?.trim()).filter(Boolean);
265
+ const argExtra = options.extra?.map((m) => m?.trim()).filter(Boolean);
266
+ if (fs.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
267
+ p$1.log.warn(c.yellow`eslint.config.js already exists, migration wizard exited.`);
268
+ return process.exit(1);
269
+ }
270
+ let result = {
271
+ extra: argExtra ?? [],
272
+ frameworks: argTemplate ?? [],
273
+ uncommittedConfirmed: false,
274
+ updateVscodeSettings: true
275
+ };
276
+ if (!argSkipPrompt) {
277
+ result = await p$1.group({
278
+ uncommittedConfirmed: () => {
279
+ if (argSkipPrompt || isGitClean()) return Promise.resolve(true);
280
+ return p$1.confirm({
281
+ initialValue: false,
282
+ message: "There are uncommitted changes in the current repository, are you sure to continue?"
283
+ });
284
+ },
285
+ frameworks: ({ results }) => {
286
+ const isArgTemplateValid = typeof argTemplate === "string" && !!frameworks.includes(argTemplate);
287
+ if (!results.uncommittedConfirmed || isArgTemplateValid) return;
288
+ const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
289
+ return p$1.multiselect({
290
+ message: c.reset(message),
291
+ options: frameworkOptions,
292
+ required: false
293
+ });
294
+ },
295
+ extra: ({ results }) => {
296
+ const isArgExtraValid = argExtra?.length && !argExtra.filter((element) => !extra.includes(element)).length;
297
+ if (!results.uncommittedConfirmed || isArgExtraValid) return;
298
+ const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
299
+ return p$1.multiselect({
300
+ message: c.reset(message),
301
+ options: extraOptions,
302
+ required: false
303
+ });
304
+ },
305
+ updateVscodeSettings: ({ results }) => {
306
+ if (!results.uncommittedConfirmed) return;
307
+ return p$1.confirm({
308
+ initialValue: true,
309
+ message: "Update .vscode/settings.json for better VS Code experience?"
310
+ });
311
+ }
312
+ }, { onCancel: () => {
313
+ p$1.cancel("Operation cancelled.");
314
+ process.exit(0);
315
+ } });
316
+ if (!result.uncommittedConfirmed) return process.exit(1);
317
+ }
318
+ await updatePackageJson(result);
319
+ await updateEslintFiles(result);
320
+ await updateVscodeSettings(result);
321
+ p$1.log.success(c.green`Setup completed`);
322
+ p$1.outro(`Now you can update the dependencies by run ${c.blue("pnpm install")} and run ${c.blue("eslint --fix")}\n`);
391
323
  }
392
324
 
393
- // src/cli/index.ts
325
+ //#endregion
326
+ //#region src/cli/index.ts
394
327
  function header() {
395
- console.log("\n");
396
- p5.intro(`${c5.green`@antfu/eslint-config `}${c5.dim`v${version}`}`);
328
+ console.log("\n");
329
+ p.intro(`${c.green`@antfu/eslint-config `}${c.dim`v${version}`}`);
397
330
  }
398
- var cli = cac("@antfu/eslint-config");
331
+ const cli = cac("@antfu/eslint-config");
399
332
  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) => {
400
- header();
401
- try {
402
- await run(args);
403
- } catch (error) {
404
- p5.log.error(c5.inverse.red(" Failed to migrate "));
405
- p5.log.error(c5.red`✘ ${String(error)}`);
406
- process5.exit(1);
407
- }
333
+ header();
334
+ try {
335
+ await run(args);
336
+ } catch (error) {
337
+ p.log.error(c.inverse.red(" Failed to migrate "));
338
+ p.log.error(c.red`✘ ${String(error)}`);
339
+ process.exit(1);
340
+ }
408
341
  });
409
342
  cli.help();
410
343
  cli.version(version);
411
344
  cli.parse();
345
+
346
+ //#endregion