@wongxy/eslint-config 0.0.16 → 0.0.18

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 CHANGED
@@ -5,9 +5,14 @@ Personal ESLint configuration, based on `@antfu/eslint-config`
5
5
  ## Usage
6
6
 
7
7
  ```bash
8
- npm i eslint @wongxy/eslint-config -D
8
+ pnpm i -D eslint @antfu/eslint-config
9
9
  ```
10
10
 
11
- ```bash
12
- npx wongxy-eslint-config
11
+ And create `eslint.config.mjs` in your project root:
12
+
13
+ ```js
14
+ // eslint.config.mjs
15
+ import wongxy from '@wongxy/eslint-config'
16
+
17
+ export default wongxy()
13
18
  ```
package/dist/index.cjs CHANGED
@@ -35,7 +35,11 @@ function wongxy(options, ...userConfigs) {
35
35
  "no-console": "off",
36
36
  "no-alert": "off",
37
37
  "no-multiple-empty-lines": "warn",
38
- "antfu/top-level-function": "off"
38
+ "antfu/top-level-function": "off",
39
+ "import/order": ["error", {
40
+ "newlines-between": "always-and-inside-groups",
41
+ "alphabetize": { order: "asc" }
42
+ }]
39
43
  }
40
44
  }
41
45
  );
package/dist/index.d.cts CHANGED
@@ -1,7 +1,9 @@
1
- import { OptionsConfig, FlatConfigItem, Awaitable, UserConfigItem } from '@antfu/eslint-config';
1
+ import { OptionsConfig, TypedFlatConfigItem, Awaitable, ConfigNames } from '@antfu/eslint-config';
2
+ import { Linter } from 'eslint';
3
+ import { FlatConfigComposer } from 'eslint-flat-config-utils';
2
4
 
3
- declare function wongxy(options?: OptionsConfig & FlatConfigItem & {
5
+ declare function wongxy(options?: OptionsConfig & TypedFlatConfigItem & {
4
6
  reactnative?: boolean;
5
- }, ...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]>;
7
+ }, ...userConfigs: Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[] | FlatConfigComposer<any, any> | Linter.FlatConfig[]>[]): FlatConfigComposer<TypedFlatConfigItem, ConfigNames>;
6
8
 
7
9
  export { wongxy as default };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { OptionsConfig, FlatConfigItem, Awaitable, UserConfigItem } from '@antfu/eslint-config';
1
+ import { OptionsConfig, TypedFlatConfigItem, Awaitable, ConfigNames } from '@antfu/eslint-config';
2
+ import { Linter } from 'eslint';
3
+ import { FlatConfigComposer } from 'eslint-flat-config-utils';
2
4
 
3
- declare function wongxy(options?: OptionsConfig & FlatConfigItem & {
5
+ declare function wongxy(options?: OptionsConfig & TypedFlatConfigItem & {
4
6
  reactnative?: boolean;
5
- }, ...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]>;
7
+ }, ...userConfigs: Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[] | FlatConfigComposer<any, any> | Linter.FlatConfig[]>[]): FlatConfigComposer<TypedFlatConfigItem, ConfigNames>;
6
8
 
7
9
  export { wongxy as default };
package/dist/index.js CHANGED
@@ -11,7 +11,11 @@ function wongxy(options, ...userConfigs) {
11
11
  "no-console": "off",
12
12
  "no-alert": "off",
13
13
  "no-multiple-empty-lines": "warn",
14
- "antfu/top-level-function": "off"
14
+ "antfu/top-level-function": "off",
15
+ "import/order": ["error", {
16
+ "newlines-between": "always-and-inside-groups",
17
+ "alphabetize": { order: "asc" }
18
+ }]
15
19
  }
16
20
  }
17
21
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wongxy/eslint-config",
3
3
  "type": "module",
4
- "version": "0.0.16",
4
+ "version": "0.0.18",
5
5
  "description": "xiyaowong's eslint config",
6
6
  "author": "xiyaowong (https://github.com/xiyaowong)",
7
7
  "license": "MIT",
@@ -12,41 +12,25 @@
12
12
  }
13
13
  },
14
14
  "main": "dist/index.js",
15
- "bin": {
16
- "eslint-config": "bin/index.js",
17
- "eslint-config-wongxy": "bin/index.js",
18
- "wongxy-eslint": "bin/index.js",
19
- "wongxy-eslint-config": "bin/index.js"
20
- },
21
15
  "files": [
22
- "bin",
23
16
  "dist"
24
17
  ],
25
18
  "peerDependencies": {
26
- "eslint-plugin-react": "*",
27
- "eslint-plugin-react-hooks": "*",
28
- "eslint-plugin-react-refresh": "*"
19
+ "@eslint-react/eslint-plugin": "^1.5.8",
20
+ "@unocss/eslint-plugin": ">=0.50.0",
21
+ "eslint-plugin-react-hooks": "^4.6.0",
22
+ "eslint-plugin-react-refresh": "^0.4.4"
29
23
  },
30
24
  "dependencies": {
31
- "@antfu/eslint-config": "^2.7.0",
32
- "parse-gitignore": "^2.0.0",
33
- "picocolors": "^1.0.0",
34
- "prompts": "^2.4.2",
35
- "yargs": "^17.7.2"
25
+ "@antfu/eslint-config": "^2.15.0"
36
26
  },
37
27
  "devDependencies": {
38
28
  "@types/eslint": "^8.56.5",
39
- "@types/prompts": "^2.4.9",
40
- "@types/yargs": "^17.0.32",
41
29
  "bumpp": "^9.3.0",
42
- "eslint": "^8.57.0",
30
+ "eslint": "^9.0.0",
43
31
  "eslint-flat-config-viewer": "^0.1.11",
44
- "parse-gitignore": "^2.0.0",
45
- "picocolors": "^1.0.0",
46
- "prompts": "^2.4.2",
47
32
  "tsup": "^8.0.2",
48
- "typescript": "5.3.3",
49
- "yargs": "^17.7.2"
33
+ "typescript": "5.4.5"
50
34
  },
51
35
  "scripts": {
52
36
  "build": "tsup --format esm,cjs --clean --dts",
package/bin/index.js DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import '../dist/cli.js'
package/dist/cli.cjs DELETED
@@ -1,313 +0,0 @@
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
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
-
26
- // src/cli.ts
27
- var cli_exports = {};
28
- module.exports = __toCommonJS(cli_exports);
29
-
30
- // src/cli/index.ts
31
- var import_node_process2 = __toESM(require("process"), 1);
32
- var import_picocolors3 = __toESM(require("picocolors"), 1);
33
- var import_helpers = require("yargs/helpers");
34
- var import_yargs = __toESM(require("yargs"), 1);
35
-
36
- // src/cli/run.ts
37
- var import_node_fs = __toESM(require("fs"), 1);
38
- var import_promises = __toESM(require("fs/promises"), 1);
39
- var import_node_path = __toESM(require("path"), 1);
40
- var import_node_process = __toESM(require("process"), 1);
41
- var import_prompts = __toESM(require("prompts"), 1);
42
- var import_picocolors2 = __toESM(require("picocolors"), 1);
43
- var import_parse_gitignore = __toESM(require("parse-gitignore"), 1);
44
-
45
- // src/cli/constants.ts
46
- var import_picocolors = __toESM(require("picocolors"), 1);
47
-
48
- // package.json
49
- var version = "0.0.16";
50
- var devDependencies = {
51
- "@types/eslint": "^8.56.5",
52
- "@types/prompts": "^2.4.9",
53
- "@types/yargs": "^17.0.32",
54
- bumpp: "^9.3.0",
55
- eslint: "^8.57.0",
56
- "eslint-flat-config-viewer": "^0.1.11",
57
- "parse-gitignore": "^2.0.0",
58
- picocolors: "^1.0.0",
59
- prompts: "^2.4.2",
60
- tsup: "^8.0.2",
61
- typescript: "5.3.3",
62
- yargs: "^17.7.2"
63
- };
64
-
65
- // src/cli/constants.ts
66
- var ARROW = import_picocolors.default.cyan("\u2192");
67
- var CHECK = import_picocolors.default.green("\u2714");
68
- var CROSS = import_picocolors.default.red("\u2718");
69
- var WARN = import_picocolors.default.yellow("\u2139");
70
- var eslintVersion = devDependencies.eslint;
71
- var vscodeSettingsString = `
72
- // Enable the ESlint flat config support
73
- "eslint.experimental.useFlatConfig": true,
74
-
75
- // Disable the default formatter, use eslint instead
76
- "prettier.enable": false,
77
- "editor.formatOnSave": false,
78
-
79
- // Auto fix
80
- "editor.codeActionsOnSave": {
81
- "source.fixAll.eslint": "explicit",
82
- "source.organizeImports": "never"
83
- },
84
-
85
- // Silent the stylistic rules in you IDE, but still auto fix them
86
- "eslint.rules.customizations": [
87
- { "rule": "style/*", "severity": "off" },
88
- { "rule": "format/*", "severity": "off" },
89
- { "rule": "*-indent", "severity": "off" },
90
- { "rule": "*-spacing", "severity": "off" },
91
- { "rule": "*-spaces", "severity": "off" },
92
- { "rule": "*-order", "severity": "off" },
93
- { "rule": "*-dangle", "severity": "off" },
94
- { "rule": "*-newline", "severity": "off" },
95
- { "rule": "*quotes", "severity": "off" },
96
- { "rule": "*semi", "severity": "off" }
97
- ],
98
-
99
- // Enable eslint for all supported languages
100
- "eslint.validate": [
101
- "javascript",
102
- "javascriptreact",
103
- "typescript",
104
- "typescriptreact",
105
- "vue",
106
- "html",
107
- "markdown",
108
- "json",
109
- "jsonc",
110
- "yaml",
111
- "toml"
112
- ]
113
- `;
114
-
115
- // src/cli/utils.ts
116
- var import_node_child_process = require("child_process");
117
- function isGitClean() {
118
- try {
119
- (0, import_node_child_process.execSync)("git diff-index --quiet HEAD --");
120
- return true;
121
- } catch (error) {
122
- return false;
123
- }
124
- }
125
-
126
- // src/cli/run.ts
127
- async function run(options = {}) {
128
- const SKIP_PROMPT = !!import_node_process.default.env.SKIP_PROMPT || options.yes;
129
- const SKIP_GIT_CHECK = !!import_node_process.default.env.SKIP_GIT_CHECK;
130
- const cwd = import_node_process.default.cwd();
131
- const pathFlatConfig = import_node_path.default.join(cwd, "eslint.config.js");
132
- const pathPackageJSON = import_node_path.default.join(cwd, "package.json");
133
- const pathESLintIgnore = import_node_path.default.join(cwd, ".eslintignore");
134
- if (import_node_fs.default.existsSync(pathFlatConfig)) {
135
- console.log(import_picocolors2.default.yellow(`${WARN} eslint.config.js already exists, migration wizard exited.`));
136
- return import_node_process.default.exit(1);
137
- }
138
- if (!SKIP_GIT_CHECK && !isGitClean()) {
139
- const { confirmed } = await (0, import_prompts.default)({
140
- initial: false,
141
- message: "There are uncommitted changes in the current repository, are you sure to continue?",
142
- name: "confirmed",
143
- type: "confirm"
144
- });
145
- if (!confirmed)
146
- return import_node_process.default.exit(1);
147
- }
148
- console.log(import_picocolors2.default.cyan(`${ARROW} bumping @wongxy/eslint-config to v${version}`));
149
- const pkgContent = await import_promises.default.readFile(pathPackageJSON, "utf-8");
150
- const pkg = JSON.parse(pkgContent);
151
- pkg.devDependencies ?? (pkg.devDependencies = {});
152
- pkg.devDependencies["@wongxy/eslint-config"] = `^${version}`;
153
- if (!pkg.devDependencies.eslint)
154
- pkg.devDependencies.eslint = eslintVersion;
155
- await import_promises.default.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
156
- console.log(import_picocolors2.default.green(`${CHECK} changes wrote to package.json`));
157
- const eslintIgnores = [];
158
- if (import_node_fs.default.existsSync(pathESLintIgnore)) {
159
- console.log(import_picocolors2.default.cyan(`${ARROW} migrating existing .eslintignore`));
160
- const content = await import_promises.default.readFile(pathESLintIgnore, "utf-8");
161
- const parsed = (0, import_parse_gitignore.default)(content);
162
- const globs = parsed.globs();
163
- for (const glob of globs) {
164
- if (glob.type === "ignore")
165
- eslintIgnores.push(...glob.patterns);
166
- else if (glob.type === "unignore")
167
- eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
168
- }
169
- }
170
- const configs = [];
171
- if (eslintIgnores.length)
172
- configs.push(` ignores: ${JSON.stringify(eslintIgnores)},`);
173
- if (!SKIP_PROMPT) {
174
- let enableReactNativeRulesPrompt = {
175
- enableReactNativeRules: false
176
- };
177
- try {
178
- enableReactNativeRulesPrompt = await (0, import_prompts.default)({
179
- initial: false,
180
- message: "Enable React Native rules?",
181
- name: "enableReactNativeRules",
182
- type: "confirm"
183
- }, {
184
- onCancel: () => {
185
- throw new Error(`Cancelled`);
186
- }
187
- });
188
- } catch (cancelled) {
189
- console.log(cancelled.message);
190
- return;
191
- }
192
- if (enableReactNativeRulesPrompt.enableReactNativeRules)
193
- configs.push(` reactnative: true,`);
194
- if (!enableReactNativeRulesPrompt.enableReactNativeRules) {
195
- let enableReactRulesPrompt = {
196
- enableReactRules: false
197
- };
198
- try {
199
- enableReactRulesPrompt = await (0, import_prompts.default)({
200
- initial: false,
201
- message: "Enable React rules?",
202
- name: "enableReactRules",
203
- type: "confirm"
204
- }, {
205
- onCancel: () => {
206
- throw new Error(`Cancelled`);
207
- }
208
- });
209
- } catch (cancelled) {
210
- console.log(cancelled.message);
211
- return;
212
- }
213
- if (enableReactRulesPrompt.enableReactRules)
214
- configs.push(` react: true,`);
215
- }
216
- }
217
- const wongxyConfig = configs.join("\n");
218
- let eslintConfigContent = "";
219
- if (pkg.type === "module") {
220
- eslintConfigContent = `
221
- import wongxy from '@wongxy/eslint-config'
222
-
223
- export default wongxy({
224
- ${wongxyConfig}
225
- })
226
- `.trimStart();
227
- } else {
228
- eslintConfigContent = `
229
- const wongxy = require('@wongxy/eslint-config').default
230
-
231
- module.exports = wongxy({
232
- ${wongxyConfig}
233
- })
234
- `.trimStart();
235
- }
236
- await import_promises.default.writeFile(pathFlatConfig, eslintConfigContent);
237
- console.log(import_picocolors2.default.green(`${CHECK} created eslint.config.js`));
238
- const files = import_node_fs.default.readdirSync(cwd);
239
- const legacyConfig = [];
240
- files.forEach((file) => {
241
- if (file.includes("eslint") || file.includes("prettier"))
242
- legacyConfig.push(file);
243
- });
244
- if (legacyConfig.length) {
245
- console.log(`${WARN} you can now remove those files manually:`);
246
- console.log(` ${import_picocolors2.default.dim(legacyConfig.join(", "))}`);
247
- }
248
- let promptResult = {
249
- updateVscodeSettings: true
250
- };
251
- if (!SKIP_PROMPT) {
252
- try {
253
- promptResult = await (0, import_prompts.default)({
254
- initial: true,
255
- message: "Update .vscode/settings.json for better VS Code experience?",
256
- name: "updateVscodeSettings",
257
- type: "confirm"
258
- }, {
259
- onCancel: () => {
260
- throw new Error(`Cancelled`);
261
- }
262
- });
263
- } catch (cancelled) {
264
- console.log(cancelled.message);
265
- return;
266
- }
267
- }
268
- if (promptResult?.updateVscodeSettings ?? true) {
269
- const dotVscodePath = import_node_path.default.join(cwd, ".vscode");
270
- const settingsPath = import_node_path.default.join(dotVscodePath, "settings.json");
271
- if (!import_node_fs.default.existsSync(dotVscodePath))
272
- await import_promises.default.mkdir(dotVscodePath, { recursive: true });
273
- if (!import_node_fs.default.existsSync(settingsPath)) {
274
- await import_promises.default.writeFile(settingsPath, `{${vscodeSettingsString}}
275
- `, "utf-8");
276
- console.log(import_picocolors2.default.green(`${CHECK} created .vscode/settings.json`));
277
- } else {
278
- let settingsContent = await import_promises.default.readFile(settingsPath, "utf8");
279
- settingsContent = settingsContent.trim().replace(/\s*}$/, "");
280
- settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
281
- settingsContent += `${vscodeSettingsString}}
282
- `;
283
- await import_promises.default.writeFile(settingsPath, settingsContent, "utf-8");
284
- console.log(import_picocolors2.default.green(`${CHECK} updated .vscode/settings.json`));
285
- }
286
- }
287
- console.log(import_picocolors2.default.green(`${CHECK} migration completed`));
288
- console.log(`Now you can update the dependencies and run ${import_picocolors2.default.blue("eslint . --fix")}
289
- `);
290
- }
291
-
292
- // src/cli/index.ts
293
- function header() {
294
- console.log(`
295
- ${import_picocolors3.default.green(`@wongxy/eslint-config `)}${import_picocolors3.default.dim(`v${version}`)}`);
296
- }
297
- var instance = (0, import_yargs.default)((0, import_helpers.hideBin)(import_node_process2.default.argv)).scriptName("@wongxy/eslint-config").usage("").command(
298
- "*",
299
- "Run the initialization or migration",
300
- (args) => args.option("yes", { alias: "y", description: "Skip prompts and use default values", type: "boolean" }).help(),
301
- async (args) => {
302
- header();
303
- console.log();
304
- try {
305
- await run(args);
306
- } catch (error) {
307
- console.error(import_picocolors3.default.inverse(import_picocolors3.default.red(" Failed to migrate ")));
308
- console.error(import_picocolors3.default.red(`${CROSS} ${String(error)}`));
309
- import_node_process2.default.exit(1);
310
- }
311
- }
312
- ).showHelpOnFail(false).alias("h", "help").version("version", version).alias("v", "version");
313
- instance.help().argv;
package/dist/cli.d.cts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { }
package/dist/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { }
package/dist/cli.js DELETED
@@ -1,284 +0,0 @@
1
- // src/cli/index.ts
2
- import process2 from "process";
3
- import c3 from "picocolors";
4
- import { hideBin } from "yargs/helpers";
5
- import yargs from "yargs";
6
-
7
- // src/cli/run.ts
8
- import fs from "fs";
9
- import fsp from "fs/promises";
10
- import path from "path";
11
- import process from "process";
12
- import prompts from "prompts";
13
- import c2 from "picocolors";
14
- import parse from "parse-gitignore";
15
-
16
- // src/cli/constants.ts
17
- import c from "picocolors";
18
-
19
- // package.json
20
- var version = "0.0.16";
21
- var devDependencies = {
22
- "@types/eslint": "^8.56.5",
23
- "@types/prompts": "^2.4.9",
24
- "@types/yargs": "^17.0.32",
25
- bumpp: "^9.3.0",
26
- eslint: "^8.57.0",
27
- "eslint-flat-config-viewer": "^0.1.11",
28
- "parse-gitignore": "^2.0.0",
29
- picocolors: "^1.0.0",
30
- prompts: "^2.4.2",
31
- tsup: "^8.0.2",
32
- typescript: "5.3.3",
33
- yargs: "^17.7.2"
34
- };
35
-
36
- // src/cli/constants.ts
37
- var ARROW = c.cyan("\u2192");
38
- var CHECK = c.green("\u2714");
39
- var CROSS = c.red("\u2718");
40
- var WARN = c.yellow("\u2139");
41
- var eslintVersion = devDependencies.eslint;
42
- var vscodeSettingsString = `
43
- // Enable the ESlint flat config support
44
- "eslint.experimental.useFlatConfig": true,
45
-
46
- // Disable the default formatter, use eslint instead
47
- "prettier.enable": false,
48
- "editor.formatOnSave": false,
49
-
50
- // Auto fix
51
- "editor.codeActionsOnSave": {
52
- "source.fixAll.eslint": "explicit",
53
- "source.organizeImports": "never"
54
- },
55
-
56
- // Silent the stylistic rules in you IDE, but still auto fix them
57
- "eslint.rules.customizations": [
58
- { "rule": "style/*", "severity": "off" },
59
- { "rule": "format/*", "severity": "off" },
60
- { "rule": "*-indent", "severity": "off" },
61
- { "rule": "*-spacing", "severity": "off" },
62
- { "rule": "*-spaces", "severity": "off" },
63
- { "rule": "*-order", "severity": "off" },
64
- { "rule": "*-dangle", "severity": "off" },
65
- { "rule": "*-newline", "severity": "off" },
66
- { "rule": "*quotes", "severity": "off" },
67
- { "rule": "*semi", "severity": "off" }
68
- ],
69
-
70
- // Enable eslint for all supported languages
71
- "eslint.validate": [
72
- "javascript",
73
- "javascriptreact",
74
- "typescript",
75
- "typescriptreact",
76
- "vue",
77
- "html",
78
- "markdown",
79
- "json",
80
- "jsonc",
81
- "yaml",
82
- "toml"
83
- ]
84
- `;
85
-
86
- // src/cli/utils.ts
87
- import { execSync } from "child_process";
88
- function isGitClean() {
89
- try {
90
- execSync("git diff-index --quiet HEAD --");
91
- return true;
92
- } catch (error) {
93
- return false;
94
- }
95
- }
96
-
97
- // src/cli/run.ts
98
- async function run(options = {}) {
99
- const SKIP_PROMPT = !!process.env.SKIP_PROMPT || options.yes;
100
- const SKIP_GIT_CHECK = !!process.env.SKIP_GIT_CHECK;
101
- const cwd = process.cwd();
102
- const pathFlatConfig = path.join(cwd, "eslint.config.js");
103
- const pathPackageJSON = path.join(cwd, "package.json");
104
- const pathESLintIgnore = path.join(cwd, ".eslintignore");
105
- if (fs.existsSync(pathFlatConfig)) {
106
- console.log(c2.yellow(`${WARN} eslint.config.js already exists, migration wizard exited.`));
107
- return process.exit(1);
108
- }
109
- if (!SKIP_GIT_CHECK && !isGitClean()) {
110
- const { confirmed } = await prompts({
111
- initial: false,
112
- message: "There are uncommitted changes in the current repository, are you sure to continue?",
113
- name: "confirmed",
114
- type: "confirm"
115
- });
116
- if (!confirmed)
117
- return process.exit(1);
118
- }
119
- console.log(c2.cyan(`${ARROW} bumping @wongxy/eslint-config to v${version}`));
120
- const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
121
- const pkg = JSON.parse(pkgContent);
122
- pkg.devDependencies ?? (pkg.devDependencies = {});
123
- pkg.devDependencies["@wongxy/eslint-config"] = `^${version}`;
124
- if (!pkg.devDependencies.eslint)
125
- pkg.devDependencies.eslint = eslintVersion;
126
- await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
127
- console.log(c2.green(`${CHECK} changes wrote to package.json`));
128
- const eslintIgnores = [];
129
- if (fs.existsSync(pathESLintIgnore)) {
130
- console.log(c2.cyan(`${ARROW} migrating existing .eslintignore`));
131
- const content = await fsp.readFile(pathESLintIgnore, "utf-8");
132
- const parsed = parse(content);
133
- const globs = parsed.globs();
134
- for (const glob of globs) {
135
- if (glob.type === "ignore")
136
- eslintIgnores.push(...glob.patterns);
137
- else if (glob.type === "unignore")
138
- eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
139
- }
140
- }
141
- const configs = [];
142
- if (eslintIgnores.length)
143
- configs.push(` ignores: ${JSON.stringify(eslintIgnores)},`);
144
- if (!SKIP_PROMPT) {
145
- let enableReactNativeRulesPrompt = {
146
- enableReactNativeRules: false
147
- };
148
- try {
149
- enableReactNativeRulesPrompt = await prompts({
150
- initial: false,
151
- message: "Enable React Native rules?",
152
- name: "enableReactNativeRules",
153
- type: "confirm"
154
- }, {
155
- onCancel: () => {
156
- throw new Error(`Cancelled`);
157
- }
158
- });
159
- } catch (cancelled) {
160
- console.log(cancelled.message);
161
- return;
162
- }
163
- if (enableReactNativeRulesPrompt.enableReactNativeRules)
164
- configs.push(` reactnative: true,`);
165
- if (!enableReactNativeRulesPrompt.enableReactNativeRules) {
166
- let enableReactRulesPrompt = {
167
- enableReactRules: false
168
- };
169
- try {
170
- enableReactRulesPrompt = await prompts({
171
- initial: false,
172
- message: "Enable React rules?",
173
- name: "enableReactRules",
174
- type: "confirm"
175
- }, {
176
- onCancel: () => {
177
- throw new Error(`Cancelled`);
178
- }
179
- });
180
- } catch (cancelled) {
181
- console.log(cancelled.message);
182
- return;
183
- }
184
- if (enableReactRulesPrompt.enableReactRules)
185
- configs.push(` react: true,`);
186
- }
187
- }
188
- const wongxyConfig = configs.join("\n");
189
- let eslintConfigContent = "";
190
- if (pkg.type === "module") {
191
- eslintConfigContent = `
192
- import wongxy from '@wongxy/eslint-config'
193
-
194
- export default wongxy({
195
- ${wongxyConfig}
196
- })
197
- `.trimStart();
198
- } else {
199
- eslintConfigContent = `
200
- const wongxy = require('@wongxy/eslint-config').default
201
-
202
- module.exports = wongxy({
203
- ${wongxyConfig}
204
- })
205
- `.trimStart();
206
- }
207
- await fsp.writeFile(pathFlatConfig, eslintConfigContent);
208
- console.log(c2.green(`${CHECK} created eslint.config.js`));
209
- const files = fs.readdirSync(cwd);
210
- const legacyConfig = [];
211
- files.forEach((file) => {
212
- if (file.includes("eslint") || file.includes("prettier"))
213
- legacyConfig.push(file);
214
- });
215
- if (legacyConfig.length) {
216
- console.log(`${WARN} you can now remove those files manually:`);
217
- console.log(` ${c2.dim(legacyConfig.join(", "))}`);
218
- }
219
- let promptResult = {
220
- updateVscodeSettings: true
221
- };
222
- if (!SKIP_PROMPT) {
223
- try {
224
- promptResult = await prompts({
225
- initial: true,
226
- message: "Update .vscode/settings.json for better VS Code experience?",
227
- name: "updateVscodeSettings",
228
- type: "confirm"
229
- }, {
230
- onCancel: () => {
231
- throw new Error(`Cancelled`);
232
- }
233
- });
234
- } catch (cancelled) {
235
- console.log(cancelled.message);
236
- return;
237
- }
238
- }
239
- if (promptResult?.updateVscodeSettings ?? true) {
240
- const dotVscodePath = path.join(cwd, ".vscode");
241
- const settingsPath = path.join(dotVscodePath, "settings.json");
242
- if (!fs.existsSync(dotVscodePath))
243
- await fsp.mkdir(dotVscodePath, { recursive: true });
244
- if (!fs.existsSync(settingsPath)) {
245
- await fsp.writeFile(settingsPath, `{${vscodeSettingsString}}
246
- `, "utf-8");
247
- console.log(c2.green(`${CHECK} created .vscode/settings.json`));
248
- } else {
249
- let settingsContent = await fsp.readFile(settingsPath, "utf8");
250
- settingsContent = settingsContent.trim().replace(/\s*}$/, "");
251
- settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
252
- settingsContent += `${vscodeSettingsString}}
253
- `;
254
- await fsp.writeFile(settingsPath, settingsContent, "utf-8");
255
- console.log(c2.green(`${CHECK} updated .vscode/settings.json`));
256
- }
257
- }
258
- console.log(c2.green(`${CHECK} migration completed`));
259
- console.log(`Now you can update the dependencies and run ${c2.blue("eslint . --fix")}
260
- `);
261
- }
262
-
263
- // src/cli/index.ts
264
- function header() {
265
- console.log(`
266
- ${c3.green(`@wongxy/eslint-config `)}${c3.dim(`v${version}`)}`);
267
- }
268
- var instance = yargs(hideBin(process2.argv)).scriptName("@wongxy/eslint-config").usage("").command(
269
- "*",
270
- "Run the initialization or migration",
271
- (args) => args.option("yes", { alias: "y", description: "Skip prompts and use default values", type: "boolean" }).help(),
272
- async (args) => {
273
- header();
274
- console.log();
275
- try {
276
- await run(args);
277
- } catch (error) {
278
- console.error(c3.inverse(c3.red(" Failed to migrate ")));
279
- console.error(c3.red(`${CROSS} ${String(error)}`));
280
- process2.exit(1);
281
- }
282
- }
283
- ).showHelpOnFail(false).alias("h", "help").version("version", version).alias("v", "version");
284
- instance.help().argv;