hkx-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
@@ -8,55 +8,66 @@ HKX 代码规范,基于 ESLint 9 Flat Config。
8
8
  pnpm add -D eslint hkx-eslint-config
9
9
  ```
10
10
 
11
- 要求 **ESLint ^9.32.0**(peerDependency)。
11
+ - **ESLint**:^9.32.0peerDependency
12
+ - **TypeScript 配置**(`standard-ts` / `node-ts` / `react-ts` / `vue-ts`):需在项目中安装 `typescript`,且 type-aware 规则依赖 `tsconfig.json`
12
13
 
13
- ## 用法
14
+ ## 两种用法
14
15
 
15
- 在项目根目录新建 `eslint.config.js`(或 `eslint.config.mjs` / `eslint.config.ts`),按项目类型选用对应 config 并展开:
16
+ ### 1. 使用 config(开箱即用)
17
+
18
+ 直接使用预设配置,已包含解析器、extends、语言选项等:
16
19
 
17
20
  ```js
18
21
  import { defineConfig } from 'eslint/config';
19
- import hkx from 'hkx-eslint-config';
22
+ import nodeTs from 'hkx-eslint-config/node-ts';
20
23
 
21
24
  export default defineConfig([
22
- ...hkx.configs.ts, // 按需换成 js / node / react / vue / vueTs / reactTs / nodeTs
23
- {
24
- ignores: ['**/node_modules/**', '**/dist/**'],
25
- },
25
+ ...nodeTs,
26
+ { ignores: ['**/node_modules/**', '**/dist/**'] },
26
27
  ]);
27
28
  ```
28
29
 
29
- ### 可选配置
30
+ | 子路径 | 说明 |
31
+ |--------|------|
32
+ | `hkx-eslint-config/standard` | 纯 JavaScript |
33
+ | `hkx-eslint-config/standard-ts` | TypeScript |
34
+ | `hkx-eslint-config/node` | Node.js (JS) |
35
+ | `hkx-eslint-config/node-ts` | Node.js (TS) |
36
+ | `hkx-eslint-config/react` | React (JS) |
37
+ | `hkx-eslint-config/react-ts` | React (TS) |
38
+ | `hkx-eslint-config/vue` | Vue (JS) |
39
+ | `hkx-eslint-config/vue-ts` | Vue (TS) |
30
40
 
31
- | 名称 | 说明 |
32
- |----------|----------------|
33
- | `js` | 纯 JavaScript |
34
- | `ts` | TypeScript |
35
- | `node` | Node.js (JS) |
36
- | `nodeTs` | Node.js (TS) |
37
- | `react` | React (JS) |
38
- | `reactTs`| React (TS) |
39
- | `vue` | Vue (JS) |
40
- | `vueTs` | Vue (TS) |
41
+ ### 2. 仅使用规则,自配解析器等
41
42
 
42
- 多种场景可组合多段 config(如先 `...hkx.configs.ts` `...hkx.configs.vueTs`),或按 `files` 在各自 config 里区分。
43
-
44
- ## 以插件形式使用
45
-
46
- 可挂载自带的 plugin,通过 `extends` 使用内置规则(plugin 提供 `js` / `ts` / `node` / `react` / `vue`):
43
+ 只引入规则集(`Linter.Config`),自行配置 parser、languageOptions、plugins 等:
47
44
 
48
45
  ```js
49
46
  import { defineConfig } from 'eslint/config';
50
- import hkx from 'hkx-eslint-config';
47
+ import recommendedTypescript from 'hkx-eslint-config/rules/recommended-typescript';
48
+ import node from 'hkx-eslint-config/rules/node';
49
+ import tseslint from 'typescript-eslint';
50
+ import globals from 'globals';
51
51
 
52
52
  export default defineConfig([
53
53
  {
54
- plugins: {
55
- hkx: hkx.plugin,
54
+ files: ['**/*.ts'],
55
+ extends: [recommendedTypescript, node],
56
+ languageOptions: {
57
+ parser: tseslint.parser,
58
+ parserOptions: { projectService: true },
59
+ globals: { ...globals.node },
56
60
  },
57
- extends: ['hkx/ts'],
58
61
  },
59
62
  ]);
60
63
  ```
61
64
 
62
- 推荐直接展开 `hkx.configs.xxx`,按需组合、可配合 `files` `ignores`。
65
+ | 子路径 | 说明 |
66
+ |--------|------|
67
+ | `hkx-eslint-config/rules/recommended-javascript` | JS 基础规则集 |
68
+ | `hkx-eslint-config/rules/recommended-typescript` | TS 基础规则集 |
69
+ | `hkx-eslint-config/rules/node` | Node 规则集 |
70
+ | `hkx-eslint-config/rules/react` | React 规则集 |
71
+ | `hkx-eslint-config/rules/vue` | Vue 规则集 |
72
+
73
+ 可任意组合 rules,再自行设置 parser、globals、plugins 等。
@@ -0,0 +1,4 @@
1
+ //#region config/node-js.d.ts
2
+ declare const config: any;
3
+ //#endregion
4
+ export { config as default };
@@ -0,0 +1,14 @@
1
+ import "../import.js";
2
+ import config$1 from "../rules/recommended-javascript.js";
3
+ import { t as config$2 } from "../node.js";
4
+ import globals from "globals";
5
+
6
+ //#region config/node-js.ts
7
+ const config = [{
8
+ files: ["**/*.js"],
9
+ extends: [config$1, config$2],
10
+ languageOptions: { globals: { ...globals.node } }
11
+ }];
12
+
13
+ //#endregion
14
+ export { config as default };
@@ -0,0 +1,4 @@
1
+ //#region config/node-ts.d.ts
2
+ declare const config: any;
3
+ //#endregion
4
+ export { config as default };
@@ -0,0 +1,19 @@
1
+ import "../import.js";
2
+ import { t as config$1 } from "../node.js";
3
+ import { t as config$2 } from "../recommended-typescript.js";
4
+ import globals from "globals";
5
+ import tseslint from "typescript-eslint";
6
+
7
+ //#region config/node-ts.ts
8
+ const config = [{
9
+ files: ["**/*.ts"],
10
+ extends: [config$2, config$1],
11
+ languageOptions: {
12
+ parser: tseslint.parser,
13
+ parserOptions: { projectService: true },
14
+ globals: { ...globals.node }
15
+ }
16
+ }];
17
+
18
+ //#endregion
19
+ export { config as default };
@@ -0,0 +1,4 @@
1
+ //#region config/react-js.d.ts
2
+ declare const config: any;
3
+ //#endregion
4
+ export { config as default };
@@ -0,0 +1,17 @@
1
+ import "../import.js";
2
+ import config$1 from "../rules/recommended-javascript.js";
3
+ import { t as config$2 } from "../react.js";
4
+ import globals from "globals";
5
+
6
+ //#region config/react-js.ts
7
+ const config = [{
8
+ files: ["**/*.js", "**/*.jsx"],
9
+ extends: [config$1, config$2],
10
+ languageOptions: {
11
+ parserOptions: { ecmaFeatures: { jsx: true } },
12
+ globals: { ...globals.browser }
13
+ }
14
+ }];
15
+
16
+ //#endregion
17
+ export { config as default };
@@ -0,0 +1,4 @@
1
+ //#region config/react-ts.d.ts
2
+ declare const config: any;
3
+ //#endregion
4
+ export { config as default };
@@ -0,0 +1,19 @@
1
+ import "../import.js";
2
+ import { t as config$1 } from "../recommended-typescript.js";
3
+ import { t as config$2 } from "../react.js";
4
+ import globals from "globals";
5
+ import tseslint from "typescript-eslint";
6
+
7
+ //#region config/react-ts.ts
8
+ const config = [{
9
+ files: ["**/*.ts", "**/*.tsx"],
10
+ extends: [config$1, config$2],
11
+ languageOptions: {
12
+ parser: tseslint.parser,
13
+ parserOptions: { projectService: true },
14
+ globals: { ...globals.browser }
15
+ }
16
+ }];
17
+
18
+ //#endregion
19
+ export { config as default };
@@ -0,0 +1,4 @@
1
+ //#region config/standard-js.d.ts
2
+ declare const config: any;
3
+ //#endregion
4
+ export { config as default };
@@ -0,0 +1,11 @@
1
+ import "../import.js";
2
+ import config$1 from "../rules/recommended-javascript.js";
3
+
4
+ //#region config/standard-js.ts
5
+ const config = [{
6
+ files: ["**/*.js"],
7
+ extends: [config$1]
8
+ }];
9
+
10
+ //#endregion
11
+ export { config as default };
@@ -0,0 +1,4 @@
1
+ //#region config/standard-ts.d.ts
2
+ declare const config: any;
3
+ //#endregion
4
+ export { config as default };
@@ -0,0 +1,16 @@
1
+ import "../import.js";
2
+ import { t as config$1 } from "../recommended-typescript.js";
3
+ import tseslint from "typescript-eslint";
4
+
5
+ //#region config/standard-ts.ts
6
+ const config = [{
7
+ files: ["**/*.ts"],
8
+ extends: [config$1],
9
+ languageOptions: {
10
+ parser: tseslint.parser,
11
+ parserOptions: { projectService: true }
12
+ }
13
+ }];
14
+
15
+ //#endregion
16
+ export { config as default };
@@ -0,0 +1,4 @@
1
+ //#region config/vue-js.d.ts
2
+ declare const config: any;
3
+ //#endregion
4
+ export { config as default };
@@ -0,0 +1,34 @@
1
+ import "../import.js";
2
+ import config$1 from "../rules/recommended-javascript.js";
3
+ import { t as config$2 } from "../vue.js";
4
+ import globals from "globals";
5
+ import pluginVue from "eslint-plugin-vue";
6
+ import vueParser from "vue-eslint-parser";
7
+
8
+ //#region config/vue-js.ts
9
+ const config = [{
10
+ files: ["**/*.js", "**/*.jsx"],
11
+ extends: [config$1],
12
+ languageOptions: {
13
+ parserOptions: { ecmaFeatures: { jsx: true } },
14
+ globals: { ...globals.browser }
15
+ }
16
+ }, {
17
+ files: ["**/*.vue"],
18
+ extends: [config$1, config$2],
19
+ plugins: { get vue() {
20
+ return pluginVue;
21
+ } },
22
+ languageOptions: {
23
+ parser: vueParser,
24
+ parserOptions: {
25
+ extraFileExtensions: [".vue", ".jsx"],
26
+ ecmaFeatures: { jsx: true }
27
+ },
28
+ globals: { ...globals.browser }
29
+ },
30
+ processor: "vue/vue"
31
+ }];
32
+
33
+ //#endregion
34
+ export { config as default };
@@ -0,0 +1,4 @@
1
+ //#region config/vue-ts.d.ts
2
+ declare const config: any;
3
+ //#endregion
4
+ export { config as default };
@@ -0,0 +1,44 @@
1
+ import "../import.js";
2
+ import { t as config$1 } from "../recommended-typescript.js";
3
+ import { t as config$2 } from "../vue.js";
4
+ import globals from "globals";
5
+ import tseslint from "typescript-eslint";
6
+ import pluginVue from "eslint-plugin-vue";
7
+ import vueParser from "vue-eslint-parser";
8
+
9
+ //#region config/vue-ts.ts
10
+ const config = [{
11
+ files: ["**/*.ts", "**/*.tsx"],
12
+ extends: [config$1],
13
+ languageOptions: {
14
+ parser: tseslint.parser,
15
+ parserOptions: {
16
+ projectService: true,
17
+ ecmaFeatures: { jsx: true }
18
+ },
19
+ globals: { ...globals.browser }
20
+ }
21
+ }, {
22
+ files: ["**/*.vue"],
23
+ extends: [config$1, config$2],
24
+ plugins: { get vue() {
25
+ return pluginVue;
26
+ } },
27
+ languageOptions: {
28
+ parser: vueParser,
29
+ parserOptions: {
30
+ parser: tseslint.parser,
31
+ extraFileExtensions: [".vue", ".tsx"],
32
+ ecmaFeatures: { jsx: true }
33
+ },
34
+ globals: { ...globals.browser }
35
+ },
36
+ processor: "vue/vue",
37
+ rules: {
38
+ "@typescript-eslint/restrict-plus-operands": "off",
39
+ "@typescript-eslint/dot-notation": "off"
40
+ }
41
+ }];
42
+
43
+ //#endregion
44
+ export { config as default };