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