@dhzh/eslint-config 0.1.4 → 0.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024-PRESENT Easton Zheng<https://github.com/eastonzh>
3
+ Copyright (c) 2022-PRESENT Easton Zheng
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,45 +1,44 @@
1
1
  # @dhzh/eslint-config
2
2
 
3
- Fork from [@antfu/eslint-config](https://github.com/antfu/eslint-config).
3
+ [![npm](https://img.shields.io/npm/v/@dhzh/eslint-config?color=444&label=)](https://npmjs.com/package/@antfu/eslint-config)
4
4
 
5
- [![npm](https://img.shields.io/npm/v/@dhzh/eslint-config?color=444&label=)](https://npmjs.com/package/@dhzh/eslint-config)
5
+ > `Special Statement`: This project comes from [`@antfu/eslint-config`](https://github.com/antfu/eslint-config). The two are almost the same, with only some differences to meet personal needs. In order to seek convenience and prevent some conflicts between the upstream branch and my own changes after forking, I chose to copy instead of fork.
6
+
7
+ Differences from [@antfu/eslint-config](./README-antfu.md):
8
+
9
+ 1. With semi: `semi: true`.
10
+ 2. Always arrow parens: `arrowParens: true`.
11
+ 3. Explicitly use `1tbs` as brace style: `braceStyle: '1tbs'`.
12
+ 4. Disabled antfu's top level function rule: `'antfu/top-level-function': 'off'`.
13
+ 5. Always curly: `'curly': ['error', 'all']`.
6
14
 
7
15
  ## Usage
8
16
 
9
- ### Wizard
17
+ ### Starter Wizard
10
18
 
11
- ```bash
12
- npx @dhzh/eslint-config@latest
19
+ We provided a CLI tool to help you set up your project, or migrate from the legacy config to the new flat config with one command.
20
+
21
+ ```shell
22
+ pnpm dlx @dhzh/eslint-config@latest
13
23
  ```
14
24
 
15
- ### Install
25
+ ### Manual Install
26
+
27
+ If you prefer to set up manually:
16
28
 
17
29
  ```bash
18
30
  pnpm i -D eslint @dhzh/eslint-config
19
31
  ```
20
32
 
21
- ### Create config file
22
-
23
- With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package.json` (recommended):
33
+ And create `eslint.config.mjs` in your project root:
24
34
 
25
35
  ```js
26
- // eslint.config.js
36
+ // eslint.config.mjs
27
37
  import dhzh from '@dhzh/eslint-config';
28
38
 
29
39
  export default dhzh();
30
40
  ```
31
41
 
32
- With CJS:
33
-
34
- ```js
35
- // eslint.config.js
36
- const dhzh = require('@dhzh/eslint-config').default;
37
-
38
- module.exports = dhzh();
39
- ```
40
-
41
- More details, you can see [README-antfu](./README-antfu.md).
42
-
43
42
  ## License
44
43
 
45
- [MIT](./LICENSE) License &copy; 2024-PRESENT [Easton Zheng](https://github.com/eastonzh)
44
+ [MIT](./LICENSE) License &copy; 2022-PRESENT [Easton Zheng](https://github.com/eastonzh)
package/dist/cli.cjs CHANGED
@@ -48,13 +48,14 @@ var import_picocolors = __toESM(require("picocolors"), 1);
48
48
  var package_default = {
49
49
  name: "@dhzh/eslint-config",
50
50
  type: "module",
51
- version: "0.1.4",
52
- packageManager: "pnpm@8.15.4",
51
+ version: "0.2.1",
52
+ packageManager: "pnpm@8.15.7",
53
53
  description: "Easton's ESLint config",
54
54
  author: "Easton Zheng <dhzhme@gmail.com>",
55
55
  license: "MIT",
56
56
  homepage: "https://github.com/eastonzh/eslint-config",
57
57
  keywords: [
58
+ "eslint",
58
59
  "eslint-config"
59
60
  ],
60
61
  exports: {
@@ -73,7 +74,8 @@ var package_default = {
73
74
  scripts: {
74
75
  build: "nr typegen && tsup --format esm,cjs --clean --dts",
75
76
  stub: "tsup --format esm",
76
- dev: "tsup --format esm,cjs --watch & eslint-flat-config-viewer",
77
+ dev: "npx @eslint/config-inspector --config eslint.config.ts",
78
+ "build:inspector": "pnpm build && npx @eslint/config-inspector build",
77
79
  watch: "tsup --format esm,cjs --watch",
78
80
  lint: "eslint .",
79
81
  typegen: "esno scripts/typegen.ts",
@@ -89,7 +91,8 @@ var package_default = {
89
91
  eslint: ">=8.40.0",
90
92
  "eslint-plugin-astro": "^0.31.4",
91
93
  "eslint-plugin-format": ">=0.1.0",
92
- "eslint-plugin-svelte": "^2.35.1",
94
+ "eslint-plugin-solid": "^0.13.2",
95
+ "eslint-plugin-svelte": ">=2.35.1",
93
96
  "prettier-plugin-astro": "^0.13.0",
94
97
  "prettier-plugin-slidev": "^1.0.5",
95
98
  "svelte-eslint-parser": "^0.33.1"
@@ -107,6 +110,9 @@ var package_default = {
107
110
  "eslint-plugin-format": {
108
111
  optional: true
109
112
  },
113
+ "eslint-plugin-solid": {
114
+ optional: true
115
+ },
110
116
  "eslint-plugin-svelte": {
111
117
  optional: true
112
118
  },
@@ -124,29 +130,29 @@ var package_default = {
124
130
  "@antfu/install-pkg": "^0.3.2",
125
131
  "@clack/prompts": "^0.7.0",
126
132
  "@stylistic/eslint-plugin": "^1.7.0",
127
- "@typescript-eslint/eslint-plugin": "^7.4.0",
128
- "@typescript-eslint/parser": "^7.4.0",
129
- "eslint-config-flat-gitignore": "^0.1.3",
130
- "eslint-flat-config-utils": "^0.1.1",
133
+ "@typescript-eslint/eslint-plugin": "^7.6.0",
134
+ "@typescript-eslint/parser": "^7.6.0",
135
+ "eslint-config-flat-gitignore": "^0.1.5",
136
+ "eslint-flat-config-utils": "^0.2.3",
131
137
  "eslint-merge-processors": "^0.1.0",
132
138
  "eslint-plugin-antfu": "^2.1.2",
133
139
  "eslint-plugin-eslint-comments": "^3.2.0",
134
- "eslint-plugin-import-x": "^0.4.4",
135
- "eslint-plugin-jsdoc": "^48.2.1",
136
- "eslint-plugin-jsonc": "^2.14.1",
140
+ "eslint-plugin-import-x": "^0.5.0",
141
+ "eslint-plugin-jsdoc": "^48.2.3",
142
+ "eslint-plugin-jsonc": "^2.15.1",
137
143
  "eslint-plugin-markdown": "^4.0.1",
138
- "eslint-plugin-n": "^16.6.2",
144
+ "eslint-plugin-n": "^17.2.1",
139
145
  "eslint-plugin-no-only-tests": "^3.1.0",
140
- "eslint-plugin-perfectionist": "^2.6.0",
146
+ "eslint-plugin-perfectionist": "^2.9.0",
141
147
  "eslint-plugin-react": "^7.34.1",
142
148
  "eslint-plugin-react-hooks": "^4.6.0",
143
149
  "eslint-plugin-react-refresh": "^0.4.6",
144
- "eslint-plugin-toml": "^0.9.2",
145
- "eslint-plugin-unicorn": "^51.0.1",
150
+ "eslint-plugin-toml": "^0.11.0",
151
+ "eslint-plugin-unicorn": "^52.0.0",
146
152
  "eslint-plugin-unused-imports": "^3.1.0",
147
- "eslint-plugin-vitest": "^0.4.0",
148
- "eslint-plugin-vue": "^9.24.0",
149
- "eslint-plugin-yml": "^1.13.2",
153
+ "eslint-plugin-vitest": "^0.5.3",
154
+ "eslint-plugin-vue": "^9.25.0",
155
+ "eslint-plugin-yml": "^1.14.0",
150
156
  "eslint-processor-vue-blocks": "^0.1.1",
151
157
  globals: "^15.0.0",
152
158
  "jsonc-eslint-parser": "^2.4.0",
@@ -162,21 +168,23 @@ var package_default = {
162
168
  "@antfu/eslint-plugin-prettier": "^5.0.1-1",
163
169
  "@antfu/ni": "^0.21.12",
164
170
  "@dhzh/eslint-config": "workspace:*",
171
+ "@eslint/config-inspector": "^0.4.6",
165
172
  "@stylistic/eslint-plugin-migrate": "^1.7.0",
166
- "@types/eslint": "^8.56.6",
173
+ "@types/eslint": "^8.56.9",
167
174
  "@types/fs-extra": "^11.0.4",
168
- "@types/node": "^20.11.30",
175
+ "@types/node": "^20.12.7",
169
176
  "@types/prompts": "^2.4.9",
170
177
  "@types/yargs": "^17.0.32",
171
- "@unocss/eslint-plugin": "^0.58.7",
172
- "astro-eslint-parser": "^0.16.3",
178
+ "@unocss/eslint-plugin": "^0.59.2",
179
+ "astro-eslint-parser": "^0.17.0",
173
180
  bumpp: "^9.4.0",
174
- eslint: "9.0.0-rc.0",
175
- "eslint-flat-config-viewer": "^0.1.14",
176
- "eslint-plugin-astro": "^0.33.1",
181
+ "bundle-require": "^4.0.2",
182
+ eslint: "^9.0.0",
183
+ "eslint-plugin-astro": "^0.34.0",
177
184
  "eslint-plugin-format": "^0.1.0",
185
+ "eslint-plugin-solid": "^0.13.2",
178
186
  "eslint-plugin-svelte": "2.36.0-next.13",
179
- "eslint-typegen": "^0.1.4",
187
+ "eslint-typegen": "^0.2.3",
180
188
  esno: "^4.7.0",
181
189
  execa: "^8.0.1",
182
190
  "fast-glob": "^3.3.2",
@@ -186,11 +194,11 @@ var package_default = {
186
194
  "prettier-plugin-slidev": "^1.0.5",
187
195
  rimraf: "^5.0.5",
188
196
  "simple-git-hooks": "^2.11.1",
189
- svelte: "^4.2.12",
190
- "svelte-eslint-parser": "^0.33.1",
197
+ svelte: "^4.2.14",
198
+ "svelte-eslint-parser": "^0.34.1",
191
199
  tsup: "^8.0.2",
192
- typescript: "^5.4.3",
193
- vitest: "^1.4.0",
200
+ typescript: "^5.4.5",
201
+ vitest: "^1.5.0",
194
202
  vue: "^3.4.21"
195
203
  },
196
204
  "simple-git-hooks": {
@@ -203,11 +211,16 @@ var package_default = {
203
211
 
204
212
  // src/cli/constants.ts
205
213
  var vscodeSettingsString = `
214
+ // Entry
215
+ "eslint.format.enable": true,
216
+ "eslint.ignoreUntitled": true,
217
+ "eslint.enable": true,
218
+
206
219
  // Enable the ESlint flat config support
207
220
  "eslint.experimental.useFlatConfig": true,
208
221
 
209
222
  // Disable the default formatter, use eslint instead
210
- "prettier.enable": false,
223
+ "prettier.enable": true, // for css and others...
211
224
  "editor.formatOnSave": false,
212
225
 
213
226
  // Auto fix
@@ -244,7 +257,45 @@ var vscodeSettingsString = `
244
257
  "yaml",
245
258
  "toml",
246
259
  "astro",
247
- ]
260
+ ],
261
+
262
+ // Enable eslint as the default formatter
263
+ "[javascript]": {
264
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint"
265
+ },
266
+ "[typescript]": {
267
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint"
268
+ },
269
+ "[javascriptreact]": {
270
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint"
271
+ },
272
+ "[typescriptreact]": {
273
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint"
274
+ },
275
+ "[json]": {
276
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint"
277
+ },
278
+ "[jsonc]": {
279
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint"
280
+ },
281
+ "[html]": {
282
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint"
283
+ },
284
+ "[markdown]": {
285
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint"
286
+ },
287
+ "[vue]": {
288
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint"
289
+ },
290
+ "[astro]": {
291
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint"
292
+ },
293
+ "[toml]": {
294
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint"
295
+ },
296
+ "[yaml]": {
297
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint"
298
+ }
248
299
  `;
249
300
  var frameworkOptions = [
250
301
  {
@@ -263,6 +314,10 @@ var frameworkOptions = [
263
314
  label: import_picocolors.default.magenta("Astro"),
264
315
  value: "astro"
265
316
  },
317
+ {
318
+ label: import_picocolors.default.cyan("Solid"),
319
+ value: "solid"
320
+ },
266
321
  {
267
322
  label: import_picocolors.default.blue("Slidev"),
268
323
  value: "slidev"
@@ -290,6 +345,9 @@ var dependenciesMap = {
290
345
  slidev: [
291
346
  "prettier-plugin-slidev"
292
347
  ],
348
+ solid: [
349
+ "eslint-plugin-solid"
350
+ ],
293
351
  svelte: [
294
352
  "eslint-plugin-svelte",
295
353
  "svelte-eslint-parser"
@@ -343,8 +401,9 @@ async function updatePackageJson(result) {
343
401
  "eslint-plugin-format",
344
402
  result.frameworks.includes("astro") ? "prettier-plugin-astro" : null
345
403
  ].forEach((f) => {
346
- if (!f)
404
+ if (!f) {
347
405
  return;
406
+ }
348
407
  pkg.devDependencies[f] = package_default.devDependencies[f];
349
408
  addedPackages.push(f);
350
409
  });
@@ -369,8 +428,9 @@ async function updatePackageJson(result) {
369
428
  });
370
429
  }
371
430
  }
372
- if (addedPackages.length)
431
+ if (addedPackages.length) {
373
432
  p.note(`${import_picocolors2.default.dim(addedPackages.join(", "))}`, "Added packages");
433
+ }
374
434
  await import_promises.default.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
375
435
  p.log.success(import_picocolors2.default.green(`Changes wrote to package.json`));
376
436
  }
@@ -398,21 +458,26 @@ async function updateEslintFiles(result) {
398
458
  const parsed = (0, import_parse_gitignore.default)(content);
399
459
  const globs = parsed.globs();
400
460
  for (const glob of globs) {
401
- if (glob.type === "ignore")
461
+ if (glob.type === "ignore") {
402
462
  eslintIgnores.push(...glob.patterns);
403
- else if (glob.type === "unignore")
463
+ } else if (glob.type === "unignore") {
404
464
  eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
465
+ }
405
466
  }
406
467
  }
407
468
  const configLines = [];
408
- if (eslintIgnores.length)
469
+ if (eslintIgnores.length) {
409
470
  configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
410
- if (result.extra.includes("formatter"))
471
+ }
472
+ if (result.extra.includes("formatter")) {
411
473
  configLines.push(`formatters: true,`);
412
- if (result.extra.includes("unocss"))
474
+ }
475
+ if (result.extra.includes("unocss")) {
413
476
  configLines.push(`unocss: true,`);
414
- for (const framework of result.frameworks)
477
+ }
478
+ for (const framework of result.frameworks) {
415
479
  configLines.push(`${framework}: true,`);
480
+ }
416
481
  const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
417
482
  const additionalConfig = [];
418
483
  const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
@@ -421,11 +486,13 @@ async function updateEslintFiles(result) {
421
486
  const files = import_node_fs.default.readdirSync(cwd);
422
487
  const legacyConfig = [];
423
488
  files.forEach((file) => {
424
- if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file))
489
+ if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file)) {
425
490
  legacyConfig.push(file);
491
+ }
426
492
  });
427
- if (legacyConfig.length)
493
+ if (legacyConfig.length) {
428
494
  p2.note(`${import_picocolors3.default.dim(legacyConfig.join(", "))}`, "You can now remove those files manually");
495
+ }
429
496
  }
430
497
 
431
498
  // src/cli/stages/update-vscode-settings.ts
@@ -437,12 +504,14 @@ var import_picocolors4 = __toESM(require("picocolors"), 1);
437
504
  var p3 = __toESM(require("@clack/prompts"), 1);
438
505
  async function updateVscodeSettings(result) {
439
506
  const cwd = import_node_process3.default.cwd();
440
- if (!result.updateVscodeSettings)
507
+ if (!result.updateVscodeSettings) {
441
508
  return;
509
+ }
442
510
  const dotVscodePath = import_node_path3.default.join(cwd, ".vscode");
443
511
  const settingsPath = import_node_path3.default.join(dotVscodePath, "settings.json");
444
- if (!import_node_fs2.default.existsSync(dotVscodePath))
512
+ if (!import_node_fs2.default.existsSync(dotVscodePath)) {
445
513
  await import_promises3.default.mkdir(dotVscodePath, { recursive: true });
514
+ }
446
515
  if (!import_node_fs2.default.existsSync(settingsPath)) {
447
516
  await import_promises3.default.writeFile(settingsPath, `{${vscodeSettingsString}}
448
517
  `, "utf-8");
@@ -476,8 +545,9 @@ async function run(options = {}) {
476
545
  if (!argSkipPrompt) {
477
546
  result = await p4.group({
478
547
  uncommittedConfirmed: () => {
479
- if (argSkipPrompt || isGitClean())
548
+ if (argSkipPrompt || isGitClean()) {
480
549
  return Promise.resolve(true);
550
+ }
481
551
  return p4.confirm({
482
552
  initialValue: false,
483
553
  message: "There are uncommitted changes in the current repository, are you sure to continue?"
@@ -485,8 +555,9 @@ async function run(options = {}) {
485
555
  },
486
556
  frameworks: ({ results }) => {
487
557
  const isArgTemplateValid = typeof argTemplate === "string" && !!frameworks.includes(argTemplate);
488
- if (!results.uncommittedConfirmed || isArgTemplateValid)
558
+ if (!results.uncommittedConfirmed || isArgTemplateValid) {
489
559
  return;
560
+ }
490
561
  const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
491
562
  return p4.multiselect({
492
563
  message: import_picocolors5.default.reset(message),
@@ -496,8 +567,9 @@ async function run(options = {}) {
496
567
  },
497
568
  extra: ({ results }) => {
498
569
  const isArgExtraValid = argExtra?.length && !argExtra.filter((element) => !extra.includes(element)).length;
499
- if (!results.uncommittedConfirmed || isArgExtraValid)
570
+ if (!results.uncommittedConfirmed || isArgExtraValid) {
500
571
  return;
572
+ }
501
573
  const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
502
574
  return p4.multiselect({
503
575
  message: import_picocolors5.default.reset(message),
@@ -506,8 +578,9 @@ async function run(options = {}) {
506
578
  });
507
579
  },
508
580
  updateVscodeSettings: ({ results }) => {
509
- if (!results.uncommittedConfirmed)
581
+ if (!results.uncommittedConfirmed) {
510
582
  return;
583
+ }
511
584
  return p4.confirm({
512
585
  initialValue: true,
513
586
  message: "Update .vscode/settings.json for better VS Code experience?"
@@ -519,8 +592,9 @@ async function run(options = {}) {
519
592
  import_node_process4.default.exit(0);
520
593
  }
521
594
  });
522
- if (!result.uncommittedConfirmed)
595
+ if (!result.uncommittedConfirmed) {
523
596
  return import_node_process4.default.exit(1);
597
+ }
524
598
  }
525
599
  await updatePackageJson(result);
526
600
  await updateEslintFiles(result);