@antfu/eslint-config 8.3.0 → 9.1.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 CHANGED
@@ -547,6 +547,10 @@ export default antfu({
547
547
  overrides: {
548
548
  'ts/consistent-type-definitions': ['error', 'interface'],
549
549
  },
550
+ // type aware rules overrides should write here
551
+ overridesTypeAware: {
552
+ 'ts/no-unsafe-assignment': ['warn'],
553
+ }
550
554
  },
551
555
  yaml: {
552
556
  overrides: {
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import process from "node:process";
2
- import fs from "node:fs/promises";
3
- import fs$1 from "node:fs";
2
+ import fsPromises from "node:fs/promises";
3
+ import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import * as p from "@clack/prompts";
6
6
  import c, { green } from "ansis";
@@ -8,7 +8,7 @@ import { cac } from "cac";
8
8
  import parse from "parse-gitignore";
9
9
  import { execSync } from "node:child_process";
10
10
  //#region package.json
11
- var version = "8.3.0";
11
+ var version = "9.1.0";
12
12
  //#endregion
13
13
  //#region src/cli/constants.ts
14
14
  const vscodeSettingsString = `
@@ -137,13 +137,13 @@ async function updateEslintFiles(result) {
137
137
  const cwd = process.cwd();
138
138
  const pathESLintIgnore = path.join(cwd, ".eslintignore");
139
139
  const pathPackageJSON = path.join(cwd, "package.json");
140
- const pkgContent = await fs.readFile(pathPackageJSON, "utf-8");
140
+ const pkgContent = await fsPromises.readFile(pathPackageJSON, "utf-8");
141
141
  const configFileName = JSON.parse(pkgContent).type === "module" ? "eslint.config.js" : "eslint.config.mjs";
142
142
  const pathFlatConfig = path.join(cwd, configFileName);
143
143
  const eslintIgnores = [];
144
- if (fs$1.existsSync(pathESLintIgnore)) {
144
+ if (fs.existsSync(pathESLintIgnore)) {
145
145
  p.log.step(c.cyan`Migrating existing .eslintignore`);
146
- const globs = parse(await fs.readFile(pathESLintIgnore, "utf-8")).globs();
146
+ const globs = parse(await fsPromises.readFile(pathESLintIgnore, "utf-8")).globs();
147
147
  for (const glob of globs) if (glob.type === "ignore") eslintIgnores.push(...glob.patterns);
148
148
  else if (glob.type === "unignore") eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
149
149
  }
@@ -153,9 +153,9 @@ async function updateEslintFiles(result) {
153
153
  if (result.extra.includes("unocss")) configLines.push(`unocss: true,`);
154
154
  for (const framework of result.frameworks) configLines.push(`${framework}: true,`);
155
155
  const eslintConfigContent = getEslintConfigContent(configLines.map((i) => ` ${i}`).join("\n"), []);
156
- await fs.writeFile(pathFlatConfig, eslintConfigContent);
156
+ await fsPromises.writeFile(pathFlatConfig, eslintConfigContent);
157
157
  p.log.success(c.green`Created ${configFileName}`);
158
- const files = fs$1.readdirSync(cwd);
158
+ const files = fs.readdirSync(cwd);
159
159
  const legacyConfig = [];
160
160
  files.forEach((file) => {
161
161
  if (ESLINT_OR_PRETTIER.test(file) && !ESLINT_CONFIG.test(file)) legacyConfig.push(file);
@@ -165,19 +165,19 @@ async function updateEslintFiles(result) {
165
165
  //#endregion
166
166
  //#region src/cli/constants-generated.ts
167
167
  const versionsMap = {
168
- "@eslint-react/eslint-plugin": "^3.0.0",
169
- "@next/eslint-plugin-next": "^16.2.6",
170
- "@unocss/eslint-plugin": "^66.6.8",
171
- "astro-eslint-parser": "^1.4.0",
172
- "eslint": "^10.3.0",
173
- "eslint-plugin-astro": "^1.7.0",
168
+ "@eslint-react/eslint-plugin": "^5.9.2",
169
+ "@next/eslint-plugin-next": "^16.2.9",
170
+ "@unocss/eslint-plugin": "^66.7.2",
171
+ "astro-eslint-parser": "^2.0.0",
172
+ "eslint": "^10.5.0",
173
+ "eslint-plugin-astro": "^2.0.0",
174
174
  "eslint-plugin-format": "^2.0.1",
175
- "eslint-plugin-react-refresh": "^0.5.2",
175
+ "eslint-plugin-react-refresh": "^0.5.3",
176
176
  "eslint-plugin-solid": "^0.14.5",
177
- "eslint-plugin-svelte": "^3.17.1",
177
+ "eslint-plugin-svelte": "^3.19.0",
178
178
  "prettier-plugin-astro": "^0.14.1",
179
179
  "prettier-plugin-slidev": "^1.0.5",
180
- "svelte-eslint-parser": "^1.6.1"
180
+ "svelte-eslint-parser": "^1.8.0"
181
181
  };
182
182
  //#endregion
183
183
  //#region src/cli/stages/update-package-json.ts
@@ -185,7 +185,7 @@ async function updatePackageJson(result) {
185
185
  const cwd = process.cwd();
186
186
  const pathPackageJSON = path.join(cwd, "package.json");
187
187
  p.log.step(c.cyan`Bumping @antfu/eslint-config to v${version}`);
188
- const pkgContent = await fs.readFile(pathPackageJSON, "utf-8");
188
+ const pkgContent = await fsPromises.readFile(pathPackageJSON, "utf-8");
189
189
  const pkg = JSON.parse(pkgContent);
190
190
  pkg.devDependencies ??= {};
191
191
  pkg.devDependencies["@antfu/eslint-config"] = `^${version}`;
@@ -216,7 +216,7 @@ async function updatePackageJson(result) {
216
216
  });
217
217
  }
218
218
  if (addedPackages.length) p.note(c.dim(addedPackages.join(", ")), "Added packages");
219
- await fs.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
219
+ await fsPromises.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
220
220
  p.log.success(c.green`Changes wrote to package.json`);
221
221
  }
222
222
  //#endregion
@@ -227,16 +227,16 @@ async function updateVscodeSettings(result) {
227
227
  if (!result.updateVscodeSettings) return;
228
228
  const dotVscodePath = path.join(cwd, ".vscode");
229
229
  const settingsPath = path.join(dotVscodePath, "settings.json");
230
- if (!fs$1.existsSync(dotVscodePath)) await fs.mkdir(dotVscodePath, { recursive: true });
231
- if (!fs$1.existsSync(settingsPath)) {
232
- await fs.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf-8");
230
+ if (!fs.existsSync(dotVscodePath)) await fsPromises.mkdir(dotVscodePath, { recursive: true });
231
+ if (!fs.existsSync(settingsPath)) {
232
+ await fsPromises.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf-8");
233
233
  p.log.success(green`Created .vscode/settings.json`);
234
234
  } else {
235
- let settingsContent = await fs.readFile(settingsPath, "utf8");
235
+ let settingsContent = await fsPromises.readFile(settingsPath, "utf8");
236
236
  settingsContent = settingsContent.trim().replace(LAST_LINE_PATTERN, "");
237
237
  settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
238
238
  settingsContent += `${vscodeSettingsString}}\n`;
239
- await fs.writeFile(settingsPath, settingsContent, "utf-8");
239
+ await fsPromises.writeFile(settingsPath, settingsContent, "utf-8");
240
240
  p.log.success(green`Updated .vscode/settings.json`);
241
241
  }
242
242
  }
@@ -246,7 +246,7 @@ async function run(options = {}) {
246
246
  const argSkipPrompt = !!process.env.SKIP_PROMPT || options.yes;
247
247
  const argTemplate = options.frameworks?.map((m) => m?.trim()).filter(Boolean);
248
248
  const argExtra = options.extra?.map((m) => m?.trim()).filter(Boolean);
249
- if (fs$1.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
249
+ if (fs.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
250
250
  p.log.warn(c.yellow`eslint.config.js already exists, migration wizard exited.`);
251
251
  return process.exit(1);
252
252
  }
@@ -276,7 +276,7 @@ async function run(options = {}) {
276
276
  });
277
277
  },
278
278
  extra: ({ results }) => {
279
- const isArgExtraValid = argExtra?.length && !argExtra.filter((element) => !extra.includes(element)).length;
279
+ const isArgExtraValid = argExtra?.length && argExtra.every((element) => extra.includes(element));
280
280
  if (!results.uncommittedConfirmed || isArgExtraValid) return;
281
281
  const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
282
282
  return p.multiselect({