@kirklin/eslint-config 3.0.0 → 5.0.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 +24 -3
- package/README.zh-cn.md +11 -11
- package/dist/cli.js +79 -254
- package/dist/index.d.ts +1852 -724
- package/dist/index.js +200 -63
- package/package.json +60 -64
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
- Optional [formatters](#formatters) support for formatting CSS, HTML, XML, etc.
|
|
34
34
|
- **Style principle**: Minimal for reading, stable for diff, consistent
|
|
35
35
|
- Sorted imports, dangling commas
|
|
36
|
-
-
|
|
36
|
+
- double quotes, no semi
|
|
37
37
|
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
|
|
38
38
|
- Respects `.gitignore` by default
|
|
39
39
|
- Requires ESLint v9.5.0+
|
|
@@ -112,8 +112,8 @@ For example:
|
|
|
112
112
|
```json
|
|
113
113
|
{
|
|
114
114
|
"scripts": {
|
|
115
|
-
"lint": "eslint
|
|
116
|
-
"lint:fix": "eslint
|
|
115
|
+
"lint": "eslint",
|
|
116
|
+
"lint:fix": "eslint --fix"
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
```
|
|
@@ -555,6 +555,27 @@ export default kirklin({
|
|
|
555
555
|
|
|
556
556
|
As it's in maintenance mode, we only accept bug fixes for Vue 2. It might also be removed in the future when `eslint-plugin-vue` drops support for Vue 2. We recommend upgrading to Vue 3 if possible.
|
|
557
557
|
|
|
558
|
+
#### Vue Accessibility
|
|
559
|
+
|
|
560
|
+
To enable Vue accessibility support, you need to explicitly turn it on:
|
|
561
|
+
|
|
562
|
+
```js
|
|
563
|
+
// eslint.config.js
|
|
564
|
+
import kirklin from "@kirklin/eslint-config";
|
|
565
|
+
|
|
566
|
+
export default kirklin({
|
|
567
|
+
vue: {
|
|
568
|
+
a11y: true
|
|
569
|
+
},
|
|
570
|
+
});
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
574
|
+
|
|
575
|
+
```bash
|
|
576
|
+
npm i -D eslint-plugin-vuejs-accessibility
|
|
577
|
+
```
|
|
578
|
+
|
|
558
579
|
### Optional Configs
|
|
559
580
|
|
|
560
581
|
We provide some optional configs for specific use cases, that we don't include their dependencies by default.
|
package/README.zh-cn.md
CHANGED
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
- 可选的[格式化程序](#formatters)支持CSS,HTML,XML等。
|
|
41
41
|
- **样式原则**:最小化阅读,稳定的差异性,保持一致性
|
|
42
42
|
|
|
43
|
-
> [!NOTE]
|
|
44
|
-
> 自 v1.0.0 版本起,该配置已重写为新的 [ESLint Flat 配置](https://eslint.org/docs/latest/use/configure/configuration-files-new),详细信息请查看 [发布说明](https://github.com/kirklin/eslint-config/releases/tag/v1.0.0)。
|
|
45
|
-
>
|
|
46
|
-
> 自 v2.7.0 版本起,现要求使用 ESLint v9.5.0 及以上版本。
|
|
43
|
+
> [!NOTE]
|
|
44
|
+
> 自 v1.0.0 版本起,该配置已重写为新的 [ESLint Flat 配置](https://eslint.org/docs/latest/use/configure/configuration-files-new),详细信息请查看 [发布说明](https://github.com/kirklin/eslint-config/releases/tag/v1.0.0)。
|
|
45
|
+
>
|
|
46
|
+
> 自 v2.7.0 版本起,现要求使用 ESLint v9.5.0 及以上版本。
|
|
47
47
|
|
|
48
48
|
## 使用方法
|
|
49
49
|
|
|
@@ -747,17 +747,17 @@ export default kirklin({
|
|
|
747
747
|
});
|
|
748
748
|
```
|
|
749
749
|
|
|
750
|
-
### 编辑器特定的禁用规则
|
|
750
|
+
### 编辑器特定的禁用规则
|
|
751
751
|
|
|
752
|
-
当 ESLint 在代码编辑器中运行时,以下规则的自动修复功能被禁用:
|
|
752
|
+
当 ESLint 在代码编辑器中运行时,以下规则的自动修复功能被禁用:
|
|
753
753
|
|
|
754
|
-
- [`prefer-const`](https://eslint.org/docs/rules/prefer-const)
|
|
755
|
-
- [`test/no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests)
|
|
756
|
-
- [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports)
|
|
754
|
+
- [`prefer-const`](https://eslint.org/docs/rules/prefer-const)
|
|
755
|
+
- [`test/no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests)
|
|
756
|
+
- [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports)
|
|
757
757
|
|
|
758
|
-
自 v3.0.0 版本起,这些规则不再被完全禁用,而是通过 [此辅助工具](https://github.com/antfu/eslint-flat-config-utils#composerdisablerulesfix) 设为不可自动修复。
|
|
758
|
+
自 v3.0.0 版本起,这些规则不再被完全禁用,而是通过 [此辅助工具](https://github.com/antfu/eslint-flat-config-utils#composerdisablerulesfix) 设为不可自动修复。
|
|
759
759
|
|
|
760
|
-
这样可以防止编辑器在重构代码时自动删除未使用的导入,以提供更好的开发体验。这些规则仍然会在你通过终端运行 ESLint 或使用 [Lint Staged](#lint-staged) 时生效。
|
|
760
|
+
这样可以防止编辑器在重构代码时自动删除未使用的导入,以提供更好的开发体验。这些规则仍然会在你通过终端运行 ESLint 或使用 [Lint Staged](#lint-staged) 时生效。
|
|
761
761
|
|
|
762
762
|
如果你不希望有这种行为,你可以手动禁用它们。
|
|
763
763
|
|
package/dist/cli.js
CHANGED
|
@@ -1,200 +1,21 @@
|
|
|
1
1
|
// src/cli/index.ts
|
|
2
2
|
import process5 from "node:process";
|
|
3
3
|
import * as p5 from "@clack/prompts";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { hideBin } from "yargs/helpers";
|
|
7
|
-
|
|
8
|
-
// src/cli/constants.ts
|
|
9
|
-
import c from "picocolors";
|
|
4
|
+
import c5 from "ansis";
|
|
5
|
+
import { cac } from "cac";
|
|
10
6
|
|
|
11
7
|
// package.json
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
funding: "https://www.buymeacoffee.com/linkirk",
|
|
21
|
-
homepage: "https://github.com/kirklin/eslint-config",
|
|
22
|
-
keywords: [
|
|
23
|
-
"eslint-config"
|
|
24
|
-
],
|
|
25
|
-
exports: {
|
|
26
|
-
".": "./dist/index.js"
|
|
27
|
-
},
|
|
28
|
-
main: "./dist/index.js",
|
|
29
|
-
types: "./dist/index.d.ts",
|
|
30
|
-
bin: "./bin/index.js",
|
|
31
|
-
files: [
|
|
32
|
-
"bin",
|
|
33
|
-
"dist"
|
|
34
|
-
],
|
|
35
|
-
scripts: {
|
|
36
|
-
build: "nr typegen && tsup --clean --dts",
|
|
37
|
-
stub: "tsup",
|
|
38
|
-
dev: "npx @eslint/config-inspector --config eslint.config.ts",
|
|
39
|
-
"build:inspector": "pnpm build && npx @eslint/config-inspector build",
|
|
40
|
-
watch: "tsup --watch",
|
|
41
|
-
lint: "eslint .",
|
|
42
|
-
"lint:fix": "eslint . --fix",
|
|
43
|
-
typegen: "tsx scripts/typegen.ts",
|
|
44
|
-
prepack: "nr build",
|
|
45
|
-
release: "bumpp && pnpm publish",
|
|
46
|
-
test: "vitest",
|
|
47
|
-
typecheck: "tsc --noEmit",
|
|
48
|
-
prepare: "simple-git-hooks"
|
|
49
|
-
},
|
|
50
|
-
peerDependencies: {
|
|
51
|
-
"@eslint-react/eslint-plugin": "^1.19.0",
|
|
52
|
-
"@prettier/plugin-xml": "^3.4.1",
|
|
53
|
-
"@unocss/eslint-plugin": ">=0.50.0",
|
|
54
|
-
"astro-eslint-parser": "^1.0.2",
|
|
55
|
-
eslint: "^9.10.0",
|
|
56
|
-
"eslint-plugin-astro": "^1.2.0",
|
|
57
|
-
"eslint-plugin-format": ">=0.1.0",
|
|
58
|
-
"eslint-plugin-react-hooks": "^5.0.0",
|
|
59
|
-
"eslint-plugin-react-refresh": "^0.4.4",
|
|
60
|
-
"eslint-plugin-solid": "^0.14.3",
|
|
61
|
-
"eslint-plugin-svelte": ">=2.35.1",
|
|
62
|
-
"prettier-plugin-astro": "^0.14.0",
|
|
63
|
-
"prettier-plugin-slidev": "^1.0.5",
|
|
64
|
-
"svelte-eslint-parser": ">=0.37.0"
|
|
65
|
-
},
|
|
66
|
-
peerDependenciesMeta: {
|
|
67
|
-
"@eslint-react/eslint-plugin": {
|
|
68
|
-
optional: true
|
|
69
|
-
},
|
|
70
|
-
"@prettier/plugin-xml": {
|
|
71
|
-
optional: true
|
|
72
|
-
},
|
|
73
|
-
"@unocss/eslint-plugin": {
|
|
74
|
-
optional: true
|
|
75
|
-
},
|
|
76
|
-
"astro-eslint-parser": {
|
|
77
|
-
optional: true
|
|
78
|
-
},
|
|
79
|
-
"eslint-plugin-astro": {
|
|
80
|
-
optional: true
|
|
81
|
-
},
|
|
82
|
-
"eslint-plugin-format": {
|
|
83
|
-
optional: true
|
|
84
|
-
},
|
|
85
|
-
"eslint-plugin-react-hooks": {
|
|
86
|
-
optional: true
|
|
87
|
-
},
|
|
88
|
-
"eslint-plugin-react-refresh": {
|
|
89
|
-
optional: true
|
|
90
|
-
},
|
|
91
|
-
"eslint-plugin-solid": {
|
|
92
|
-
optional: true
|
|
93
|
-
},
|
|
94
|
-
"eslint-plugin-svelte": {
|
|
95
|
-
optional: true
|
|
96
|
-
},
|
|
97
|
-
"prettier-plugin-astro": {
|
|
98
|
-
optional: true
|
|
99
|
-
},
|
|
100
|
-
"prettier-plugin-slidev": {
|
|
101
|
-
optional: true
|
|
102
|
-
},
|
|
103
|
-
"svelte-eslint-parser": {
|
|
104
|
-
optional: true
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
dependencies: {
|
|
108
|
-
"@antfu/install-pkg": "^1.0.0",
|
|
109
|
-
"@clack/prompts": "^0.10.0",
|
|
110
|
-
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
|
|
111
|
-
"@eslint/markdown": "^6.2.2",
|
|
112
|
-
"@stylistic/eslint-plugin": "^3.1.0",
|
|
113
|
-
"@typescript-eslint/eslint-plugin": "^8.23.0",
|
|
114
|
-
"@typescript-eslint/parser": "^8.23.0",
|
|
115
|
-
"@vitest/eslint-plugin": "^1.1.26",
|
|
116
|
-
"eslint-config-flat-gitignore": "^2.0.0",
|
|
117
|
-
"eslint-flat-config-utils": "^2.0.1",
|
|
118
|
-
"eslint-merge-processors": "^2.0.0",
|
|
119
|
-
"eslint-plugin-command": "^3.0.0",
|
|
120
|
-
"eslint-plugin-import-x": "^4.6.1",
|
|
121
|
-
"eslint-plugin-jsdoc": "^50.6.3",
|
|
122
|
-
"eslint-plugin-jsonc": "^2.19.1",
|
|
123
|
-
"eslint-plugin-kirklin": "^2.0.0",
|
|
124
|
-
"eslint-plugin-n": "^17.15.1",
|
|
125
|
-
"eslint-plugin-no-only-tests": "^3.3.0",
|
|
126
|
-
"eslint-plugin-perfectionist": "^4.8.0",
|
|
127
|
-
"eslint-plugin-regexp": "^2.7.0",
|
|
128
|
-
"eslint-plugin-toml": "^0.12.0",
|
|
129
|
-
"eslint-plugin-unicorn": "^56.0.1",
|
|
130
|
-
"eslint-plugin-unused-imports": "^4.1.4",
|
|
131
|
-
"eslint-plugin-vue": "^9.32.0",
|
|
132
|
-
"eslint-plugin-yml": "^1.16.0",
|
|
133
|
-
"eslint-processor-vue-blocks": "^2.0.0",
|
|
134
|
-
globals: "^15.14.0",
|
|
135
|
-
"jsonc-eslint-parser": "^2.4.0",
|
|
136
|
-
"local-pkg": "^1.0.0",
|
|
137
|
-
"parse-gitignore": "^2.0.0",
|
|
138
|
-
picocolors: "^1.1.1",
|
|
139
|
-
"toml-eslint-parser": "^0.10.0",
|
|
140
|
-
"vue-eslint-parser": "^9.4.3",
|
|
141
|
-
"yaml-eslint-parser": "^1.2.3",
|
|
142
|
-
yargs: "^17.7.2"
|
|
143
|
-
},
|
|
144
|
-
devDependencies: {
|
|
145
|
-
"@antfu/ni": "^23.3.1",
|
|
146
|
-
"@eslint-react/eslint-plugin": "^1.26.2",
|
|
147
|
-
"@eslint/config-inspector": "^1.0.0",
|
|
148
|
-
"@kirklin/eslint-config": "workspace:*",
|
|
149
|
-
"@prettier/plugin-xml": "^3.4.1",
|
|
150
|
-
"@stylistic/eslint-plugin-migrate": "^3.1.0",
|
|
151
|
-
"@types/fs-extra": "^11.0.4",
|
|
152
|
-
"@types/node": "^22.13.1",
|
|
153
|
-
"@types/prompts": "^2.4.9",
|
|
154
|
-
"@types/yargs": "^17.0.33",
|
|
155
|
-
"@unocss/eslint-plugin": "^65.4.3",
|
|
156
|
-
"astro-eslint-parser": "^1.2.1",
|
|
157
|
-
bumpp: "^10.0.2",
|
|
158
|
-
eslint: "^9.20.0",
|
|
159
|
-
"eslint-plugin-astro": "^1.3.1",
|
|
160
|
-
"eslint-plugin-format": "^1.0.1",
|
|
161
|
-
"eslint-plugin-react-hooks": "^5.1.0",
|
|
162
|
-
"eslint-plugin-react-refresh": "^0.4.18",
|
|
163
|
-
"eslint-plugin-solid": "^0.14.5",
|
|
164
|
-
"eslint-plugin-svelte": "^2.46.1",
|
|
165
|
-
"eslint-typegen": "^1.0.0",
|
|
166
|
-
execa: "^9.5.2",
|
|
167
|
-
"fast-glob": "^3.3.3",
|
|
168
|
-
"fs-extra": "^11.3.0",
|
|
169
|
-
jiti: "^2.4.2",
|
|
170
|
-
"lint-staged": "^15.4.3",
|
|
171
|
-
"prettier-plugin-astro": "^0.14.1",
|
|
172
|
-
"prettier-plugin-slidev": "^1.0.5",
|
|
173
|
-
rimraf: "^6.0.1",
|
|
174
|
-
"simple-git-hooks": "^2.11.1",
|
|
175
|
-
svelte: "^5.19.9",
|
|
176
|
-
"svelte-eslint-parser": "^0.43.0",
|
|
177
|
-
tsup: "^8.3.6",
|
|
178
|
-
tsx: "^4.19.2",
|
|
179
|
-
typescript: "^5.7.3",
|
|
180
|
-
vitest: "^3.0.5",
|
|
181
|
-
vue: "^3.5.13"
|
|
182
|
-
},
|
|
183
|
-
resolutions: {
|
|
184
|
-
"@eslint-community/eslint-utils": "^4.4.1",
|
|
185
|
-
"@typescript-eslint/utils": "^8.23.0",
|
|
186
|
-
eslint: "^9.20.0",
|
|
187
|
-
tsx: "^4.19.2"
|
|
188
|
-
},
|
|
189
|
-
"simple-git-hooks": {
|
|
190
|
-
"pre-commit": "npx lint-staged"
|
|
191
|
-
},
|
|
192
|
-
"lint-staged": {
|
|
193
|
-
"*": "eslint --fix"
|
|
194
|
-
}
|
|
195
|
-
};
|
|
8
|
+
var version = "5.0.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";
|
|
196
16
|
|
|
197
17
|
// src/cli/constants.ts
|
|
18
|
+
import c from "ansis";
|
|
198
19
|
var vscodeSettingsString = `
|
|
199
20
|
// Disable the default formatter, use eslint instead
|
|
200
21
|
"prettier.enable": false,
|
|
@@ -290,6 +111,12 @@ var dependenciesMap = {
|
|
|
290
111
|
"eslint-plugin-astro",
|
|
291
112
|
"astro-eslint-parser"
|
|
292
113
|
],
|
|
114
|
+
formatter: [
|
|
115
|
+
"eslint-plugin-format"
|
|
116
|
+
],
|
|
117
|
+
formatterAstro: [
|
|
118
|
+
"prettier-plugin-astro"
|
|
119
|
+
],
|
|
293
120
|
react: [
|
|
294
121
|
"@eslint-react/eslint-plugin",
|
|
295
122
|
"eslint-plugin-react-hooks",
|
|
@@ -305,24 +132,20 @@ var dependenciesMap = {
|
|
|
305
132
|
"eslint-plugin-svelte",
|
|
306
133
|
"svelte-eslint-parser"
|
|
307
134
|
],
|
|
135
|
+
unocss: [
|
|
136
|
+
"@unocss/eslint-plugin"
|
|
137
|
+
],
|
|
308
138
|
vue: []
|
|
309
139
|
};
|
|
310
140
|
|
|
311
|
-
// src/cli/run.ts
|
|
312
|
-
import fs3 from "node:fs";
|
|
313
|
-
import path4 from "node:path";
|
|
314
|
-
import process4 from "node:process";
|
|
315
|
-
import * as p4 from "@clack/prompts";
|
|
316
|
-
import c5 from "picocolors";
|
|
317
|
-
|
|
318
141
|
// src/cli/stages/update-eslint-files.ts
|
|
319
142
|
import fs from "node:fs";
|
|
320
143
|
import fsp from "node:fs/promises";
|
|
321
144
|
import path from "node:path";
|
|
322
145
|
import process from "node:process";
|
|
323
146
|
import * as p from "@clack/prompts";
|
|
147
|
+
import c2 from "ansis";
|
|
324
148
|
import parse from "parse-gitignore";
|
|
325
|
-
import c2 from "picocolors";
|
|
326
149
|
|
|
327
150
|
// src/cli/utils.ts
|
|
328
151
|
import { execSync } from "node:child_process";
|
|
@@ -357,7 +180,7 @@ async function updateEslintFiles(result) {
|
|
|
357
180
|
const pathFlatConfig = path.join(cwd, configFileName);
|
|
358
181
|
const eslintIgnores = [];
|
|
359
182
|
if (fs.existsSync(pathESLintIgnore)) {
|
|
360
|
-
p.log.step(c2.cyan
|
|
183
|
+
p.log.step(c2.cyan`Migrating existing .eslintignore`);
|
|
361
184
|
const content = await fsp.readFile(pathESLintIgnore, "utf-8");
|
|
362
185
|
const parsed = parse(content);
|
|
363
186
|
const globs = parsed.globs();
|
|
@@ -386,7 +209,7 @@ async function updateEslintFiles(result) {
|
|
|
386
209
|
const additionalConfig = [];
|
|
387
210
|
const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
|
|
388
211
|
await fsp.writeFile(pathFlatConfig, eslintConfigContent);
|
|
389
|
-
p.log.success(c2.green
|
|
212
|
+
p.log.success(c2.green`Created ${configFileName}`);
|
|
390
213
|
const files = fs.readdirSync(cwd);
|
|
391
214
|
const legacyConfig = [];
|
|
392
215
|
files.forEach((file) => {
|
|
@@ -395,7 +218,7 @@ async function updateEslintFiles(result) {
|
|
|
395
218
|
}
|
|
396
219
|
});
|
|
397
220
|
if (legacyConfig.length) {
|
|
398
|
-
p.note(
|
|
221
|
+
p.note(c2.dim(legacyConfig.join(", ")), "You can now remove those files manually");
|
|
399
222
|
}
|
|
400
223
|
}
|
|
401
224
|
|
|
@@ -404,37 +227,54 @@ import fsp2 from "node:fs/promises";
|
|
|
404
227
|
import path2 from "node:path";
|
|
405
228
|
import process2 from "node:process";
|
|
406
229
|
import * as p2 from "@clack/prompts";
|
|
407
|
-
import c3 from "
|
|
230
|
+
import c3 from "ansis";
|
|
231
|
+
|
|
232
|
+
// src/cli/constants-generated.ts
|
|
233
|
+
var versionsMap = {
|
|
234
|
+
"@eslint-react/eslint-plugin": "^1.43.0",
|
|
235
|
+
"@unocss/eslint-plugin": "^66.0.0",
|
|
236
|
+
"astro-eslint-parser": "^1.2.2",
|
|
237
|
+
"eslint": "^9.24.0",
|
|
238
|
+
"eslint-plugin-astro": "^1.3.1",
|
|
239
|
+
"eslint-plugin-format": "^1.0.1",
|
|
240
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
241
|
+
"eslint-plugin-react-refresh": "^0.4.19",
|
|
242
|
+
"eslint-plugin-solid": "^0.14.5",
|
|
243
|
+
"eslint-plugin-svelte": "^3.5.1",
|
|
244
|
+
"prettier-plugin-astro": "^0.14.1",
|
|
245
|
+
"prettier-plugin-slidev": "^1.0.5",
|
|
246
|
+
"svelte-eslint-parser": "^1.1.2"
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// src/cli/stages/update-package-json.ts
|
|
408
250
|
async function updatePackageJson(result) {
|
|
409
251
|
const cwd = process2.cwd();
|
|
410
252
|
const pathPackageJSON = path2.join(cwd, "package.json");
|
|
411
|
-
p2.log.step(c3.cyan
|
|
253
|
+
p2.log.step(c3.cyan`Bumping @kirklin/eslint-config to v${version}`);
|
|
412
254
|
const pkgContent = await fsp2.readFile(pathPackageJSON, "utf-8");
|
|
413
255
|
const pkg = JSON.parse(pkgContent);
|
|
414
256
|
pkg.devDependencies ??= {};
|
|
415
|
-
pkg.devDependencies["@kirklin/eslint-config"] = `^${
|
|
416
|
-
pkg.devDependencies.eslint ??=
|
|
257
|
+
pkg.devDependencies["@kirklin/eslint-config"] = `^${version}`;
|
|
258
|
+
pkg.devDependencies.eslint ??= versionsMap.eslint;
|
|
417
259
|
const addedPackages = [];
|
|
418
260
|
if (result.extra.length) {
|
|
419
261
|
result.extra.forEach((item) => {
|
|
420
262
|
switch (item) {
|
|
421
263
|
case "formatter":
|
|
422
264
|
[
|
|
423
|
-
|
|
424
|
-
result.frameworks.includes("astro") ?
|
|
265
|
+
...dependenciesMap.formatter,
|
|
266
|
+
...result.frameworks.includes("astro") ? dependenciesMap.formatterAstro : []
|
|
425
267
|
].forEach((f) => {
|
|
426
268
|
if (!f) {
|
|
427
269
|
return;
|
|
428
270
|
}
|
|
429
|
-
pkg.devDependencies[f] =
|
|
271
|
+
pkg.devDependencies[f] = versionsMap[f];
|
|
430
272
|
addedPackages.push(f);
|
|
431
273
|
});
|
|
432
274
|
break;
|
|
433
275
|
case "unocss":
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
].forEach((f) => {
|
|
437
|
-
pkg.devDependencies[f] = package_default.devDependencies[f];
|
|
276
|
+
dependenciesMap.unocss.forEach((f) => {
|
|
277
|
+
pkg.devDependencies[f] = versionsMap[f];
|
|
438
278
|
addedPackages.push(f);
|
|
439
279
|
});
|
|
440
280
|
break;
|
|
@@ -445,16 +285,16 @@ async function updatePackageJson(result) {
|
|
|
445
285
|
const deps = dependenciesMap[framework];
|
|
446
286
|
if (deps) {
|
|
447
287
|
deps.forEach((f) => {
|
|
448
|
-
pkg.devDependencies[f] =
|
|
288
|
+
pkg.devDependencies[f] = versionsMap[f];
|
|
449
289
|
addedPackages.push(f);
|
|
450
290
|
});
|
|
451
291
|
}
|
|
452
292
|
}
|
|
453
293
|
if (addedPackages.length) {
|
|
454
|
-
p2.note(
|
|
294
|
+
p2.note(c3.dim(addedPackages.join(", ")), "Added packages");
|
|
455
295
|
}
|
|
456
296
|
await fsp2.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
457
|
-
p2.log.success(c3.green
|
|
297
|
+
p2.log.success(c3.green`Changes wrote to package.json`);
|
|
458
298
|
}
|
|
459
299
|
|
|
460
300
|
// src/cli/stages/update-vscode-settings.ts
|
|
@@ -463,7 +303,7 @@ import fsp3 from "node:fs/promises";
|
|
|
463
303
|
import path3 from "node:path";
|
|
464
304
|
import process3 from "node:process";
|
|
465
305
|
import * as p3 from "@clack/prompts";
|
|
466
|
-
import
|
|
306
|
+
import { green } from "ansis";
|
|
467
307
|
async function updateVscodeSettings(result) {
|
|
468
308
|
const cwd = process3.cwd();
|
|
469
309
|
if (!result.updateVscodeSettings) {
|
|
@@ -477,7 +317,7 @@ async function updateVscodeSettings(result) {
|
|
|
477
317
|
if (!fs2.existsSync(settingsPath)) {
|
|
478
318
|
await fsp3.writeFile(settingsPath, `{${vscodeSettingsString}}
|
|
479
319
|
`, "utf-8");
|
|
480
|
-
p3.log.success(
|
|
320
|
+
p3.log.success(green`Created .vscode/settings.json`);
|
|
481
321
|
} else {
|
|
482
322
|
let settingsContent = await fsp3.readFile(settingsPath, "utf8");
|
|
483
323
|
settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
|
|
@@ -485,17 +325,17 @@ async function updateVscodeSettings(result) {
|
|
|
485
325
|
settingsContent += `${vscodeSettingsString}}
|
|
486
326
|
`;
|
|
487
327
|
await fsp3.writeFile(settingsPath, settingsContent, "utf-8");
|
|
488
|
-
p3.log.success(
|
|
328
|
+
p3.log.success(green`Updated .vscode/settings.json`);
|
|
489
329
|
}
|
|
490
330
|
}
|
|
491
331
|
|
|
492
332
|
// src/cli/run.ts
|
|
493
333
|
async function run(options = {}) {
|
|
494
334
|
const argSkipPrompt = !!process4.env.SKIP_PROMPT || options.yes;
|
|
495
|
-
const argTemplate = options.frameworks?.map((m) => m
|
|
496
|
-
const argExtra = options.extra?.map((m) => m
|
|
335
|
+
const argTemplate = options.frameworks?.map((m) => m?.trim()).filter(Boolean);
|
|
336
|
+
const argExtra = options.extra?.map((m) => m?.trim()).filter(Boolean);
|
|
497
337
|
if (fs3.existsSync(path4.join(process4.cwd(), "eslint.config.js"))) {
|
|
498
|
-
p4.log.warn(
|
|
338
|
+
p4.log.warn(c4.yellow`eslint.config.js already exists, migration wizard exited.`);
|
|
499
339
|
return process4.exit(1);
|
|
500
340
|
}
|
|
501
341
|
let result = {
|
|
@@ -522,7 +362,7 @@ async function run(options = {}) {
|
|
|
522
362
|
}
|
|
523
363
|
const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
|
|
524
364
|
return p4.multiselect({
|
|
525
|
-
message:
|
|
365
|
+
message: c4.reset(message),
|
|
526
366
|
options: frameworkOptions,
|
|
527
367
|
required: false
|
|
528
368
|
});
|
|
@@ -534,7 +374,7 @@ async function run(options = {}) {
|
|
|
534
374
|
}
|
|
535
375
|
const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
|
|
536
376
|
return p4.multiselect({
|
|
537
|
-
message:
|
|
377
|
+
message: c4.reset(message),
|
|
538
378
|
options: extraOptions,
|
|
539
379
|
required: false
|
|
540
380
|
});
|
|
@@ -561,42 +401,27 @@ async function run(options = {}) {
|
|
|
561
401
|
await updatePackageJson(result);
|
|
562
402
|
await updateEslintFiles(result);
|
|
563
403
|
await updateVscodeSettings(result);
|
|
564
|
-
p4.log.success(
|
|
565
|
-
p4.outro(`Now you can update the dependencies by run ${
|
|
404
|
+
p4.log.success(c4.green`Setup completed`);
|
|
405
|
+
p4.outro(`Now you can update the dependencies by run ${c4.blue("pnpm install")} and run ${c4.blue("eslint --fix")}
|
|
566
406
|
`);
|
|
567
407
|
}
|
|
568
408
|
|
|
569
409
|
// src/cli/index.ts
|
|
570
410
|
function header() {
|
|
571
411
|
console.log("\n");
|
|
572
|
-
p5.intro(`${
|
|
412
|
+
p5.intro(`${c5.green`@kirklin/eslint-config `}${c5.dim`v${version}`}`);
|
|
573
413
|
}
|
|
574
|
-
var
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
description: "Use the framework template for optimal customization: vue / react / svelte / astro",
|
|
584
|
-
type: "string"
|
|
585
|
-
}).option("extra", {
|
|
586
|
-
alias: "e",
|
|
587
|
-
array: true,
|
|
588
|
-
description: "Use the extra utils: formatter / perfectionist / unocss",
|
|
589
|
-
type: "string"
|
|
590
|
-
}).help(),
|
|
591
|
-
async (args) => {
|
|
592
|
-
header();
|
|
593
|
-
try {
|
|
594
|
-
await run(args);
|
|
595
|
-
} catch (error) {
|
|
596
|
-
p5.log.error(c6.inverse(c6.red(" Failed to migrate ")));
|
|
597
|
-
p5.log.error(c6.red(`\u2718 ${String(error)}`));
|
|
598
|
-
process5.exit(1);
|
|
599
|
-
}
|
|
414
|
+
var cli = cac("@kirklin/eslint-config");
|
|
415
|
+
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) => {
|
|
416
|
+
header();
|
|
417
|
+
try {
|
|
418
|
+
await run(args);
|
|
419
|
+
} catch (error) {
|
|
420
|
+
p5.log.error(c5.inverse.red(" Failed to migrate "));
|
|
421
|
+
p5.log.error(c5.red`✘ ${String(error)}`);
|
|
422
|
+
process5.exit(1);
|
|
600
423
|
}
|
|
601
|
-
)
|
|
602
|
-
|
|
424
|
+
});
|
|
425
|
+
cli.help();
|
|
426
|
+
cli.version(version);
|
|
427
|
+
cli.parse();
|