@dhzh/eslint-config 2.0.1 → 2.0.3

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
@@ -2,52 +2,65 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@dhzh/eslint-config?color=444&label=)](https://www.npmjs.com/package/@dhzh/eslint-config)
4
4
 
5
- I use ESLint to format and lint my code:
5
+ An ESLint flat config preset for TypeScript-first projects with built-in support for React, Vue, JSON, YAML, TOML, Tailwind CSS, UnoCSS, and formatting rules.
6
6
 
7
- | | | |
7
+ ## Included Configs
8
+
9
+ | Config | Source | Powered by |
8
10
  |---|---|---|
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
- | [vue](./src/configs/vue.ts) | [`eslint-plugin-vue`](https://eslint.vuejs.org/) [`vue-eslint-parser`](https://www.npmjs.com/package/vue-eslint-parser) [`eslint-processor-vue-blocks`](https://github.com/antfu/eslint-processor-vue-blocks) |
11
- | [stylistic](./src/configs/stylistic.ts) | [`ESLint Stylistic`](https://eslint.style/) [`eslint-plugin-antfu`](https://github.com/antfu/eslint-plugin-antfu) |
12
- | [typescript](./src/configs/typescript.ts) | [`typescript-eslint`](https://typescript-eslint.io/) |
13
- | [javascript](./src/configs/javascript.ts) | [`@eslint/js`](https://eslint.org/docs/latest/rules) |
14
- | [node](./src/configs/node.ts) | [`eslint-plugin-n`](https://github.com/eslint-community/eslint-plugin-n) |
15
- | [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) |
16
- | [unicorn](./src/configs/unicorn.ts) | [`eslint-plugin-unicorn`](https://www.npmjs.com/package/eslint-plugin-unicorn) |
17
- | [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) |
18
- | [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 |
19
- | [tailwindcss](./src/configs/tailwindcss.ts) | [`eslint-plugin-tailwindcss`](https://github.com/francoismassart/eslint-plugin-tailwindcss) |
20
- | [unocss](./src/configs/unocss.ts) | [`@unocss/eslint-config`](https://unocss.dev/integrations/eslint) |
21
- | [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/) |
22
- | [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/) |
23
- | 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) |
24
- | [regexp](./src/configs/regexp.ts) | [`eslint-plugin-regexp`](https://ota-meshi.github.io/eslint-plugin-regexp/) |
25
- | [eslint-comments](./src/configs/eslint-comments.ts) | [`eslint-plugin-eslint-comments`](https://eslint-community.github.io/eslint-plugin-eslint-comments/) |
26
- | markdown | [`@eslint/markdown`](https://github.com/eslint/markdown) |
27
- | jsdoc | [`eslint-plugin-jsdoc`](https://github.com/gajus/eslint-plugin-jsdoc) |
28
-
29
- ## Usage
30
-
31
- > Requires ESLint v9.5.0+
32
- > This package is ESM-only.
33
-
34
- ### Starter Wizard
35
-
36
- 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.
11
+ | React | [src/configs/react.ts](./src/configs/react.ts) | [`@eslint-react/eslint-plugin`](https://www.npmjs.com/package/@eslint-react/eslint-plugin) [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks) [`eslint-plugin-react-refresh`](https://www.npmjs.com/package/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) |
12
+ | Vue | [src/configs/vue.ts](./src/configs/vue.ts) | [`@eslint/js`](https://www.npmjs.com/package/@eslint/js) [`typescript-eslint`](https://www.npmjs.com/package/typescript-eslint) [`eslint-plugin-vue`](https://www.npmjs.com/package/eslint-plugin-vue) [`eslint-merge-processors`](https://www.npmjs.com/package/eslint-merge-processors) [`eslint-processor-vue-blocks`](https://www.npmjs.com/package/eslint-processor-vue-blocks) |
13
+ | Stylistic | [src/configs/stylistic.ts](./src/configs/stylistic.ts) | [`@stylistic/eslint-plugin`](https://www.npmjs.com/package/@stylistic/eslint-plugin) [`eslint-plugin-antfu`](https://www.npmjs.com/package/eslint-plugin-antfu) |
14
+ | TypeScript | [src/configs/typescript.ts](./src/configs/typescript.ts) | [`typescript-eslint`](https://typescript-eslint.io/) |
15
+ | JavaScript | [src/configs/javascript.ts](./src/configs/javascript.ts) | [`@eslint/js`](https://www.npmjs.com/package/@eslint/js) [`eslint-plugin-antfu`](https://www.npmjs.com/package/eslint-plugin-antfu) |
16
+ | Node.js | [src/configs/node.ts](./src/configs/node.ts) | [`eslint-plugin-n`](https://github.com/eslint-community/eslint-plugin-n) |
17
+ | JSON and package.json | [src/configs/json.ts](./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) |
18
+ | Unicorn | [src/configs/unicorn.ts](./src/configs/unicorn.ts) | [`eslint-plugin-unicorn`](https://www.npmjs.com/package/eslint-plugin-unicorn) |
19
+ | Imports | [src/configs/imports.ts](./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) [`eslint-plugin-antfu`](https://github.com/antfu/eslint-plugin-antfu) |
20
+ | Format | [src/configs/format.ts](./src/configs/format.ts) | [`eslint-plugin-format`](https://www.npmjs.com/package/eslint-plugin-format) [`@prettier/plugin-xml`](https://www.npmjs.com/package/@prettier/plugin-xml) |
21
+ | Tailwind CSS | [src/configs/tailwindcss.ts](./src/configs/tailwindcss.ts) | [`eslint-plugin-tailwindcss`](https://github.com/francoismassart/eslint-plugin-tailwindcss) |
22
+ | UnoCSS | [src/configs/unocss.ts](./src/configs/unocss.ts) | [`@unocss/eslint-config`](https://unocss.dev/integrations/eslint) |
23
+ | YAML | [src/configs/yml.ts](./src/configs/yml.ts) | [`eslint-plugin-yml`](https://ota-meshi.github.io/eslint-plugin-yml/) |
24
+ | TOML | [src/configs/toml.ts](./src/configs/toml.ts) | [`eslint-plugin-toml`](https://www.npmjs.com/package/eslint-plugin-toml) [`toml-eslint-parser`](https://www.npmjs.com/package/toml-eslint-parser) |
25
+ | RegExp | [src/configs/regexp.ts](./src/configs/regexp.ts) | [`eslint-plugin-regexp`](https://ota-meshi.github.io/eslint-plugin-regexp/) |
26
+ | ESLint comments | [src/configs/eslint-comments.ts](./src/configs/eslint-comments.ts) | [`@eslint-community/eslint-plugin-eslint-comments`](https://eslint-community.github.io/eslint-plugin-eslint-comments/) |
27
+ | Testing | Planned | [`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) |
28
+ | Markdown | Planned | [`@eslint/markdown`](https://github.com/eslint/markdown) |
29
+ | JSDoc | Planned | [`eslint-plugin-jsdoc`](https://github.com/gajus/eslint-plugin-jsdoc) |
30
+ | Ignores and language options | [src/configs/ignores.ts](./src/configs/ignores.ts), [src/configs/language-options.ts](./src/configs/language-options.ts) | Built-in config composition |
31
+
32
+ ## Requirements
33
+
34
+ - Node.js `^22.13.0 || >=24`
35
+ - ESLint `^10.2.1`
36
+ - ESM-only package consumption
37
+
38
+ ## Quick Start
39
+
40
+ ### CLI Wizard
41
+
42
+ Use the CLI to create or migrate your flat config setup:
37
43
 
38
44
  ```shell
39
45
  pnpm dlx @dhzh/eslint-config@latest
40
46
  ```
41
47
 
42
- ### Manual Install
48
+ The wizard updates:
49
+
50
+ - `package.json`
51
+ - `eslint.config.*`
52
+ - `.vscode/settings.json`
53
+ - `.npmignore`
43
54
 
44
- If you prefer to set up manually:
55
+ ### Manual Setup
56
+
57
+ Install the package and ESLint:
45
58
 
46
59
  ```bash
47
60
  pnpm i -D eslint @dhzh/eslint-config
48
61
  ```
49
62
 
50
- And create `eslint.config.mjs` in your project root:
63
+ Then create `eslint.config.mjs`:
51
64
 
52
65
  ```js
53
66
  // eslint.config.mjs
@@ -56,6 +69,34 @@ import { defineConfig } from '@dhzh/eslint-config';
56
69
  export default defineConfig();
57
70
  ```
58
71
 
72
+ ## Customization
73
+
74
+ `defineConfig()` accepts `configs`, `ignorePatterns`, and `sourceType`.
75
+
76
+ ```js
77
+ // eslint.config.mjs
78
+ import { defineConfig } from '@dhzh/eslint-config';
79
+
80
+ export default defineConfig({
81
+ ignorePatterns: ['dist', 'coverage'],
82
+ configs: {
83
+ json: {
84
+ packageJsonRequireType: false,
85
+ },
86
+ yml: {
87
+ quotes: 'double',
88
+ },
89
+ imports: {
90
+ closeOrder: false,
91
+ },
92
+ },
93
+ });
94
+ ```
95
+
96
+ For the full option surface, check [src/types/index.ts](./src/types/index.ts) and the config implementations under [src/configs](./src/configs).
97
+
98
+ Rows marked as `Planned` are not wired into the current published config yet.
99
+
59
100
  ## License
60
101
 
61
102
  [MIT](./LICENSE) License © 2022 [Lyle Zheng](https://github.com/tinywaves)
@@ -6,7 +6,7 @@ import fsp from "node:fs/promises";
6
6
  import path from "node:path";
7
7
  import fs from "node:fs";
8
8
  //#region package.json
9
- var version = "2.0.1";
9
+ var version = "2.0.3";
10
10
  var devDependencies = {
11
11
  "@eslint/config-inspector": "^2.0.0",
12
12
  "@prettier/plugin-xml": "^3.4.2",
package/dist/index.mjs CHANGED
@@ -3,8 +3,10 @@ import pluginReactHooks from "eslint-plugin-react-hooks";
3
3
  import pluginReactRefresh from "eslint-plugin-react-refresh";
4
4
  import pluginReactCompiler from "eslint-plugin-react-compiler";
5
5
  import pluginReactGoogleTranslate from "eslint-plugin-react-google-translate";
6
- import { isPackageExists } from "local-pkg";
7
6
  import { defineConfig as defineConfig$1 } from "eslint/config";
7
+ import process from "node:process";
8
+ import { getPackagesSync } from "@manypkg/get-packages";
9
+ import { isPackageExists } from "local-pkg";
8
10
  import js from "@eslint/js";
9
11
  import tseslint from "typescript-eslint";
10
12
  import pluginVue from "eslint-plugin-vue";
@@ -13,7 +15,6 @@ import { mergeProcessors } from "eslint-merge-processors";
13
15
  import processorVueBlocks from "eslint-processor-vue-blocks";
14
16
  import pluginStylistic from "@stylistic/eslint-plugin";
15
17
  import pluginAntfu from "eslint-plugin-antfu";
16
- import process from "node:process";
17
18
  import pluginNode from "eslint-plugin-n";
18
19
  import pluginJsonc from "eslint-plugin-jsonc";
19
20
  import pluginPackageJson from "eslint-plugin-package-json";
@@ -147,6 +148,14 @@ const mergeRule = (...rules) => {
147
148
  if (Object.keys(finalOptions).length === 0) return finalLevel;
148
149
  return [finalLevel, finalOptions];
149
150
  };
151
+ function isPackageAvailable(name, cwd = process.cwd()) {
152
+ if (isPackageExists(name, { paths: [cwd] })) return true;
153
+ try {
154
+ return getPackagesSync(cwd).packages.some((pkg) => name in (pkg.packageJson.dependencies || {}) || name in (pkg.packageJson.devDependencies || {}) || name in (pkg.packageJson.peerDependencies || {}) || name in (pkg.packageJson.optionalDependencies || {}));
155
+ } catch {
156
+ return false;
157
+ }
158
+ }
150
159
  //#endregion
151
160
  //#region src/configs/react.ts
152
161
  const ReactRefreshAllowConstantExportPackages = ["vite"];
@@ -173,11 +182,11 @@ function react(options = {}) {
173
182
  googleTranslate: {}
174
183
  } } = options;
175
184
  const config = language === "typescript" ? pluginReact.configs["recommended-type-checked"] : pluginReact.configs.recommended;
176
- const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((i) => isPackageExists(i));
177
- const isUsingRemix = RemixPackages.some((i) => isPackageExists(i));
178
- const isUsingReactRouter = ReactRouterPackages.some((i) => isPackageExists(i));
179
- const isUsingNext = NextJsPackages.some((i) => isPackageExists(i));
180
- const isUsingExpo = ExpoPackages.some((i) => isPackageExists(i));
185
+ const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((i) => isPackageAvailable(i));
186
+ const isUsingRemix = RemixPackages.some((i) => isPackageAvailable(i));
187
+ const isUsingReactRouter = ReactRouterPackages.some((i) => isPackageAvailable(i));
188
+ const isUsingNext = NextJsPackages.some((i) => isPackageAvailable(i));
189
+ const isUsingExpo = ExpoPackages.some((i) => isPackageAvailable(i));
181
190
  return [
182
191
  {
183
192
  ...config,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dhzh/eslint-config",
3
3
  "type": "module",
4
- "version": "2.0.1",
4
+ "version": "2.0.3",
5
5
  "description": "tinywaves's ESLint config",
6
6
  "author": {
7
7
  "name": "Lyle Zheng",
@@ -52,6 +52,7 @@
52
52
  "@eslint-community/eslint-plugin-eslint-comments": "^4.7.1",
53
53
  "@eslint-react/eslint-plugin": "^4.2.3",
54
54
  "@eslint/js": "^10.0.1",
55
+ "@manypkg/get-packages": "^3.1.0",
55
56
  "@stylistic/eslint-plugin": "^5.10.0",
56
57
  "@unocss/eslint-config": "66.6.8",
57
58
  "ansis": "^4.2.0",