@whoj/eslint-config 2.5.0 → 7.4.30
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 +724 -12
- package/bin/index.mjs +2 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +444 -0
- package/dist/index.d.mts +20584 -0
- package/dist/index.mjs +2654 -0
- package/dist/lib-DRA-mDV0.mjs +11181 -0
- package/package.json +184 -98
- package/bin/index.js +0 -2
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -729
- package/dist/index.d.ts +0 -17681
- package/dist/index.js +0 -2698
package/dist/cli.js
DELETED
|
@@ -1,729 +0,0 @@
|
|
|
1
|
-
// src/cli/index.ts
|
|
2
|
-
import yargs from "yargs";
|
|
3
|
-
import c7 from "picocolors";
|
|
4
|
-
import process6 from "node:process";
|
|
5
|
-
import * as p6 from "@clack/prompts";
|
|
6
|
-
import { hideBin } from "yargs/helpers";
|
|
7
|
-
|
|
8
|
-
// src/cli/run.ts
|
|
9
|
-
import fs4 from "node:fs";
|
|
10
|
-
import c6 from "picocolors";
|
|
11
|
-
import path5 from "node:path";
|
|
12
|
-
import process5 from "node:process";
|
|
13
|
-
import * as p5 from "@clack/prompts";
|
|
14
|
-
|
|
15
|
-
// src/cli/utils.ts
|
|
16
|
-
import { execSync } from "node:child_process";
|
|
17
|
-
function getEslintConfigContent(mainConfig, additionalConfigs) {
|
|
18
|
-
return `
|
|
19
|
-
import whoj from '@whoj/eslint-config';
|
|
20
|
-
|
|
21
|
-
export default whoj({
|
|
22
|
-
${mainConfig}
|
|
23
|
-
}${additionalConfigs?.map((config) => `,{
|
|
24
|
-
${config}
|
|
25
|
-
}`)});
|
|
26
|
-
`.trimStart();
|
|
27
|
-
}
|
|
28
|
-
function getJetbrainsEslintConfigContent(configFrom) {
|
|
29
|
-
return `
|
|
30
|
-
import whoj from "${configFrom}";
|
|
31
|
-
|
|
32
|
-
export default whoj.clone().overrides({
|
|
33
|
-
'whoj/javascript/rules': {
|
|
34
|
-
rules: {
|
|
35
|
-
'prefer-const': 'warn',
|
|
36
|
-
'unused-imports/no-unused-imports': 'warn'
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
'whoj/test/rules': {
|
|
40
|
-
rules: {
|
|
41
|
-
'test/no-only-tests': 'warn',
|
|
42
|
-
'test/consistent-test-it': ['error', { fn: 'it', withinDescribe: 'it' }],
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}).disableRulesFix([
|
|
46
|
-
'unused-imports/no-unused-imports',
|
|
47
|
-
'test/no-only-tests',
|
|
48
|
-
'prefer-const'
|
|
49
|
-
], {
|
|
50
|
-
builtinRules: () => import(['eslint', 'use-at-your-own-risk'].join('/')).then(r => r.builtinRules)
|
|
51
|
-
});
|
|
52
|
-
`.trimStart();
|
|
53
|
-
}
|
|
54
|
-
function isGitClean() {
|
|
55
|
-
try {
|
|
56
|
-
execSync("git diff-index --quiet HEAD --");
|
|
57
|
-
return true;
|
|
58
|
-
} catch {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// src/cli/stages/update-eslint-files.ts
|
|
64
|
-
import fs from "node:fs";
|
|
65
|
-
import c from "picocolors";
|
|
66
|
-
import path from "node:path";
|
|
67
|
-
import fsp from "node:fs/promises";
|
|
68
|
-
import process from "node:process";
|
|
69
|
-
import * as p from "@clack/prompts";
|
|
70
|
-
import parse from "parse-gitignore";
|
|
71
|
-
async function updateEslintFiles(result) {
|
|
72
|
-
const cwd = process.cwd();
|
|
73
|
-
const pathESLintIgnore = path.join(cwd, ".eslintignore");
|
|
74
|
-
const pathPackageJSON = path.join(cwd, "package.json");
|
|
75
|
-
const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
|
|
76
|
-
const pkg = JSON.parse(pkgContent);
|
|
77
|
-
const configFileName = pkg.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
78
|
-
const pathFlatConfig = path.join(cwd, configFileName);
|
|
79
|
-
const eslintIgnores = [];
|
|
80
|
-
if (fs.existsSync(pathESLintIgnore)) {
|
|
81
|
-
p.log.step(c.cyan("Migrating existing .eslintignore"));
|
|
82
|
-
const content = await fsp.readFile(pathESLintIgnore, "utf-8");
|
|
83
|
-
const parsed = parse(content);
|
|
84
|
-
const globs = parsed.globs();
|
|
85
|
-
for (const glob of globs) {
|
|
86
|
-
if (glob.type === "ignore")
|
|
87
|
-
eslintIgnores.push(...glob.patterns);
|
|
88
|
-
else if (glob.type === "unignore")
|
|
89
|
-
eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const configLines = [];
|
|
93
|
-
if (eslintIgnores.length)
|
|
94
|
-
configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
|
|
95
|
-
if (result.extra.includes("formatter"))
|
|
96
|
-
configLines.push("formatters: true,");
|
|
97
|
-
if (result.extra.includes("unocss"))
|
|
98
|
-
configLines.push("unocss: true,");
|
|
99
|
-
for (const framework of result.frameworks)
|
|
100
|
-
configLines.push(`${framework}: true,`);
|
|
101
|
-
const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
|
|
102
|
-
const additionalConfig = [];
|
|
103
|
-
const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
|
|
104
|
-
await fsp.writeFile(pathFlatConfig, eslintConfigContent);
|
|
105
|
-
p.log.success(c.green(`Created ${configFileName}`));
|
|
106
|
-
const files = fs.readdirSync(cwd);
|
|
107
|
-
const legacyConfig = [];
|
|
108
|
-
files.forEach((file) => {
|
|
109
|
-
if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file))
|
|
110
|
-
legacyConfig.push(file);
|
|
111
|
-
});
|
|
112
|
-
if (legacyConfig.length)
|
|
113
|
-
p.note(`${c.dim(legacyConfig.join(", "))}`, "You can now remove those files manually");
|
|
114
|
-
return pathFlatConfig;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// src/cli/stages/update-package-json.ts
|
|
118
|
-
import c3 from "picocolors";
|
|
119
|
-
import path2 from "node:path";
|
|
120
|
-
import fsp2 from "node:fs/promises";
|
|
121
|
-
import process2 from "node:process";
|
|
122
|
-
import * as p2 from "@clack/prompts";
|
|
123
|
-
|
|
124
|
-
// src/cli/constants.ts
|
|
125
|
-
import c2 from "picocolors";
|
|
126
|
-
|
|
127
|
-
// package.json
|
|
128
|
-
var package_default = {
|
|
129
|
-
name: "@whoj/eslint-config",
|
|
130
|
-
type: "module",
|
|
131
|
-
version: "2.5.0",
|
|
132
|
-
packageManager: "pnpm@10.3.0",
|
|
133
|
-
description: "ESLint config",
|
|
134
|
-
license: "MIT",
|
|
135
|
-
homepage: "https://github.com/who-jonson/eslint-config",
|
|
136
|
-
keywords: [
|
|
137
|
-
"eslint-config"
|
|
138
|
-
],
|
|
139
|
-
exports: {
|
|
140
|
-
".": "./dist/index.js"
|
|
141
|
-
},
|
|
142
|
-
main: "./dist/index.js",
|
|
143
|
-
types: "./dist/index.d.ts",
|
|
144
|
-
bin: "./bin/index.js",
|
|
145
|
-
files: [
|
|
146
|
-
"bin",
|
|
147
|
-
"dist"
|
|
148
|
-
],
|
|
149
|
-
scripts: {
|
|
150
|
-
build: "nr typegen && tsup --clean --dts",
|
|
151
|
-
stub: "tsup",
|
|
152
|
-
dev: "npx @eslint/config-inspector --config eslint.config.ts",
|
|
153
|
-
"build:inspector": "pnpm build && npx @eslint/config-inspector build",
|
|
154
|
-
watch: "tsup --watch",
|
|
155
|
-
lint: "eslint .",
|
|
156
|
-
"lint:fix": "eslint . --fix",
|
|
157
|
-
typegen: "tsx scripts/typegen.ts",
|
|
158
|
-
prepack: "nr build",
|
|
159
|
-
release: "bumpp && pnpm publish",
|
|
160
|
-
test: "vitest",
|
|
161
|
-
typecheck: "tsc --noEmit",
|
|
162
|
-
prepare: "simple-git-hooks"
|
|
163
|
-
},
|
|
164
|
-
peerDependencies: {
|
|
165
|
-
"@prettier/plugin-xml": "^3.4.1",
|
|
166
|
-
"@unocss/eslint-plugin": ">=0.50.0",
|
|
167
|
-
eslint: "^9.20.0",
|
|
168
|
-
"eslint-plugin-format": ">=0.1.0"
|
|
169
|
-
},
|
|
170
|
-
peerDependenciesMeta: {
|
|
171
|
-
"@prettier/plugin-xml": {
|
|
172
|
-
optional: true
|
|
173
|
-
},
|
|
174
|
-
"@unocss/eslint-plugin": {
|
|
175
|
-
optional: true
|
|
176
|
-
},
|
|
177
|
-
"astro-eslint-parser": {
|
|
178
|
-
optional: true
|
|
179
|
-
},
|
|
180
|
-
"eslint-plugin-format": {
|
|
181
|
-
optional: true
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
dependencies: {
|
|
185
|
-
"@antfu/install-pkg": "^1.0.0",
|
|
186
|
-
"@clack/prompts": "^0.10.0",
|
|
187
|
-
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
|
|
188
|
-
"@eslint/markdown": "^6.2.2",
|
|
189
|
-
"@stylistic/eslint-plugin": "^3.1.0",
|
|
190
|
-
"@typescript-eslint/eslint-plugin": "^8.24.0",
|
|
191
|
-
"@typescript-eslint/parser": "^8.24.0",
|
|
192
|
-
"@vitest/eslint-plugin": "^1.1.31",
|
|
193
|
-
"eslint-config-flat-gitignore": "^2.0.0",
|
|
194
|
-
"eslint-flat-config-utils": "^2.0.1",
|
|
195
|
-
"eslint-merge-processors": "^2.0.0",
|
|
196
|
-
"eslint-plugin-antfu": "^3.0.0",
|
|
197
|
-
"eslint-plugin-command": "^3.0.0",
|
|
198
|
-
"eslint-plugin-import-x": "^4.6.1",
|
|
199
|
-
"eslint-plugin-jsdoc": "^50.6.3",
|
|
200
|
-
"eslint-plugin-jsonc": "^2.19.1",
|
|
201
|
-
"eslint-plugin-n": "^17.15.1",
|
|
202
|
-
"eslint-plugin-no-only-tests": "^3.3.0",
|
|
203
|
-
"eslint-plugin-perfectionist": "^4.9.0",
|
|
204
|
-
"eslint-plugin-regexp": "^2.7.0",
|
|
205
|
-
"eslint-plugin-toml": "^0.12.0",
|
|
206
|
-
"eslint-plugin-unicorn": "^56.0.1",
|
|
207
|
-
"eslint-plugin-unused-imports": "^4.1.4",
|
|
208
|
-
"eslint-plugin-vue": "^9.32.0",
|
|
209
|
-
"eslint-plugin-yml": "^1.16.0",
|
|
210
|
-
"eslint-processor-vue-blocks": "^2.0.0",
|
|
211
|
-
"fast-xml-parser": "^4.5.1",
|
|
212
|
-
globals: "^15.15.0",
|
|
213
|
-
"jsonc-eslint-parser": "^2.4.0",
|
|
214
|
-
"local-pkg": "^1.0.0",
|
|
215
|
-
"parse-gitignore": "^2.0.0",
|
|
216
|
-
picocolors: "^1.1.1",
|
|
217
|
-
"toml-eslint-parser": "^0.10.0",
|
|
218
|
-
"vue-eslint-parser": "^9.4.3",
|
|
219
|
-
"yaml-eslint-parser": "^1.2.3",
|
|
220
|
-
yargs: "^17.7.2"
|
|
221
|
-
},
|
|
222
|
-
devDependencies: {
|
|
223
|
-
"@antfu/ni": "^23.3.1",
|
|
224
|
-
"@eslint-react/eslint-plugin": "^1.26.2",
|
|
225
|
-
"@eslint/config-inspector": "^1.0.0",
|
|
226
|
-
"@prettier/plugin-xml": "^3.4.1",
|
|
227
|
-
"@stylistic/eslint-plugin-migrate": "^3.1.0",
|
|
228
|
-
"@types/fs-extra": "^11.0.4",
|
|
229
|
-
"@types/node": "^22.13.2",
|
|
230
|
-
"@types/prompts": "^2.4.9",
|
|
231
|
-
"@types/yargs": "^17.0.33",
|
|
232
|
-
"@unocss/eslint-plugin": "^65.4.3",
|
|
233
|
-
"@whoj/eslint-config": "workspace:*",
|
|
234
|
-
"astro-eslint-parser": "^1.2.1",
|
|
235
|
-
bumpp: "^10.0.3",
|
|
236
|
-
eslint: "^9.20.1",
|
|
237
|
-
"eslint-plugin-astro": "^1.3.1",
|
|
238
|
-
"eslint-plugin-format": "^1.0.1",
|
|
239
|
-
"eslint-plugin-react-hooks": "^5.1.0",
|
|
240
|
-
"eslint-plugin-react-refresh": "^0.4.19",
|
|
241
|
-
"eslint-plugin-solid": "^0.14.5",
|
|
242
|
-
"eslint-plugin-svelte": "^2.46.1",
|
|
243
|
-
"eslint-typegen": "^1.0.0",
|
|
244
|
-
execa: "^9.5.2",
|
|
245
|
-
"fast-glob": "^3.3.3",
|
|
246
|
-
"fs-extra": "^11.3.0",
|
|
247
|
-
jiti: "^2.4.2",
|
|
248
|
-
"lint-staged": "^15.4.3",
|
|
249
|
-
"prettier-plugin-astro": "^0.14.1",
|
|
250
|
-
"prettier-plugin-slidev": "^1.0.5",
|
|
251
|
-
rimraf: "^6.0.1",
|
|
252
|
-
"simple-git-hooks": "^2.11.1",
|
|
253
|
-
svelte: "^5.20.0",
|
|
254
|
-
"svelte-eslint-parser": "^0.43.0",
|
|
255
|
-
tsup: "^8.3.6",
|
|
256
|
-
tsx: "^4.19.2",
|
|
257
|
-
typescript: "^5.7.3",
|
|
258
|
-
vitest: "^3.0.4",
|
|
259
|
-
vue: "^3.5.13"
|
|
260
|
-
},
|
|
261
|
-
pnpm: {
|
|
262
|
-
onlyBuiltDependencies: [
|
|
263
|
-
"esbuild",
|
|
264
|
-
"simple-git-hooks"
|
|
265
|
-
]
|
|
266
|
-
},
|
|
267
|
-
resolutions: {
|
|
268
|
-
"@eslint-community/eslint-utils": "^4.4.1",
|
|
269
|
-
"@typescript-eslint/utils": "^8.22.0",
|
|
270
|
-
eslint: "^9.19.0",
|
|
271
|
-
tsx: "^4.19.2"
|
|
272
|
-
},
|
|
273
|
-
"simple-git-hooks": {
|
|
274
|
-
"pre-commit": "npx lint-staged"
|
|
275
|
-
},
|
|
276
|
-
"lint-staged": {
|
|
277
|
-
"*": "eslint --fix"
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
// src/cli/constants.ts
|
|
282
|
-
var jetbrainsSettingsObj = {
|
|
283
|
-
"?xml": { version: "1.0", encoding: "UTF-8" },
|
|
284
|
-
"project": { version: "4", component: {
|
|
285
|
-
"name": "EslintConfiguration",
|
|
286
|
-
"extra-options": { value: "--cache" },
|
|
287
|
-
"option": { value: "true", name: "fix-on-save" },
|
|
288
|
-
"custom-configuration-file": { used: "true", path: "$PROJECT_DIR$/eslint.config.js" }
|
|
289
|
-
} }
|
|
290
|
-
};
|
|
291
|
-
var vscodeSettingsString = `
|
|
292
|
-
// Disable the default formatter, use eslint instead
|
|
293
|
-
"prettier.enable": false,
|
|
294
|
-
"editor.formatOnSave": false,
|
|
295
|
-
|
|
296
|
-
// Auto fix
|
|
297
|
-
"editor.codeActionsOnSave": {
|
|
298
|
-
"source.fixAll.eslint": "explicit",
|
|
299
|
-
"source.organizeImports": "never"
|
|
300
|
-
},
|
|
301
|
-
|
|
302
|
-
// Silent the stylistic rules in you IDE, but still auto fix them
|
|
303
|
-
"eslint.rules.customizations": [
|
|
304
|
-
{ "rule": "style/*", "severity": "off", "fixable": true },
|
|
305
|
-
{ "rule": "format/*", "severity": "off", "fixable": true },
|
|
306
|
-
{ "rule": "*-indent", "severity": "off", "fixable": true },
|
|
307
|
-
{ "rule": "*-spacing", "severity": "off", "fixable": true },
|
|
308
|
-
{ "rule": "*-spaces", "severity": "off", "fixable": true },
|
|
309
|
-
{ "rule": "*-order", "severity": "off", "fixable": true },
|
|
310
|
-
{ "rule": "*-dangle", "severity": "off", "fixable": true },
|
|
311
|
-
{ "rule": "*-newline", "severity": "off", "fixable": true },
|
|
312
|
-
{ "rule": "*quotes", "severity": "off", "fixable": true },
|
|
313
|
-
{ "rule": "*semi", "severity": "off", "fixable": true }
|
|
314
|
-
],
|
|
315
|
-
|
|
316
|
-
// Enable eslint for all supported languages
|
|
317
|
-
"eslint.validate": [
|
|
318
|
-
"javascript",
|
|
319
|
-
"javascriptreact",
|
|
320
|
-
"typescript",
|
|
321
|
-
"typescriptreact",
|
|
322
|
-
"vue",
|
|
323
|
-
"html",
|
|
324
|
-
"markdown",
|
|
325
|
-
"json",
|
|
326
|
-
"json5",
|
|
327
|
-
"jsonc",
|
|
328
|
-
"yaml",
|
|
329
|
-
"toml",
|
|
330
|
-
"xml",
|
|
331
|
-
"gql",
|
|
332
|
-
"graphql",
|
|
333
|
-
"astro",
|
|
334
|
-
"svelte",
|
|
335
|
-
"css",
|
|
336
|
-
"less",
|
|
337
|
-
"scss",
|
|
338
|
-
"pcss",
|
|
339
|
-
"postcss"
|
|
340
|
-
]
|
|
341
|
-
`;
|
|
342
|
-
var frameworkOptions = [
|
|
343
|
-
{
|
|
344
|
-
value: "vue",
|
|
345
|
-
label: c2.green("Vue")
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
value: "react",
|
|
349
|
-
label: c2.cyan("React")
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
value: "svelte",
|
|
353
|
-
label: c2.red("Svelte")
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
value: "astro",
|
|
357
|
-
label: c2.magenta("Astro")
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
value: "solid",
|
|
361
|
-
label: c2.cyan("Solid")
|
|
362
|
-
},
|
|
363
|
-
{
|
|
364
|
-
value: "slidev",
|
|
365
|
-
label: c2.blue("Slidev")
|
|
366
|
-
}
|
|
367
|
-
];
|
|
368
|
-
var frameworks = frameworkOptions.map(({ value }) => value);
|
|
369
|
-
var extraOptions = [
|
|
370
|
-
{
|
|
371
|
-
value: "formatter",
|
|
372
|
-
label: c2.red("Formatter"),
|
|
373
|
-
hint: "Use external formatters (Prettier and/or dprint) to format files that ESLint cannot handle yet (.css, .html, etc)"
|
|
374
|
-
},
|
|
375
|
-
{
|
|
376
|
-
value: "unocss",
|
|
377
|
-
label: c2.cyan("UnoCSS")
|
|
378
|
-
}
|
|
379
|
-
];
|
|
380
|
-
var extra = extraOptions.map(({ value }) => value);
|
|
381
|
-
var dependenciesMap = {
|
|
382
|
-
vue: [],
|
|
383
|
-
solid: [
|
|
384
|
-
"eslint-plugin-solid"
|
|
385
|
-
],
|
|
386
|
-
slidev: [
|
|
387
|
-
"prettier-plugin-slidev"
|
|
388
|
-
],
|
|
389
|
-
astro: [
|
|
390
|
-
"eslint-plugin-astro",
|
|
391
|
-
"astro-eslint-parser"
|
|
392
|
-
],
|
|
393
|
-
svelte: [
|
|
394
|
-
"eslint-plugin-svelte",
|
|
395
|
-
"svelte-eslint-parser"
|
|
396
|
-
],
|
|
397
|
-
react: [
|
|
398
|
-
"@eslint-react/eslint-plugin",
|
|
399
|
-
"eslint-plugin-react-hooks",
|
|
400
|
-
"eslint-plugin-react-refresh"
|
|
401
|
-
]
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
// src/cli/stages/update-package-json.ts
|
|
405
|
-
async function updatePackageJson(result) {
|
|
406
|
-
const cwd = process2.cwd();
|
|
407
|
-
const pathPackageJSON = path2.join(cwd, "package.json");
|
|
408
|
-
p2.log.step(c3.cyan(`Bumping @whoj/eslint-config to v${package_default.version}`));
|
|
409
|
-
const pkgContent = await fsp2.readFile(pathPackageJSON, "utf-8");
|
|
410
|
-
const pkg = JSON.parse(pkgContent);
|
|
411
|
-
pkg.devDependencies ??= {};
|
|
412
|
-
pkg.devDependencies["@whoj/eslint-config"] = `^${package_default.version}`;
|
|
413
|
-
pkg.devDependencies.eslint ??= package_default.devDependencies.eslint.replace("npm:eslint-ts-patch@", "").replace(/-\d+$/, "");
|
|
414
|
-
const addedPackages = [];
|
|
415
|
-
if (result.extra.length) {
|
|
416
|
-
result.extra.forEach((item) => {
|
|
417
|
-
switch (item) {
|
|
418
|
-
case "unocss":
|
|
419
|
-
[
|
|
420
|
-
"@unocss/eslint-plugin"
|
|
421
|
-
].forEach((f) => {
|
|
422
|
-
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
423
|
-
addedPackages.push(f);
|
|
424
|
-
});
|
|
425
|
-
break;
|
|
426
|
-
case "formatter":
|
|
427
|
-
[
|
|
428
|
-
"eslint-plugin-format",
|
|
429
|
-
result.frameworks.includes("astro") ? "prettier-plugin-astro" : null
|
|
430
|
-
].forEach((f) => {
|
|
431
|
-
if (!f)
|
|
432
|
-
return;
|
|
433
|
-
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
434
|
-
addedPackages.push(f);
|
|
435
|
-
});
|
|
436
|
-
break;
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
for (const framework of result.frameworks) {
|
|
441
|
-
const deps = dependenciesMap[framework];
|
|
442
|
-
if (deps) {
|
|
443
|
-
deps.forEach((f) => {
|
|
444
|
-
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
445
|
-
addedPackages.push(f);
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
if (addedPackages.length)
|
|
450
|
-
p2.note(`${c3.dim(addedPackages.join(", "))}`, "Added packages");
|
|
451
|
-
await fsp2.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
452
|
-
p2.log.success(c3.green("Changes wrote to package.json"));
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// src/cli/stages/update-jetbrains-idea.ts
|
|
456
|
-
import fs2 from "node:fs";
|
|
457
|
-
import c4 from "picocolors";
|
|
458
|
-
import path3 from "node:path";
|
|
459
|
-
import fsp3 from "node:fs/promises";
|
|
460
|
-
import process3 from "node:process";
|
|
461
|
-
import * as p3 from "@clack/prompts";
|
|
462
|
-
|
|
463
|
-
// node_modules/.pnpm/@antfu+utils@8.1.0/node_modules/@antfu/utils/dist/index.mjs
|
|
464
|
-
var toString = (v) => Object.prototype.toString.call(v);
|
|
465
|
-
var isObject = (val) => toString(val) === "[object Object]";
|
|
466
|
-
function objectKeys(obj) {
|
|
467
|
-
return Object.keys(obj);
|
|
468
|
-
}
|
|
469
|
-
function deepMergeWithArray(target, ...sources) {
|
|
470
|
-
if (!sources.length)
|
|
471
|
-
return target;
|
|
472
|
-
const source = sources.shift();
|
|
473
|
-
if (source === void 0)
|
|
474
|
-
return target;
|
|
475
|
-
if (Array.isArray(target) && Array.isArray(source))
|
|
476
|
-
target.push(...source);
|
|
477
|
-
if (isMergableObject(target) && isMergableObject(source)) {
|
|
478
|
-
objectKeys(source).forEach((key) => {
|
|
479
|
-
if (key === "__proto__" || key === "constructor" || key === "prototype")
|
|
480
|
-
return;
|
|
481
|
-
if (Array.isArray(source[key])) {
|
|
482
|
-
if (!target[key])
|
|
483
|
-
target[key] = [];
|
|
484
|
-
deepMergeWithArray(target[key], source[key]);
|
|
485
|
-
} else if (isMergableObject(source[key])) {
|
|
486
|
-
if (!target[key])
|
|
487
|
-
target[key] = {};
|
|
488
|
-
deepMergeWithArray(target[key], source[key]);
|
|
489
|
-
} else {
|
|
490
|
-
target[key] = source[key];
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
return deepMergeWithArray(target, ...sources);
|
|
495
|
-
}
|
|
496
|
-
function isMergableObject(item) {
|
|
497
|
-
return isObject(item) && !Array.isArray(item);
|
|
498
|
-
}
|
|
499
|
-
var VOID = Symbol("p-void");
|
|
500
|
-
|
|
501
|
-
// src/cli/stages/update-jetbrains-idea.ts
|
|
502
|
-
import { XMLParser, XMLBuilder } from "fast-xml-parser";
|
|
503
|
-
async function updateJetbrainsIdea(result, flatConfigPath) {
|
|
504
|
-
const cwd = process3.cwd();
|
|
505
|
-
if (!result.updateJetbrainsIdea)
|
|
506
|
-
return;
|
|
507
|
-
const dotIdeaPath = path3.join(cwd, ".idea/jsLinters");
|
|
508
|
-
const settingsPath = path3.join(dotIdeaPath, "eslint.xml");
|
|
509
|
-
const ideaFlatConfigPath = path3.join(dotIdeaPath, path3.basename(flatConfigPath));
|
|
510
|
-
const xmlParserOptions = {
|
|
511
|
-
attributeNamePrefix: "",
|
|
512
|
-
ignoreAttributes: false,
|
|
513
|
-
unpairedTags: [
|
|
514
|
-
"option",
|
|
515
|
-
"files-pattern",
|
|
516
|
-
"extra-options",
|
|
517
|
-
"work-dir-patterns",
|
|
518
|
-
"additional-rules-dir",
|
|
519
|
-
"custom-configuration-file"
|
|
520
|
-
]
|
|
521
|
-
};
|
|
522
|
-
const xmlBuilderOptions = {
|
|
523
|
-
format: true,
|
|
524
|
-
...xmlParserOptions,
|
|
525
|
-
suppressUnpairedNode: false,
|
|
526
|
-
suppressBooleanAttributes: false
|
|
527
|
-
};
|
|
528
|
-
const builder = new XMLBuilder(xmlBuilderOptions);
|
|
529
|
-
if (!fs2.existsSync(dotIdeaPath)) {
|
|
530
|
-
await fsp3.mkdir(dotIdeaPath, { recursive: true });
|
|
531
|
-
}
|
|
532
|
-
await fsp3.writeFile(
|
|
533
|
-
ideaFlatConfigPath,
|
|
534
|
-
getJetbrainsEslintConfigContent(
|
|
535
|
-
path3.relative(
|
|
536
|
-
path3.dirname(ideaFlatConfigPath),
|
|
537
|
-
flatConfigPath
|
|
538
|
-
)
|
|
539
|
-
),
|
|
540
|
-
"utf8"
|
|
541
|
-
);
|
|
542
|
-
p3.log.success(c4.green(`Created ${path3.relative(cwd, ideaFlatConfigPath)}`));
|
|
543
|
-
const ideaSettingsObject = deepMergeWithArray(
|
|
544
|
-
jetbrainsSettingsObj,
|
|
545
|
-
{
|
|
546
|
-
project: {
|
|
547
|
-
component: {
|
|
548
|
-
"custom-configuration-file": {
|
|
549
|
-
used: "true",
|
|
550
|
-
path: `$PROJECT_DIR$/.idea/jsLinters/${path3.basename(flatConfigPath)}`
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
);
|
|
556
|
-
if (!fs2.existsSync(settingsPath)) {
|
|
557
|
-
await fsp3.writeFile(settingsPath, builder.build(ideaSettingsObject), "utf8");
|
|
558
|
-
p3.log.success(c4.green("Created .idea/jsLinters/eslint.xml"));
|
|
559
|
-
} else {
|
|
560
|
-
const ideaSettingsContent = await fsp3.readFile(settingsPath, "utf8");
|
|
561
|
-
const parser = new XMLParser(xmlParserOptions);
|
|
562
|
-
const ideaXml = deepMergeWithArray(
|
|
563
|
-
parser.parse(ideaSettingsContent),
|
|
564
|
-
jetbrainsSettingsObj
|
|
565
|
-
);
|
|
566
|
-
await fsp3.writeFile(settingsPath, builder.build(ideaXml), "utf8");
|
|
567
|
-
p3.log.success(c4.green("Updated .idea/jsLinters/eslint.xml"));
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
// src/cli/stages/update-vscode-settings.ts
|
|
572
|
-
import fs3 from "node:fs";
|
|
573
|
-
import c5 from "picocolors";
|
|
574
|
-
import path4 from "node:path";
|
|
575
|
-
import fsp4 from "node:fs/promises";
|
|
576
|
-
import process4 from "node:process";
|
|
577
|
-
import * as p4 from "@clack/prompts";
|
|
578
|
-
async function updateVscodeSettings(result) {
|
|
579
|
-
const cwd = process4.cwd();
|
|
580
|
-
if (!result.updateVscodeSettings)
|
|
581
|
-
return;
|
|
582
|
-
const dotVscodePath = path4.join(cwd, ".vscode");
|
|
583
|
-
const settingsPath = path4.join(dotVscodePath, "settings.json");
|
|
584
|
-
if (!fs3.existsSync(dotVscodePath))
|
|
585
|
-
await fsp4.mkdir(dotVscodePath, { recursive: true });
|
|
586
|
-
if (!fs3.existsSync(settingsPath)) {
|
|
587
|
-
await fsp4.writeFile(settingsPath, `{${vscodeSettingsString}}
|
|
588
|
-
`, "utf-8");
|
|
589
|
-
p4.log.success(c5.green("Created .vscode/settings.json"));
|
|
590
|
-
} else {
|
|
591
|
-
let settingsContent = await fsp4.readFile(settingsPath, "utf8");
|
|
592
|
-
settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
|
|
593
|
-
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
594
|
-
settingsContent += `${vscodeSettingsString}}
|
|
595
|
-
`;
|
|
596
|
-
await fsp4.writeFile(settingsPath, settingsContent, "utf-8");
|
|
597
|
-
p4.log.success(c5.green("Updated .vscode/settings.json"));
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
// src/cli/run.ts
|
|
602
|
-
async function run({ jetbrains, vscode, ...options } = {}) {
|
|
603
|
-
const argSkipPrompt = !!process5.env.SKIP_PROMPT || options.yes;
|
|
604
|
-
const argTemplate = options.frameworks?.map((m) => m.trim());
|
|
605
|
-
const argExtra = options.extra?.map((m) => m.trim());
|
|
606
|
-
if (fs4.existsSync(path5.join(process5.cwd(), "eslint.config.js"))) {
|
|
607
|
-
p5.log.warn(c6.yellow("eslint.config.js already exists, migration wizard exited."));
|
|
608
|
-
return process5.exit(1);
|
|
609
|
-
}
|
|
610
|
-
let result = {
|
|
611
|
-
extra: argExtra ?? [],
|
|
612
|
-
frameworks: argTemplate ?? [],
|
|
613
|
-
uncommittedConfirmed: false,
|
|
614
|
-
updateVscodeSettings: vscode ?? true,
|
|
615
|
-
updateJetbrainsIdea: jetbrains ?? true
|
|
616
|
-
};
|
|
617
|
-
if (!argSkipPrompt) {
|
|
618
|
-
result = await p5.group({
|
|
619
|
-
uncommittedConfirmed: () => {
|
|
620
|
-
if (argSkipPrompt || isGitClean())
|
|
621
|
-
return Promise.resolve(true);
|
|
622
|
-
return p5.confirm({
|
|
623
|
-
initialValue: false,
|
|
624
|
-
message: "There are uncommitted changes in the current repository, are you sure to continue?"
|
|
625
|
-
});
|
|
626
|
-
},
|
|
627
|
-
frameworks: ({ results }) => {
|
|
628
|
-
const isArgTemplateValid = typeof argTemplate === "string" && !!frameworks.includes(argTemplate);
|
|
629
|
-
if (!results.uncommittedConfirmed || isArgTemplateValid)
|
|
630
|
-
return;
|
|
631
|
-
const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
|
|
632
|
-
return p5.multiselect({
|
|
633
|
-
message: c6.reset(message),
|
|
634
|
-
options: frameworkOptions,
|
|
635
|
-
required: false
|
|
636
|
-
});
|
|
637
|
-
},
|
|
638
|
-
extra: ({ results }) => {
|
|
639
|
-
const isArgExtraValid = argExtra?.length && !argExtra.filter((element) => !extra.includes(element)).length;
|
|
640
|
-
if (!results.uncommittedConfirmed || isArgExtraValid)
|
|
641
|
-
return;
|
|
642
|
-
const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
|
|
643
|
-
return p5.multiselect({
|
|
644
|
-
message: c6.reset(message),
|
|
645
|
-
options: extraOptions,
|
|
646
|
-
required: false
|
|
647
|
-
});
|
|
648
|
-
},
|
|
649
|
-
updateJetbrainsIdea: ({ results }) => {
|
|
650
|
-
if (!results.uncommittedConfirmed)
|
|
651
|
-
return;
|
|
652
|
-
return p5.confirm({
|
|
653
|
-
initialValue: true,
|
|
654
|
-
message: "Update JetBrain IDE's eslint configuration for better experience WebStorm / PhpStorm?"
|
|
655
|
-
});
|
|
656
|
-
},
|
|
657
|
-
updateVscodeSettings: ({ results }) => {
|
|
658
|
-
if (!results.uncommittedConfirmed)
|
|
659
|
-
return;
|
|
660
|
-
return p5.confirm({
|
|
661
|
-
initialValue: true,
|
|
662
|
-
message: "Update .vscode/settings.json for better VS Code experience?"
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
}, {
|
|
666
|
-
onCancel: () => {
|
|
667
|
-
p5.cancel("Operation cancelled.");
|
|
668
|
-
process5.exit(0);
|
|
669
|
-
}
|
|
670
|
-
});
|
|
671
|
-
if (!result.uncommittedConfirmed)
|
|
672
|
-
return process5.exit(1);
|
|
673
|
-
}
|
|
674
|
-
await updatePackageJson(result);
|
|
675
|
-
const configFileName = await updateEslintFiles(result);
|
|
676
|
-
await updateJetbrainsIdea(
|
|
677
|
-
result,
|
|
678
|
-
configFileName
|
|
679
|
-
);
|
|
680
|
-
await updateVscodeSettings(result);
|
|
681
|
-
p5.log.success(c6.green("Setup completed"));
|
|
682
|
-
p5.outro(`Now you can update the dependencies by run ${c6.blue("pnpm install")} and run ${c6.blue("eslint . --fix")}
|
|
683
|
-
`);
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
// src/cli/index.ts
|
|
687
|
-
function header() {
|
|
688
|
-
console.log("\n");
|
|
689
|
-
p6.intro(`${c7.green("@whoj/eslint-config ")}${c7.dim(`v${package_default.version}`)}`);
|
|
690
|
-
}
|
|
691
|
-
var instance = yargs(hideBin(process6.argv)).scriptName("@whoj/eslint-config").usage("").command(
|
|
692
|
-
"*",
|
|
693
|
-
"Run the initialization or migration",
|
|
694
|
-
(args) => args.option("yes", {
|
|
695
|
-
alias: "y",
|
|
696
|
-
type: "boolean",
|
|
697
|
-
description: "Skip prompts and use default values"
|
|
698
|
-
}).option("jetbrains", {
|
|
699
|
-
default: true,
|
|
700
|
-
type: "boolean",
|
|
701
|
-
alias: ["idea", "j"],
|
|
702
|
-
description: "Configure eslint settings for better Jetbrains IDE. (WebStorm / PhpStorm) experience."
|
|
703
|
-
}).option("vscode", {
|
|
704
|
-
default: true,
|
|
705
|
-
type: "boolean",
|
|
706
|
-
alias: ["c", "code"],
|
|
707
|
-
description: "Add/Update .vscode/settings.json for better VS Code experience."
|
|
708
|
-
}).option("template", {
|
|
709
|
-
alias: "t",
|
|
710
|
-
type: "string",
|
|
711
|
-
description: "Use the framework template for optimal customization: vue / react / svelte / astro"
|
|
712
|
-
}).option("extra", {
|
|
713
|
-
alias: "e",
|
|
714
|
-
array: true,
|
|
715
|
-
type: "string",
|
|
716
|
-
description: "Use the extra utils: formatter / perfectionist / unocss"
|
|
717
|
-
}).help(),
|
|
718
|
-
async (args) => {
|
|
719
|
-
header();
|
|
720
|
-
try {
|
|
721
|
-
await run(args);
|
|
722
|
-
} catch (error) {
|
|
723
|
-
p6.log.error(c7.inverse(c7.red(" Failed to migrate ")));
|
|
724
|
-
p6.log.error(c7.red(`\u2718 ${String(error)}`));
|
|
725
|
-
process6.exit(1);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
).showHelpOnFail(false).alias("h", "help").version("version", package_default.version).alias("v", "version");
|
|
729
|
-
instance.help().argv;
|