@dhzh/eslint-config 0.27.0 → 1.0.1
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/LICENSE +1 -1
- package/README.md +24 -54
- package/bin/index.js +1 -1
- package/dist/cli/index.cjs +371 -0
- package/dist/cli/index.js +347 -0
- package/dist/index.cjs +1240 -2371
- package/dist/index.d.cts +74 -17524
- package/dist/index.d.ts +74 -17524
- package/dist/index.js +1239 -2293
- package/package.json +45 -93
- package/dist/cli.cjs +0 -673
- package/dist/cli.js +0 -644
- /package/dist/{cli.d.cts → cli/index.d.cts} +0 -0
- /package/dist/{cli.d.ts → cli/index.d.ts} +0 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -2,58 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://npmjs.com/package/@antfu/eslint-config)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- `
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
[
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
'parent',
|
|
28
|
-
'sibling',
|
|
29
|
-
'index',
|
|
30
|
-
'style',
|
|
31
|
-
'side-effect',
|
|
32
|
-
'side-effect-style',
|
|
33
|
-
'object',
|
|
34
|
-
'builtin-type',
|
|
35
|
-
'external-type',
|
|
36
|
-
'internal-type',
|
|
37
|
-
'parent-type',
|
|
38
|
-
'sibling-type',
|
|
39
|
-
'index-type',
|
|
40
|
-
'unknown',
|
|
41
|
-
];
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
> Note: Temporarily close the rules of the [`Perfectionist`](https://perfectionist.dev/) plugin from version `v0.15.0`, because I haven't found a way to achieve the best balance between actual development needs and personal habits.
|
|
45
|
-
|
|
46
|
-
9. React related:
|
|
47
|
-
|
|
48
|
-
- `'react/no-useless-fragment': 'warn'`
|
|
49
|
-
|
|
50
|
-
10. Remove spacing when useing jsx curly braces:
|
|
51
|
-
|
|
52
|
-
- `'style/jsx-curly-spacing': ['error', { children: true, when: 'never' }]`
|
|
53
|
-
|
|
54
|
-
11. Keep auto fix with code editors for rules: [`prefer-const`](https://eslint.org/docs/rules/prefer-const), [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports).
|
|
55
|
-
|
|
56
|
-
12. Disable [`perfectionist/sort-objects`](https://perfectionist.dev/rules/sort-objects) rule.
|
|
5
|
+
I use ESLint to format and lint my code:
|
|
6
|
+
|
|
7
|
+
| | | |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| [react](./src/configs/react.ts) | [`ESLint React`](https://eslint-react.xyz/) [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks) [`eslint-plugin-react-refresh`](https://github.com/ArnaudBarre/eslint-plugin-react-refresh) [`eslint-plugin-react-compiler`](https://www.npmjs.com/package/eslint-plugin-react-compiler) [`eslint-plugin-react-google-translate`](https://www.npmjs.com/package/eslint-plugin-react-google-translate) |
|
|
10
|
+
| [stylistic](./src/configs/stylistic.ts) | [`ESLint Stylistic`](https://eslint.style/) [`eslint-plugin-antfu`](https://github.com/antfu/eslint-plugin-antfu) [`eslint-plugin-hyoban`](https://github.com/hyoban/eslint-plugin-hyoban) |
|
|
11
|
+
| [typescript](./src/configs/typescript.ts) | [`typescript-eslint`](https://typescript-eslint.io/) |
|
|
12
|
+
| [javascript](./src/configs/javascript.ts) | [`@eslint/js`](https://eslint.org/docs/latest/rules) |
|
|
13
|
+
| [node](./src/configs/node.ts) | [`eslint-plugin-n`](https://github.com/eslint-community/eslint-plugin-n) |
|
|
14
|
+
| [json](./src/configs/json.ts) | [`eslint-plugin-jsonc`](https://ota-meshi.github.io/eslint-plugin-jsonc/) [`eslint-plugin-package-json`](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json) [`jsonc-eslint-parser`](https://github.com/ota-meshi/jsonc-eslint-parser) |
|
|
15
|
+
| [unicorn](./src/configs/unicorn.ts) | [`eslint-plugin-unicorn`](https://www.npmjs.com/package/eslint-plugin-unicorn) |
|
|
16
|
+
| [imports](./src/configs/imports.ts) | [`eslint-plugin-import-x`](https://www.npmjs.com/package/eslint-plugin-import-x) [`eslint-plugin-unused-imports`](https://github.com/sweepline/eslint-plugin-unused-imports) [`eslint-plugin-simple-import-sort`](https://github.com/lydell/eslint-plugin-simple-import-sort) |
|
|
17
|
+
| [formatters](./src/configs/formatters.ts) | [`eslint-plugin-format`](https://github.com/antfu/eslint-plugin-format) [`@prettier/plugin-xml`](https://github.com/prettier/plugin-xml) | html/css/graphql/xml/svg |
|
|
18
|
+
| [tailwindcss](./src/configs/tailwindcss.ts) | [`eslint-plugin-tailwindcss`](https://github.com/francoismassart/eslint-plugin-tailwindcss) |
|
|
19
|
+
| [unocss](./src/configs/unocss.ts) | [`@unocss/eslint-config`](https://unocss.dev/integrations/eslint) |
|
|
20
|
+
| [yml](./src/configs/yml.ts) | [`eslint-plugin-yml`](https://ota-meshi.github.io/eslint-plugin-yml/) [`yaml-eslint-parser`](https://ota-meshi.github.io/yaml-eslint-parser/) |
|
|
21
|
+
| [toml](./src/configs/toml.ts) | [`eslint-plugin-toml`](https://ota-meshi.github.io/eslint-plugin-toml/) [`toml-eslint-parser`](https://ota-meshi.github.io/toml-eslint-parser/) |
|
|
22
|
+
| testing | [`eslint-plugin-vitest`](https://github.com/vitest-dev/eslint-plugin-vitest) [`eslint-plugin-jest`](https://github.com/jest-community/eslint-plugin-jest) [`eslint-plugin-no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests) |
|
|
23
|
+
| [regexp](./src/configs/regexp.ts) | [`eslint-plugin-regexp`](https://ota-meshi.github.io/eslint-plugin-regexp/) |
|
|
24
|
+
| [eslint-comments](./src/configs/eslint-comments.ts) | [`eslint-plugin-eslint-comments`](https://eslint-community.github.io/eslint-plugin-eslint-comments/) |
|
|
25
|
+
| markdown | [`@eslint/markdown`](https://github.com/eslint/markdown) |
|
|
26
|
+
| jsdoc | [`eslint-plugin-jsdoc`](https://github.com/gajus/eslint-plugin-jsdoc) |
|
|
57
27
|
|
|
58
28
|
## Usage
|
|
59
29
|
|
|
@@ -79,9 +49,9 @@ And create `eslint.config.mjs` in your project root:
|
|
|
79
49
|
|
|
80
50
|
```js
|
|
81
51
|
// eslint.config.mjs
|
|
82
|
-
import
|
|
52
|
+
import { defineConfig } from '@dhzh/eslint-config';
|
|
83
53
|
|
|
84
|
-
export default
|
|
54
|
+
export default defineConfig();
|
|
85
55
|
```
|
|
86
56
|
|
|
87
57
|
## License
|
package/bin/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import '../dist/cli.js';
|
|
2
|
+
import '../dist/cli/index.js';
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/cli/index.ts
|
|
26
|
+
var p5 = __toESM(require("@clack/prompts"), 1);
|
|
27
|
+
var import_ansis5 = __toESM(require("ansis"), 1);
|
|
28
|
+
var import_cac = require("cac");
|
|
29
|
+
|
|
30
|
+
// package.json
|
|
31
|
+
var version = "1.0.1";
|
|
32
|
+
var package_default = {
|
|
33
|
+
name: "@dhzh/eslint-config",
|
|
34
|
+
type: "module",
|
|
35
|
+
version,
|
|
36
|
+
packageManager: "pnpm@10.7.0",
|
|
37
|
+
description: "Lyle's ESLint config",
|
|
38
|
+
author: {
|
|
39
|
+
name: "Lyle Zheng",
|
|
40
|
+
email: "dhzhme@gmail.com"
|
|
41
|
+
},
|
|
42
|
+
license: "MIT",
|
|
43
|
+
homepage: "https://github.com/tinywaves/eslint-config",
|
|
44
|
+
repository: {
|
|
45
|
+
type: "git",
|
|
46
|
+
url: "git+https://github.com/tinywaves/eslint-config"
|
|
47
|
+
},
|
|
48
|
+
bugs: {
|
|
49
|
+
url: "https://github.com/tinywaves/eslint-config/issues"
|
|
50
|
+
},
|
|
51
|
+
keywords: [
|
|
52
|
+
"eslint",
|
|
53
|
+
"eslint-config"
|
|
54
|
+
],
|
|
55
|
+
sideEffects: false,
|
|
56
|
+
exports: {
|
|
57
|
+
".": {
|
|
58
|
+
import: "./dist/index.js",
|
|
59
|
+
require: "./dist/index.cjs"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
main: "./dist/index.js",
|
|
63
|
+
types: "./dist/index.d.ts",
|
|
64
|
+
bin: "./bin/index.js",
|
|
65
|
+
files: [
|
|
66
|
+
"bin",
|
|
67
|
+
"dist"
|
|
68
|
+
],
|
|
69
|
+
engines: {
|
|
70
|
+
node: "^18.18.0 || ^20.9.0 || >=21.1.0"
|
|
71
|
+
},
|
|
72
|
+
scripts: {
|
|
73
|
+
build: "tsup --clean --dts",
|
|
74
|
+
"build:inspector": "pnpm run build && npx @eslint/config-inspector build",
|
|
75
|
+
dev: "pnpm run typegen && npx @eslint/config-inspector --config eslint.config.ts",
|
|
76
|
+
lint: "eslint",
|
|
77
|
+
"lint-fix": "eslint --fix .",
|
|
78
|
+
prepack: "pnpm run build",
|
|
79
|
+
prepare: "simple-git-hooks",
|
|
80
|
+
release: "bumpp && pnpm publish --access=public",
|
|
81
|
+
typecheck: "tsc --noEmit",
|
|
82
|
+
typegen: "tsx scripts/eslint-typegen.ts"
|
|
83
|
+
},
|
|
84
|
+
peerDependencies: {
|
|
85
|
+
"@prettier/plugin-xml": "^3.4.1",
|
|
86
|
+
eslint: "^9.10.0"
|
|
87
|
+
},
|
|
88
|
+
peerDependenciesMeta: {
|
|
89
|
+
"@prettier/plugin-xml": {
|
|
90
|
+
optional: true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
dependencies: {
|
|
94
|
+
"@clack/prompts": "^0.10.0",
|
|
95
|
+
"@eslint-community/eslint-plugin-eslint-comments": "^4.5.0",
|
|
96
|
+
"@eslint-react/eslint-plugin": "^1.48.4",
|
|
97
|
+
"@eslint/js": "^9.25.1",
|
|
98
|
+
"@stylistic/eslint-plugin": "^4.2.0",
|
|
99
|
+
"@unocss/eslint-config": "66.1.0-beta.12",
|
|
100
|
+
ansis: "^3.17.0",
|
|
101
|
+
cac: "^6.7.14",
|
|
102
|
+
"eslint-plugin-antfu": "^3.1.1",
|
|
103
|
+
"eslint-plugin-format": "^1.0.1",
|
|
104
|
+
"eslint-plugin-hyoban": "^0.6.1",
|
|
105
|
+
"eslint-plugin-import-x": "^4.10.6",
|
|
106
|
+
"eslint-plugin-jsonc": "^2.20.0",
|
|
107
|
+
"eslint-plugin-n": "^17.16.2",
|
|
108
|
+
"eslint-plugin-package-json": "^0.30.0",
|
|
109
|
+
"eslint-plugin-react-compiler": "19.1.0-rc.1",
|
|
110
|
+
"eslint-plugin-react-google-translate": "^0.1.1",
|
|
111
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
112
|
+
"eslint-plugin-react-refresh": "^0.4.20",
|
|
113
|
+
"eslint-plugin-regexp": "^2.7.0",
|
|
114
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
115
|
+
"eslint-plugin-tailwindcss": "^3.18.0",
|
|
116
|
+
"eslint-plugin-toml": "^0.12.0",
|
|
117
|
+
"eslint-plugin-unicorn": "^57.0.0",
|
|
118
|
+
"eslint-plugin-unused-imports": "^4.1.4",
|
|
119
|
+
"eslint-plugin-yml": "^1.17.0",
|
|
120
|
+
globals: "^16.0.0",
|
|
121
|
+
"jsonc-eslint-parser": "^2.4.0",
|
|
122
|
+
"local-pkg": "^1.1.1",
|
|
123
|
+
"toml-eslint-parser": "^0.10.0",
|
|
124
|
+
"typescript-eslint": "^8.30.1",
|
|
125
|
+
"yaml-eslint-parser": "^1.3.0"
|
|
126
|
+
},
|
|
127
|
+
devDependencies: {
|
|
128
|
+
"@eslint/config-inspector": "^1.0.2",
|
|
129
|
+
"@prettier/plugin-xml": "^3.4.1",
|
|
130
|
+
"@types/eslint-plugin-tailwindcss": "^3.17.0",
|
|
131
|
+
"@types/node": "^22.13.11",
|
|
132
|
+
bumpp: "^10.0.3",
|
|
133
|
+
"bundle-require": "^5.1.0",
|
|
134
|
+
eslint: "^9.25.0",
|
|
135
|
+
"eslint-typegen": "^2.1.0",
|
|
136
|
+
"lint-staged": "^15.5.0",
|
|
137
|
+
"simple-git-hooks": "^2.12.1",
|
|
138
|
+
tsup: "^8.4.0",
|
|
139
|
+
tsx: "^4.19.3",
|
|
140
|
+
typescript: "^5.8.3"
|
|
141
|
+
},
|
|
142
|
+
"simple-git-hooks": {
|
|
143
|
+
"pre-commit": "npx lint-staged"
|
|
144
|
+
},
|
|
145
|
+
"lint-staged": {
|
|
146
|
+
"*": "eslint --fix"
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// src/cli/run.ts
|
|
151
|
+
var p4 = __toESM(require("@clack/prompts"), 1);
|
|
152
|
+
var import_ansis4 = __toESM(require("ansis"), 1);
|
|
153
|
+
|
|
154
|
+
// src/cli/stages/update-eslint-config.ts
|
|
155
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
156
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
157
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
158
|
+
var import_ansis = __toESM(require("ansis"), 1);
|
|
159
|
+
var p = __toESM(require("@clack/prompts"), 1);
|
|
160
|
+
|
|
161
|
+
// src/cli/constants.ts
|
|
162
|
+
var vscodeSettingsString = `
|
|
163
|
+
// Entry
|
|
164
|
+
"eslint.format.enable": true,
|
|
165
|
+
"eslint.ignoreUntitled": true,
|
|
166
|
+
"eslint.enable": true,
|
|
167
|
+
|
|
168
|
+
// Disable the default formatter, use eslint instead
|
|
169
|
+
"prettier.enable": false,
|
|
170
|
+
"editor.formatOnSave": false,
|
|
171
|
+
|
|
172
|
+
// Auto fix
|
|
173
|
+
"editor.codeActionsOnSave": {
|
|
174
|
+
"source.fixAll.eslint": "explicit",
|
|
175
|
+
"source.organizeImports": "never"
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
// Silent the stylistic rules in you IDE, but still auto fix them
|
|
179
|
+
// "eslint.rules.customizations": [
|
|
180
|
+
// { "rule": "style/*", "severity": "off", "fixable": true },
|
|
181
|
+
// { "rule": "format/*", "severity": "off", "fixable": true },
|
|
182
|
+
// { "rule": "*-indent", "severity": "off", "fixable": true },
|
|
183
|
+
// { "rule": "*-spacing", "severity": "off", "fixable": true },
|
|
184
|
+
// { "rule": "*-spaces", "severity": "off", "fixable": true },
|
|
185
|
+
// { "rule": "*-order", "severity": "off", "fixable": true },
|
|
186
|
+
// { "rule": "*-dangle", "severity": "off", "fixable": true },
|
|
187
|
+
// { "rule": "*-newline", "severity": "off", "fixable": true },
|
|
188
|
+
// { "rule": "*quotes", "severity": "off", "fixable": true },
|
|
189
|
+
// { "rule": "*semi", "severity": "off", "fixable": true }
|
|
190
|
+
// ],
|
|
191
|
+
|
|
192
|
+
// Enable eslint for all supported languages
|
|
193
|
+
"eslint.validate": [
|
|
194
|
+
"javascript",
|
|
195
|
+
"javascriptreact",
|
|
196
|
+
"typescript",
|
|
197
|
+
"typescriptreact",
|
|
198
|
+
"vue",
|
|
199
|
+
"html",
|
|
200
|
+
"markdown",
|
|
201
|
+
"json",
|
|
202
|
+
"json5",
|
|
203
|
+
"jsonc",
|
|
204
|
+
"yaml",
|
|
205
|
+
"toml",
|
|
206
|
+
"xml",
|
|
207
|
+
"css",
|
|
208
|
+
"less",
|
|
209
|
+
"scss",
|
|
210
|
+
"pcss",
|
|
211
|
+
"postcss",
|
|
212
|
+
"gql",
|
|
213
|
+
"graphql",
|
|
214
|
+
"astro",
|
|
215
|
+
"svelte"
|
|
216
|
+
],
|
|
217
|
+
|
|
218
|
+
// Enable eslint as the default formatter
|
|
219
|
+
"[javascript]": {
|
|
220
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
221
|
+
},
|
|
222
|
+
"[javascriptreact]": {
|
|
223
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
224
|
+
},
|
|
225
|
+
"[typescript]": {
|
|
226
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
227
|
+
},
|
|
228
|
+
"[typescriptreact]": {
|
|
229
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
230
|
+
},
|
|
231
|
+
"[vue]": {
|
|
232
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
233
|
+
},
|
|
234
|
+
"[html]": {
|
|
235
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
236
|
+
},
|
|
237
|
+
"[markdown]": {
|
|
238
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
239
|
+
},
|
|
240
|
+
"[json]": {
|
|
241
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
242
|
+
},
|
|
243
|
+
"[jsonc]": {
|
|
244
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
245
|
+
},
|
|
246
|
+
"[yaml]": {
|
|
247
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
248
|
+
},
|
|
249
|
+
"[toml]": {
|
|
250
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
251
|
+
},
|
|
252
|
+
"[xml]": {
|
|
253
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
254
|
+
},
|
|
255
|
+
"[css]": {
|
|
256
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
257
|
+
},
|
|
258
|
+
"[less]": {
|
|
259
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
260
|
+
},
|
|
261
|
+
"[scss]": {
|
|
262
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
263
|
+
},
|
|
264
|
+
"[pcss]": {
|
|
265
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
266
|
+
},
|
|
267
|
+
"[postcss]": {
|
|
268
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
269
|
+
},
|
|
270
|
+
"[gql]": {
|
|
271
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
272
|
+
},
|
|
273
|
+
"[graphql]": {
|
|
274
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
275
|
+
},
|
|
276
|
+
"[astro]": {
|
|
277
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
278
|
+
}
|
|
279
|
+
`;
|
|
280
|
+
var eslintConfigContent = `
|
|
281
|
+
import { defineConfig } from '@dhzh/eslint-config';
|
|
282
|
+
|
|
283
|
+
export default defineConfig();
|
|
284
|
+
`;
|
|
285
|
+
|
|
286
|
+
// src/cli/stages/update-eslint-config.ts
|
|
287
|
+
async function updateEslintConfig() {
|
|
288
|
+
const cwd = import_node_process.default.cwd();
|
|
289
|
+
const pathPackageJSON = import_node_path.default.join(cwd, "package.json");
|
|
290
|
+
const pkgContent = await import_promises.default.readFile(pathPackageJSON, "utf8");
|
|
291
|
+
const pkg = JSON.parse(pkgContent);
|
|
292
|
+
const configFileName = pkg.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
293
|
+
const pathFlatConfig = import_node_path.default.join(cwd, configFileName);
|
|
294
|
+
await import_promises.default.writeFile(pathFlatConfig, eslintConfigContent);
|
|
295
|
+
p.log.success(import_ansis.default.green`Created ${configFileName}`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// src/cli/stages/update-package-json.ts
|
|
299
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
300
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
301
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
302
|
+
var p2 = __toESM(require("@clack/prompts"), 1);
|
|
303
|
+
var import_ansis2 = __toESM(require("ansis"), 1);
|
|
304
|
+
async function updatePackageJson() {
|
|
305
|
+
const cwd = import_node_process2.default.cwd();
|
|
306
|
+
const pathPackageJSON = import_node_path2.default.join(cwd, "package.json");
|
|
307
|
+
p2.log.step(import_ansis2.default.cyan`Bumping @dhzh/eslint-config to v${version}`);
|
|
308
|
+
const pkgContent = await import_promises2.default.readFile(pathPackageJSON, "utf8");
|
|
309
|
+
const pkg = JSON.parse(pkgContent);
|
|
310
|
+
pkg.devDependencies ??= {};
|
|
311
|
+
pkg.devDependencies["@dhzh/eslint-config"] = `^${version}`;
|
|
312
|
+
pkg.devDependencies.eslint ??= package_default.devDependencies.eslint;
|
|
313
|
+
await import_promises2.default.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
314
|
+
p2.log.success(import_ansis2.default.green`Changes wrote to package.json`);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/cli/stages/update-vscode-settings.ts
|
|
318
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
319
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
320
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
321
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
322
|
+
var import_ansis3 = require("ansis");
|
|
323
|
+
var p3 = __toESM(require("@clack/prompts"), 1);
|
|
324
|
+
async function updateVscodeSettings() {
|
|
325
|
+
const cwd = import_node_process3.default.cwd();
|
|
326
|
+
const dotVscodePath = import_node_path3.default.join(cwd, ".vscode");
|
|
327
|
+
const settingsPath = import_node_path3.default.join(dotVscodePath, "settings.json");
|
|
328
|
+
if (!import_node_fs.default.existsSync(dotVscodePath)) {
|
|
329
|
+
await import_promises3.default.mkdir(dotVscodePath, { recursive: true });
|
|
330
|
+
}
|
|
331
|
+
if (import_node_fs.default.existsSync(settingsPath)) {
|
|
332
|
+
let settingsContent = await import_promises3.default.readFile(settingsPath, "utf8");
|
|
333
|
+
settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
|
|
334
|
+
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
335
|
+
settingsContent += `${vscodeSettingsString}}
|
|
336
|
+
`;
|
|
337
|
+
await import_promises3.default.writeFile(settingsPath, settingsContent, "utf8");
|
|
338
|
+
p3.log.success(import_ansis3.green`Updated .vscode/settings.json`);
|
|
339
|
+
} else {
|
|
340
|
+
await import_promises3.default.writeFile(settingsPath, `{${vscodeSettingsString}}
|
|
341
|
+
`, "utf8");
|
|
342
|
+
p3.log.success(import_ansis3.green`Created .vscode/settings.json`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// src/cli/run.ts
|
|
347
|
+
async function run() {
|
|
348
|
+
await updatePackageJson();
|
|
349
|
+
await updateEslintConfig();
|
|
350
|
+
await updateVscodeSettings();
|
|
351
|
+
p4.log.success(import_ansis4.default.green`Setup completed`);
|
|
352
|
+
p4.outro(`Now you can update the dependencies by run ${import_ansis4.default.blue("pnpm i")} and run ${import_ansis4.default.blue("eslint --fix")}
|
|
353
|
+
`);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/cli/index.ts
|
|
357
|
+
var cli = (0, import_cac.cac)("@dhzh/eslint-config");
|
|
358
|
+
cli.command("", "Run the initialization or migration").action(async () => {
|
|
359
|
+
console.log("\n");
|
|
360
|
+
p5.intro(`${import_ansis5.default.green`@dhzh/eslint-config `}${import_ansis5.default.dim`v${version}`}`);
|
|
361
|
+
try {
|
|
362
|
+
await run();
|
|
363
|
+
} catch (error) {
|
|
364
|
+
p5.log.error(import_ansis5.default.inverse.red(" Failed to migrate "));
|
|
365
|
+
p5.log.error(import_ansis5.default.red`✘ ${String(error)}`);
|
|
366
|
+
throw error;
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
cli.help();
|
|
370
|
+
cli.version(version);
|
|
371
|
+
cli.parse();
|