@kirklin/eslint-config 8.0.2 → 8.2.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.mjs +32 -44
- package/dist/index.d.mts +629 -525
- package/dist/index.mjs +93 -169
- package/dist/{lib-4A9shWox.mjs → lib-EoktVv6C.mjs} +2731 -2507
- package/package.json +67 -57
package/dist/cli.mjs
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
-
import
|
|
3
|
-
import fs from "node:fs";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import fs$1 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";
|
|
7
7
|
import { cac } from "cac";
|
|
8
8
|
import parse from "parse-gitignore";
|
|
9
9
|
import { execSync } from "node:child_process";
|
|
10
|
-
|
|
11
10
|
//#region package.json
|
|
12
|
-
var version = "8.0
|
|
13
|
-
|
|
11
|
+
var version = "8.2.0";
|
|
14
12
|
//#endregion
|
|
15
13
|
//#region src/cli/constants.ts
|
|
16
14
|
const vscodeSettingsString = `
|
|
@@ -105,18 +103,13 @@ const dependenciesMap = {
|
|
|
105
103
|
formatter: ["eslint-plugin-format"],
|
|
106
104
|
formatterAstro: ["prettier-plugin-astro"],
|
|
107
105
|
nextjs: ["@next/eslint-plugin-next"],
|
|
108
|
-
react: [
|
|
109
|
-
"@eslint-react/eslint-plugin",
|
|
110
|
-
"eslint-plugin-react-hooks",
|
|
111
|
-
"eslint-plugin-react-refresh"
|
|
112
|
-
],
|
|
106
|
+
react: ["@eslint-react/eslint-plugin", "eslint-plugin-react-refresh"],
|
|
113
107
|
slidev: ["prettier-plugin-slidev"],
|
|
114
108
|
solid: ["eslint-plugin-solid"],
|
|
115
109
|
svelte: ["eslint-plugin-svelte", "svelte-eslint-parser"],
|
|
116
110
|
unocss: ["@unocss/eslint-plugin"],
|
|
117
111
|
vue: []
|
|
118
112
|
};
|
|
119
|
-
|
|
120
113
|
//#endregion
|
|
121
114
|
//#region src/cli/utils.ts
|
|
122
115
|
function isGitClean() {
|
|
@@ -136,20 +129,21 @@ ${mainConfig}
|
|
|
136
129
|
}${additionalConfigs?.map((config) => `,{\n${config}\n}`)})
|
|
137
130
|
`.trimStart();
|
|
138
131
|
}
|
|
139
|
-
|
|
140
132
|
//#endregion
|
|
141
133
|
//#region src/cli/stages/update-eslint-files.ts
|
|
134
|
+
const ESLINT_OR_PRETTIER = /eslint|prettier/;
|
|
135
|
+
const ESLINT_CONFIG = /eslint\.config\./;
|
|
142
136
|
async function updateEslintFiles(result) {
|
|
143
137
|
const cwd = process.cwd();
|
|
144
138
|
const pathESLintIgnore = path.join(cwd, ".eslintignore");
|
|
145
139
|
const pathPackageJSON = path.join(cwd, "package.json");
|
|
146
|
-
const pkgContent = await
|
|
140
|
+
const pkgContent = await fs.readFile(pathPackageJSON, "utf-8");
|
|
147
141
|
const configFileName = JSON.parse(pkgContent).type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
148
142
|
const pathFlatConfig = path.join(cwd, configFileName);
|
|
149
143
|
const eslintIgnores = [];
|
|
150
|
-
if (fs.existsSync(pathESLintIgnore)) {
|
|
144
|
+
if (fs$1.existsSync(pathESLintIgnore)) {
|
|
151
145
|
p.log.step(c.cyan`Migrating existing .eslintignore`);
|
|
152
|
-
const globs = parse(await
|
|
146
|
+
const globs = parse(await fs.readFile(pathESLintIgnore, "utf-8")).globs();
|
|
153
147
|
for (const glob of globs) if (glob.type === "ignore") eslintIgnores.push(...glob.patterns);
|
|
154
148
|
else if (glob.type === "unignore") eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
|
|
155
149
|
}
|
|
@@ -159,42 +153,39 @@ async function updateEslintFiles(result) {
|
|
|
159
153
|
if (result.extra.includes("unocss")) configLines.push(`unocss: true,`);
|
|
160
154
|
for (const framework of result.frameworks) configLines.push(`${framework}: true,`);
|
|
161
155
|
const eslintConfigContent = getEslintConfigContent(configLines.map((i) => ` ${i}`).join("\n"), []);
|
|
162
|
-
await
|
|
156
|
+
await fs.writeFile(pathFlatConfig, eslintConfigContent);
|
|
163
157
|
p.log.success(c.green`Created ${configFileName}`);
|
|
164
|
-
const files = fs.readdirSync(cwd);
|
|
158
|
+
const files = fs$1.readdirSync(cwd);
|
|
165
159
|
const legacyConfig = [];
|
|
166
160
|
files.forEach((file) => {
|
|
167
|
-
if (
|
|
161
|
+
if (ESLINT_OR_PRETTIER.test(file) && !ESLINT_CONFIG.test(file)) legacyConfig.push(file);
|
|
168
162
|
});
|
|
169
163
|
if (legacyConfig.length) p.note(c.dim(legacyConfig.join(", ")), "You can now remove those files manually");
|
|
170
164
|
}
|
|
171
|
-
|
|
172
165
|
//#endregion
|
|
173
166
|
//#region src/cli/constants-generated.ts
|
|
174
167
|
const versionsMap = {
|
|
175
|
-
"@eslint-react/eslint-plugin": "^
|
|
176
|
-
"@next/eslint-plugin-next": "^16.
|
|
177
|
-
"@unocss/eslint-plugin": "^66.6.
|
|
178
|
-
"astro-eslint-parser": "^1.
|
|
179
|
-
"eslint": "^10.
|
|
168
|
+
"@eslint-react/eslint-plugin": "^3.0.0",
|
|
169
|
+
"@next/eslint-plugin-next": "^16.2.2",
|
|
170
|
+
"@unocss/eslint-plugin": "^66.6.7",
|
|
171
|
+
"astro-eslint-parser": "^1.4.0",
|
|
172
|
+
"eslint": "^10.1.0",
|
|
180
173
|
"eslint-plugin-astro": "^1.6.0",
|
|
181
|
-
"eslint-plugin-format": "^
|
|
182
|
-
"eslint-plugin-react-
|
|
183
|
-
"eslint-plugin-react-refresh": "^0.5.0",
|
|
174
|
+
"eslint-plugin-format": "^2.0.1",
|
|
175
|
+
"eslint-plugin-react-refresh": "^0.5.2",
|
|
184
176
|
"eslint-plugin-solid": "^0.14.5",
|
|
185
|
-
"eslint-plugin-svelte": "^3.
|
|
177
|
+
"eslint-plugin-svelte": "^3.16.0",
|
|
186
178
|
"prettier-plugin-astro": "^0.14.1",
|
|
187
179
|
"prettier-plugin-slidev": "^1.0.5",
|
|
188
|
-
"svelte-eslint-parser": "^1.
|
|
180
|
+
"svelte-eslint-parser": "^1.6.0"
|
|
189
181
|
};
|
|
190
|
-
|
|
191
182
|
//#endregion
|
|
192
183
|
//#region src/cli/stages/update-package-json.ts
|
|
193
184
|
async function updatePackageJson(result) {
|
|
194
185
|
const cwd = process.cwd();
|
|
195
186
|
const pathPackageJSON = path.join(cwd, "package.json");
|
|
196
187
|
p.log.step(c.cyan`Bumping @kirklin/eslint-config to v${version}`);
|
|
197
|
-
const pkgContent = await
|
|
188
|
+
const pkgContent = await fs.readFile(pathPackageJSON, "utf-8");
|
|
198
189
|
const pkg = JSON.parse(pkgContent);
|
|
199
190
|
pkg.devDependencies ??= {};
|
|
200
191
|
pkg.devDependencies["@kirklin/eslint-config"] = `^${version}`;
|
|
@@ -225,38 +216,37 @@ async function updatePackageJson(result) {
|
|
|
225
216
|
});
|
|
226
217
|
}
|
|
227
218
|
if (addedPackages.length) p.note(c.dim(addedPackages.join(", ")), "Added packages");
|
|
228
|
-
await
|
|
219
|
+
await fs.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
229
220
|
p.log.success(c.green`Changes wrote to package.json`);
|
|
230
221
|
}
|
|
231
|
-
|
|
232
222
|
//#endregion
|
|
233
223
|
//#region src/cli/stages/update-vscode-settings.ts
|
|
224
|
+
const LAST_LINE_PATTERN = /\s*\}$/;
|
|
234
225
|
async function updateVscodeSettings(result) {
|
|
235
226
|
const cwd = process.cwd();
|
|
236
227
|
if (!result.updateVscodeSettings) return;
|
|
237
228
|
const dotVscodePath = path.join(cwd, ".vscode");
|
|
238
229
|
const settingsPath = path.join(dotVscodePath, "settings.json");
|
|
239
|
-
if (!fs.existsSync(dotVscodePath)) await
|
|
240
|
-
if (!fs.existsSync(settingsPath)) {
|
|
241
|
-
await
|
|
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");
|
|
242
233
|
p.log.success(green`Created .vscode/settings.json`);
|
|
243
234
|
} else {
|
|
244
|
-
let settingsContent = await
|
|
245
|
-
settingsContent = settingsContent.trim().replace(
|
|
235
|
+
let settingsContent = await fs.readFile(settingsPath, "utf8");
|
|
236
|
+
settingsContent = settingsContent.trim().replace(LAST_LINE_PATTERN, "");
|
|
246
237
|
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
247
238
|
settingsContent += `${vscodeSettingsString}}\n`;
|
|
248
|
-
await
|
|
239
|
+
await fs.writeFile(settingsPath, settingsContent, "utf-8");
|
|
249
240
|
p.log.success(green`Updated .vscode/settings.json`);
|
|
250
241
|
}
|
|
251
242
|
}
|
|
252
|
-
|
|
253
243
|
//#endregion
|
|
254
244
|
//#region src/cli/run.ts
|
|
255
245
|
async function run(options = {}) {
|
|
256
246
|
const argSkipPrompt = !!process.env.SKIP_PROMPT || options.yes;
|
|
257
247
|
const argTemplate = options.frameworks?.map((m) => m?.trim()).filter(Boolean);
|
|
258
248
|
const argExtra = options.extra?.map((m) => m?.trim()).filter(Boolean);
|
|
259
|
-
if (fs.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
|
|
249
|
+
if (fs$1.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
|
|
260
250
|
p.log.warn(c.yellow`eslint.config.js already exists, migration wizard exited.`);
|
|
261
251
|
return process.exit(1);
|
|
262
252
|
}
|
|
@@ -314,7 +304,6 @@ async function run(options = {}) {
|
|
|
314
304
|
p.log.success(c.green`Setup completed`);
|
|
315
305
|
p.outro(`Now you can update the dependencies by run ${c.blue("pnpm install")} and run ${c.blue("eslint --fix")}\n`);
|
|
316
306
|
}
|
|
317
|
-
|
|
318
307
|
//#endregion
|
|
319
308
|
//#region src/cli/index.ts
|
|
320
309
|
function header() {
|
|
@@ -335,6 +324,5 @@ cli.command("", "Run the initialization or migration").option("--yes, -y", "Skip
|
|
|
335
324
|
cli.help();
|
|
336
325
|
cli.version(version);
|
|
337
326
|
cli.parse();
|
|
338
|
-
|
|
339
327
|
//#endregion
|
|
340
|
-
export {
|
|
328
|
+
export {};
|