@hestjs/eslint-config 0.1.0
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 +163 -0
- package/base.config.ts +46 -0
- package/dist/base.config.d.ts +5 -0
- package/dist/base.config.js +48 -0
- package/dist/eslint.config.d.ts +8 -0
- package/dist/eslint.config.js +97 -0
- package/dist/react.config.d.ts +5 -0
- package/dist/react.config.js +83 -0
- package/dist/vue.config.d.ts +5 -0
- package/dist/vue.config.js +88 -0
- package/eslint.config.ts +95 -0
- package/package.json +97 -0
- package/react.config.ts +82 -0
- package/tsup.config.ts +31 -0
- package/vue.config.ts +87 -0
package/README.md
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
# @eve-tools/eslint-config
|
2
|
+
|
3
|
+
ESLint 配置包,为 Eve Framework 项目提供统一的代码风格和质量检查。
|
4
|
+
|
5
|
+
## 特性
|
6
|
+
|
7
|
+
- 🎯 现代 ESLint 平坦配置格式
|
8
|
+
- 🔧 TypeScript 优先
|
9
|
+
- ⚛️ React 支持
|
10
|
+
- 💚 Vue 支持
|
11
|
+
- 📦 零配置,开箱即用
|
12
|
+
- 🚀 基于最新的 ESLint 和 TypeScript 规则
|
13
|
+
|
14
|
+
## 安装
|
15
|
+
|
16
|
+
```bash
|
17
|
+
bun add -D @eve-tools/eslint-config eslint typescript
|
18
|
+
```
|
19
|
+
|
20
|
+
## 使用方法
|
21
|
+
|
22
|
+
### 基础配置
|
23
|
+
|
24
|
+
在项目根目录创建 `eslint.config.ts`:
|
25
|
+
|
26
|
+
```typescript
|
27
|
+
// eslint.config.ts
|
28
|
+
import eveConfig from '@eve-tools/eslint-config';
|
29
|
+
|
30
|
+
export default eveConfig;
|
31
|
+
```
|
32
|
+
|
33
|
+
### TypeScript 项目
|
34
|
+
|
35
|
+
```typescript
|
36
|
+
// eslint.config.ts
|
37
|
+
import baseConfig from '@eve-tools/eslint-config/base';
|
38
|
+
|
39
|
+
export default baseConfig;
|
40
|
+
```
|
41
|
+
|
42
|
+
### React 项目
|
43
|
+
|
44
|
+
```typescript
|
45
|
+
// eslint.config.ts
|
46
|
+
import reactConfig from '@eve-tools/eslint-config/react';
|
47
|
+
|
48
|
+
export default reactConfig;
|
49
|
+
```
|
50
|
+
|
51
|
+
### Vue 项目
|
52
|
+
|
53
|
+
```typescript
|
54
|
+
// eslint.config.ts
|
55
|
+
import vueConfig from '@eve-tools/eslint-config/vue';
|
56
|
+
|
57
|
+
export default vueConfig;
|
58
|
+
```
|
59
|
+
|
60
|
+
### 自定义配置
|
61
|
+
|
62
|
+
```typescript
|
63
|
+
// eslint.config.ts
|
64
|
+
import eveConfig from '@eve-tools/eslint-config';
|
65
|
+
|
66
|
+
export default [
|
67
|
+
...eveConfig,
|
68
|
+
{
|
69
|
+
// 你的自定义规则
|
70
|
+
rules: {
|
71
|
+
'no-console': 'off',
|
72
|
+
},
|
73
|
+
},
|
74
|
+
];
|
75
|
+
```
|
76
|
+
|
77
|
+
### 直接使用 TypeScript 源文件(推荐用于开发环境)
|
78
|
+
|
79
|
+
如果你想直接使用 TypeScript 源文件获得更好的开发体验:
|
80
|
+
|
81
|
+
```typescript
|
82
|
+
// eslint.config.ts
|
83
|
+
import eveConfig from '@eve-tools/eslint-config/source';
|
84
|
+
|
85
|
+
export default eveConfig;
|
86
|
+
```
|
87
|
+
|
88
|
+
或者:
|
89
|
+
|
90
|
+
```typescript
|
91
|
+
// eslint.config.ts
|
92
|
+
import reactConfig from '@eve-tools/eslint-config/react/source';
|
93
|
+
|
94
|
+
export default reactConfig;
|
95
|
+
```
|
96
|
+
|
97
|
+
### 如果环境不支持 TypeScript 配置
|
98
|
+
|
99
|
+
```javascript
|
100
|
+
// eslint.config.js (降级方案)
|
101
|
+
import eveConfig from '@eve-tools/eslint-config';
|
102
|
+
|
103
|
+
export default eveConfig;
|
104
|
+
```
|
105
|
+
|
106
|
+
## 包含的规则
|
107
|
+
|
108
|
+
### 基础规则
|
109
|
+
- 强制使用单引号
|
110
|
+
- 要求分号
|
111
|
+
- 禁止多个空行
|
112
|
+
- 强制使用 === 而不是 ==
|
113
|
+
- 更多代码风格规则...
|
114
|
+
|
115
|
+
### TypeScript 规则
|
116
|
+
- 优先使用类型导入
|
117
|
+
- 禁止使用 any 类型(警告)
|
118
|
+
- 强制使用可选链操作符
|
119
|
+
- 强制使用空值合并操作符
|
120
|
+
- 更多 TypeScript 最佳实践...
|
121
|
+
|
122
|
+
### React 规则
|
123
|
+
- React Hooks 规则
|
124
|
+
- React Refresh 规则
|
125
|
+
- JSX 最佳实践
|
126
|
+
|
127
|
+
### Vue 规则
|
128
|
+
- Vue 3 推荐规则
|
129
|
+
- 组件命名规范
|
130
|
+
- 模板语法检查
|
131
|
+
|
132
|
+
## 脚本配置
|
133
|
+
|
134
|
+
在 `package.json` 中添加:
|
135
|
+
|
136
|
+
```json
|
137
|
+
{
|
138
|
+
"scripts": {
|
139
|
+
"lint": "eslint . --config eslint.config.ts",
|
140
|
+
"lint:fix": "eslint . --config eslint.config.ts --fix"
|
141
|
+
}
|
142
|
+
}
|
143
|
+
```
|
144
|
+
|
145
|
+
## VS Code 配置
|
146
|
+
|
147
|
+
在 `.vscode/settings.json` 中添加:
|
148
|
+
|
149
|
+
```json
|
150
|
+
{
|
151
|
+
"eslint.experimental.useFlatConfig": true,
|
152
|
+
"eslint.options": {
|
153
|
+
"overrideConfigFile": "eslint.config.ts"
|
154
|
+
},
|
155
|
+
"editor.codeActionsOnSave": {
|
156
|
+
"source.fixAll.eslint": true
|
157
|
+
}
|
158
|
+
}
|
159
|
+
```
|
160
|
+
|
161
|
+
## 许可证
|
162
|
+
|
163
|
+
MIT
|
package/base.config.ts
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
import * as js from '@eslint/js';
|
2
|
+
import tseslint from 'typescript-eslint';
|
3
|
+
|
4
|
+
export default tseslint.config(
|
5
|
+
js.configs.recommended,
|
6
|
+
...tseslint.configs.recommended,
|
7
|
+
{
|
8
|
+
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
|
9
|
+
rules: {
|
10
|
+
// 基础规则
|
11
|
+
'no-console': 'warn',
|
12
|
+
'no-unused-vars': 'off',
|
13
|
+
'prefer-const': 'error',
|
14
|
+
'no-var': 'error',
|
15
|
+
eqeqeq: ['error', 'always'],
|
16
|
+
curly: ['error', 'all'],
|
17
|
+
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1 }],
|
18
|
+
'no-trailing-spaces': 'error',
|
19
|
+
'comma-dangle': ['error', 'always-multiline'],
|
20
|
+
quotes: ['error', 'single', { avoidEscape: true }],
|
21
|
+
semi: ['error', 'always'],
|
22
|
+
'object-curly-spacing': ['error', 'always'],
|
23
|
+
'array-bracket-spacing': ['error', 'never'],
|
24
|
+
'space-before-blocks': 'error',
|
25
|
+
'keyword-spacing': 'error',
|
26
|
+
|
27
|
+
// TypeScript 规则(如果适用)
|
28
|
+
'@typescript-eslint/no-unused-vars': [
|
29
|
+
'error',
|
30
|
+
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
|
31
|
+
],
|
32
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
33
|
+
'@typescript-eslint/consistent-type-imports': 'off',
|
34
|
+
},
|
35
|
+
},
|
36
|
+
{
|
37
|
+
ignores: [
|
38
|
+
'node_modules/**',
|
39
|
+
'dist/**',
|
40
|
+
'build/**',
|
41
|
+
'*.d.ts',
|
42
|
+
'.bun/**',
|
43
|
+
'bun.lockb',
|
44
|
+
],
|
45
|
+
},
|
46
|
+
);
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import * as js from '@eslint/js';
|
2
|
+
import tseslint from 'typescript-eslint';
|
3
|
+
|
4
|
+
// base.config.ts
|
5
|
+
var base_config_default = tseslint.config(
|
6
|
+
js.configs.recommended,
|
7
|
+
...tseslint.configs.recommended,
|
8
|
+
{
|
9
|
+
files: ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"],
|
10
|
+
rules: {
|
11
|
+
// 基础规则
|
12
|
+
"no-console": "warn",
|
13
|
+
"no-unused-vars": "off",
|
14
|
+
"prefer-const": "error",
|
15
|
+
"no-var": "error",
|
16
|
+
eqeqeq: ["error", "always"],
|
17
|
+
curly: ["error", "all"],
|
18
|
+
"no-multiple-empty-lines": ["error", { max: 2, maxEOF: 1 }],
|
19
|
+
"no-trailing-spaces": "error",
|
20
|
+
"comma-dangle": ["error", "always-multiline"],
|
21
|
+
quotes: ["error", "single", { avoidEscape: true }],
|
22
|
+
semi: ["error", "always"],
|
23
|
+
"object-curly-spacing": ["error", "always"],
|
24
|
+
"array-bracket-spacing": ["error", "never"],
|
25
|
+
"space-before-blocks": "error",
|
26
|
+
"keyword-spacing": "error",
|
27
|
+
// TypeScript 规则(如果适用)
|
28
|
+
"@typescript-eslint/no-unused-vars": [
|
29
|
+
"error",
|
30
|
+
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" }
|
31
|
+
],
|
32
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
33
|
+
"@typescript-eslint/consistent-type-imports": "off"
|
34
|
+
}
|
35
|
+
},
|
36
|
+
{
|
37
|
+
ignores: [
|
38
|
+
"node_modules/**",
|
39
|
+
"dist/**",
|
40
|
+
"build/**",
|
41
|
+
"*.d.ts",
|
42
|
+
".bun/**",
|
43
|
+
"bun.lockb"
|
44
|
+
]
|
45
|
+
}
|
46
|
+
);
|
47
|
+
|
48
|
+
export { base_config_default as default };
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
2
|
+
|
3
|
+
declare function createConfig(options?: {
|
4
|
+
tsconfigRootDir?: string;
|
5
|
+
}): _typescript_eslint_utils_ts_eslint.FlatConfig.ConfigArray;
|
6
|
+
declare const _default: _typescript_eslint_utils_ts_eslint.FlatConfig.ConfigArray;
|
7
|
+
|
8
|
+
export { createConfig, _default as default };
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import * as js from '@eslint/js';
|
2
|
+
import tseslint from 'typescript-eslint';
|
3
|
+
|
4
|
+
// eslint.config.ts
|
5
|
+
function createConfig(options = {}) {
|
6
|
+
return tseslint.config(
|
7
|
+
js.configs.recommended,
|
8
|
+
...tseslint.configs.recommended,
|
9
|
+
...tseslint.configs.strict,
|
10
|
+
{
|
11
|
+
files: ["**/*.ts", "**/*.tsx"],
|
12
|
+
languageOptions: {
|
13
|
+
parserOptions: {
|
14
|
+
// 如果提供了 tsconfigRootDir,则使用它
|
15
|
+
...options.tsconfigRootDir && {
|
16
|
+
tsconfigRootDir: options.tsconfigRootDir
|
17
|
+
}
|
18
|
+
}
|
19
|
+
},
|
20
|
+
rules: {
|
21
|
+
// 基础规则
|
22
|
+
"no-console": "warn",
|
23
|
+
"no-unused-vars": "off",
|
24
|
+
// 关闭基础规则,使用 TypeScript 版本
|
25
|
+
"prefer-const": "error",
|
26
|
+
"no-var": "error",
|
27
|
+
eqeqeq: ["error", "always"],
|
28
|
+
curly: ["error", "all"],
|
29
|
+
"no-multiple-empty-lines": ["error", { max: 2, maxEOF: 1 }],
|
30
|
+
"no-trailing-spaces": "error",
|
31
|
+
"comma-dangle": ["error", "always-multiline"],
|
32
|
+
quotes: ["error", "single", { avoidEscape: true }],
|
33
|
+
semi: ["error", "always"],
|
34
|
+
"object-curly-spacing": ["error", "always"],
|
35
|
+
"array-bracket-spacing": ["error", "never"],
|
36
|
+
"space-before-blocks": "error",
|
37
|
+
"keyword-spacing": "error",
|
38
|
+
// TypeScript 特定规则
|
39
|
+
"@typescript-eslint/no-unused-vars": [
|
40
|
+
"error",
|
41
|
+
{
|
42
|
+
argsIgnorePattern: "^_",
|
43
|
+
varsIgnorePattern: "^_",
|
44
|
+
caughtErrorsIgnorePattern: "^_"
|
45
|
+
}
|
46
|
+
],
|
47
|
+
"@typescript-eslint/no-extraneous-class": "off",
|
48
|
+
// 允许类中有非方法成员
|
49
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
50
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
51
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
52
|
+
"@typescript-eslint/no-import-type-side-effects": "error",
|
53
|
+
"@typescript-eslint/array-type": ["error", { default: "array" }],
|
54
|
+
"@typescript-eslint/consistent-type-definitions": [
|
55
|
+
"error",
|
56
|
+
"interface"
|
57
|
+
],
|
58
|
+
"@typescript-eslint/method-signature-style": ["error", "property"],
|
59
|
+
"@typescript-eslint/prefer-function-type": "error",
|
60
|
+
"@typescript-eslint/ban-ts-comment": [
|
61
|
+
"error",
|
62
|
+
{
|
63
|
+
"ts-expect-error": "allow-with-description",
|
64
|
+
"ts-ignore": "allow-with-description",
|
65
|
+
"ts-nocheck": "allow-with-description",
|
66
|
+
"ts-check": false
|
67
|
+
}
|
68
|
+
]
|
69
|
+
}
|
70
|
+
},
|
71
|
+
{
|
72
|
+
files: ["**/*.js", "**/*.mjs"],
|
73
|
+
...tseslint.configs.disableTypeChecked
|
74
|
+
},
|
75
|
+
{
|
76
|
+
// Logger 和演示文件的特殊配置 - 允许使用 console
|
77
|
+
files: ["**/logger.ts", "**/logger-demo.ts", "**/node-types-demo.ts"],
|
78
|
+
rules: {
|
79
|
+
"no-console": "off"
|
80
|
+
// 演示文件中允许使用 console
|
81
|
+
}
|
82
|
+
},
|
83
|
+
{
|
84
|
+
ignores: [
|
85
|
+
"node_modules/**",
|
86
|
+
"dist/**",
|
87
|
+
"build/**",
|
88
|
+
"*.d.ts",
|
89
|
+
".bun/**",
|
90
|
+
"bun.lockb"
|
91
|
+
]
|
92
|
+
}
|
93
|
+
);
|
94
|
+
}
|
95
|
+
var eslint_config_default = createConfig({ tsconfigRootDir: __dirname });
|
96
|
+
|
97
|
+
export { createConfig, eslint_config_default as default };
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import * as js from '@eslint/js';
|
2
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
3
|
+
import reactRefresh from 'eslint-plugin-react-refresh';
|
4
|
+
import tseslint from 'typescript-eslint';
|
5
|
+
|
6
|
+
// react.config.ts
|
7
|
+
var react_config_default = tseslint.config(
|
8
|
+
js.configs.recommended,
|
9
|
+
...tseslint.configs.recommended,
|
10
|
+
...tseslint.configs.strict,
|
11
|
+
{
|
12
|
+
files: ["**/*.ts", "**/*.tsx"],
|
13
|
+
languageOptions: {
|
14
|
+
parser: tseslint.parser,
|
15
|
+
parserOptions: {
|
16
|
+
project: "./tsconfig.json",
|
17
|
+
tsconfigRootDir: import.meta.dirname,
|
18
|
+
ecmaFeatures: {
|
19
|
+
jsx: true
|
20
|
+
}
|
21
|
+
}
|
22
|
+
},
|
23
|
+
plugins: {
|
24
|
+
"react-hooks": reactHooks,
|
25
|
+
"react-refresh": reactRefresh
|
26
|
+
},
|
27
|
+
rules: {
|
28
|
+
// 基础规则
|
29
|
+
"no-console": "warn",
|
30
|
+
"no-unused-vars": "off",
|
31
|
+
"prefer-const": "error",
|
32
|
+
"no-var": "error",
|
33
|
+
eqeqeq: ["error", "always"],
|
34
|
+
curly: ["error", "all"],
|
35
|
+
"no-multiple-empty-lines": ["error", { max: 2, maxEOF: 1 }],
|
36
|
+
"no-trailing-spaces": "error",
|
37
|
+
"comma-dangle": ["error", "always-multiline"],
|
38
|
+
quotes: ["error", "single", { avoidEscape: true }],
|
39
|
+
semi: ["error", "always"],
|
40
|
+
"object-curly-spacing": ["error", "always"],
|
41
|
+
"array-bracket-spacing": ["error", "never"],
|
42
|
+
"space-before-blocks": "error",
|
43
|
+
"keyword-spacing": "error",
|
44
|
+
// TypeScript 规则
|
45
|
+
"@typescript-eslint/no-unused-vars": [
|
46
|
+
"error",
|
47
|
+
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" }
|
48
|
+
],
|
49
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
50
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
51
|
+
"@typescript-eslint/prefer-nullish-coalescing": "error",
|
52
|
+
"@typescript-eslint/prefer-optional-chain": "error",
|
53
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
54
|
+
"@typescript-eslint/consistent-type-imports": [
|
55
|
+
"error",
|
56
|
+
{ prefer: "type-imports" }
|
57
|
+
],
|
58
|
+
"@typescript-eslint/no-import-type-side-effects": "error",
|
59
|
+
// React 规则
|
60
|
+
...reactHooks.configs.recommended.rules,
|
61
|
+
"react-refresh/only-export-components": [
|
62
|
+
"warn",
|
63
|
+
{ allowConstantExport: true }
|
64
|
+
]
|
65
|
+
}
|
66
|
+
},
|
67
|
+
{
|
68
|
+
files: ["**/*.js", "**/*.mjs"],
|
69
|
+
...tseslint.configs.disableTypeChecked
|
70
|
+
},
|
71
|
+
{
|
72
|
+
ignores: [
|
73
|
+
"node_modules/**",
|
74
|
+
"dist/**",
|
75
|
+
"build/**",
|
76
|
+
"*.d.ts",
|
77
|
+
".bun/**",
|
78
|
+
"bun.lockb"
|
79
|
+
]
|
80
|
+
}
|
81
|
+
);
|
82
|
+
|
83
|
+
export { react_config_default as default };
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import * as js from '@eslint/js';
|
2
|
+
import pluginVue from 'eslint-plugin-vue';
|
3
|
+
import tseslint from 'typescript-eslint';
|
4
|
+
|
5
|
+
// vue.config.ts
|
6
|
+
var vue_config_default = tseslint.config(
|
7
|
+
js.configs.recommended,
|
8
|
+
...tseslint.configs.recommended,
|
9
|
+
...tseslint.configs.strict,
|
10
|
+
...pluginVue.configs["flat/recommended"],
|
11
|
+
{
|
12
|
+
files: ["**/*.ts", "**/*.tsx", "**/*.vue"],
|
13
|
+
languageOptions: {
|
14
|
+
parser: tseslint.parser,
|
15
|
+
parserOptions: {
|
16
|
+
project: "./tsconfig.json",
|
17
|
+
tsconfigRootDir: import.meta.dirname,
|
18
|
+
parser: "@typescript-eslint/parser",
|
19
|
+
extraFileExtensions: [".vue"]
|
20
|
+
}
|
21
|
+
},
|
22
|
+
rules: {
|
23
|
+
// 基础规则
|
24
|
+
"no-console": "warn",
|
25
|
+
"no-unused-vars": "off",
|
26
|
+
"prefer-const": "error",
|
27
|
+
"no-var": "error",
|
28
|
+
eqeqeq: ["error", "always"],
|
29
|
+
curly: ["error", "all"],
|
30
|
+
"no-multiple-empty-lines": ["error", { max: 2, maxEOF: 1 }],
|
31
|
+
"no-trailing-spaces": "error",
|
32
|
+
"comma-dangle": ["error", "always-multiline"],
|
33
|
+
quotes: ["error", "single", { avoidEscape: true }],
|
34
|
+
semi: ["error", "always"],
|
35
|
+
"object-curly-spacing": ["error", "always"],
|
36
|
+
"array-bracket-spacing": ["error", "never"],
|
37
|
+
"space-before-blocks": "error",
|
38
|
+
"keyword-spacing": "error",
|
39
|
+
// TypeScript 规则
|
40
|
+
"@typescript-eslint/no-unused-vars": [
|
41
|
+
"error",
|
42
|
+
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" }
|
43
|
+
],
|
44
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
45
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
46
|
+
"@typescript-eslint/prefer-nullish-coalescing": "error",
|
47
|
+
"@typescript-eslint/prefer-optional-chain": "error",
|
48
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
49
|
+
"@typescript-eslint/consistent-type-imports": [
|
50
|
+
"error",
|
51
|
+
{ prefer: "type-imports" }
|
52
|
+
],
|
53
|
+
"@typescript-eslint/no-import-type-side-effects": "error",
|
54
|
+
// Vue 规则
|
55
|
+
"vue/multi-word-component-names": "off",
|
56
|
+
"vue/no-unused-vars": "error",
|
57
|
+
"vue/prefer-import-from-vue": "error",
|
58
|
+
"vue/prefer-separate-static-class": "error",
|
59
|
+
"vue/prefer-true-attribute-shorthand": "error",
|
60
|
+
"vue/v-on-function-call": "error",
|
61
|
+
"vue/no-useless-v-bind": "error",
|
62
|
+
"vue/no-unused-refs": "error",
|
63
|
+
"vue/padding-line-between-blocks": "error",
|
64
|
+
"vue/component-tags-order": [
|
65
|
+
"error",
|
66
|
+
{
|
67
|
+
order: ["script", "template", "style"]
|
68
|
+
}
|
69
|
+
]
|
70
|
+
}
|
71
|
+
},
|
72
|
+
{
|
73
|
+
files: ["**/*.js", "**/*.mjs"],
|
74
|
+
...tseslint.configs.disableTypeChecked
|
75
|
+
},
|
76
|
+
{
|
77
|
+
ignores: [
|
78
|
+
"node_modules/**",
|
79
|
+
"dist/**",
|
80
|
+
"build/**",
|
81
|
+
"*.d.ts",
|
82
|
+
".bun/**",
|
83
|
+
"bun.lockb"
|
84
|
+
]
|
85
|
+
}
|
86
|
+
);
|
87
|
+
|
88
|
+
export { vue_config_default as default };
|
package/eslint.config.ts
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
import * as js from '@eslint/js';
|
2
|
+
import tseslint from 'typescript-eslint';
|
3
|
+
|
4
|
+
export function createConfig(options: { tsconfigRootDir?: string } = {}) {
|
5
|
+
return tseslint.config(
|
6
|
+
js.configs.recommended,
|
7
|
+
...tseslint.configs.recommended,
|
8
|
+
...tseslint.configs.strict,
|
9
|
+
{
|
10
|
+
files: ['**/*.ts', '**/*.tsx'],
|
11
|
+
languageOptions: {
|
12
|
+
parserOptions: {
|
13
|
+
// 如果提供了 tsconfigRootDir,则使用它
|
14
|
+
...(options.tsconfigRootDir && {
|
15
|
+
tsconfigRootDir: options.tsconfigRootDir,
|
16
|
+
}),
|
17
|
+
},
|
18
|
+
},
|
19
|
+
rules: {
|
20
|
+
// 基础规则
|
21
|
+
'no-console': 'warn',
|
22
|
+
'no-unused-vars': 'off', // 关闭基础规则,使用 TypeScript 版本
|
23
|
+
'prefer-const': 'error',
|
24
|
+
'no-var': 'error',
|
25
|
+
eqeqeq: ['error', 'always'],
|
26
|
+
curly: ['error', 'all'],
|
27
|
+
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1 }],
|
28
|
+
'no-trailing-spaces': 'error',
|
29
|
+
'comma-dangle': ['error', 'always-multiline'],
|
30
|
+
quotes: ['error', 'single', { avoidEscape: true }],
|
31
|
+
semi: ['error', 'always'],
|
32
|
+
'object-curly-spacing': ['error', 'always'],
|
33
|
+
'array-bracket-spacing': ['error', 'never'],
|
34
|
+
'space-before-blocks': 'error',
|
35
|
+
'keyword-spacing': 'error',
|
36
|
+
|
37
|
+
// TypeScript 特定规则
|
38
|
+
'@typescript-eslint/no-unused-vars': [
|
39
|
+
'error',
|
40
|
+
{
|
41
|
+
argsIgnorePattern: '^_',
|
42
|
+
varsIgnorePattern: '^_',
|
43
|
+
caughtErrorsIgnorePattern: '^_',
|
44
|
+
},
|
45
|
+
],
|
46
|
+
'@typescript-eslint/no-extraneous-class': 'off', // 允许类中有非方法成员
|
47
|
+
|
48
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
49
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
50
|
+
'@typescript-eslint/no-non-null-assertion': 'error',
|
51
|
+
'@typescript-eslint/no-import-type-side-effects': 'error',
|
52
|
+
'@typescript-eslint/array-type': ['error', { default: 'array' }],
|
53
|
+
'@typescript-eslint/consistent-type-definitions': [
|
54
|
+
'error',
|
55
|
+
'interface',
|
56
|
+
],
|
57
|
+
'@typescript-eslint/method-signature-style': ['error', 'property'],
|
58
|
+
'@typescript-eslint/prefer-function-type': 'error',
|
59
|
+
'@typescript-eslint/ban-ts-comment': [
|
60
|
+
'error',
|
61
|
+
{
|
62
|
+
'ts-expect-error': 'allow-with-description',
|
63
|
+
'ts-ignore': 'allow-with-description',
|
64
|
+
'ts-nocheck': 'allow-with-description',
|
65
|
+
'ts-check': false,
|
66
|
+
},
|
67
|
+
],
|
68
|
+
},
|
69
|
+
},
|
70
|
+
{
|
71
|
+
files: ['**/*.js', '**/*.mjs'],
|
72
|
+
...tseslint.configs.disableTypeChecked,
|
73
|
+
},
|
74
|
+
{
|
75
|
+
// Logger 和演示文件的特殊配置 - 允许使用 console
|
76
|
+
files: ['**/logger.ts', '**/logger-demo.ts', '**/node-types-demo.ts'],
|
77
|
+
rules: {
|
78
|
+
'no-console': 'off', // 演示文件中允许使用 console
|
79
|
+
},
|
80
|
+
},
|
81
|
+
{
|
82
|
+
ignores: [
|
83
|
+
'node_modules/**',
|
84
|
+
'dist/**',
|
85
|
+
'build/**',
|
86
|
+
'*.d.ts',
|
87
|
+
'.bun/**',
|
88
|
+
'bun.lockb',
|
89
|
+
],
|
90
|
+
},
|
91
|
+
);
|
92
|
+
}
|
93
|
+
|
94
|
+
// 默认导出,向后兼容,并为本包设置 tsconfigRootDir
|
95
|
+
export default createConfig({ tsconfigRootDir: __dirname });
|
package/package.json
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
{
|
2
|
+
"name": "@hestjs/eslint-config",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"description": "ESLint configuration",
|
5
|
+
"type": "module",
|
6
|
+
"main": "dist/eslint.config.js",
|
7
|
+
"types": "dist/eslint.config.d.ts",
|
8
|
+
"exports": {
|
9
|
+
".": {
|
10
|
+
"types": "./dist/eslint.config.d.ts",
|
11
|
+
"import": "./dist/eslint.config.js"
|
12
|
+
},
|
13
|
+
"./react": {
|
14
|
+
"types": "./dist/react.config.d.ts",
|
15
|
+
"import": "./dist/react.config.js"
|
16
|
+
},
|
17
|
+
"./vue": {
|
18
|
+
"types": "./dist/vue.config.d.ts",
|
19
|
+
"import": "./dist/vue.config.js"
|
20
|
+
},
|
21
|
+
"./base": {
|
22
|
+
"types": "./dist/base.config.d.ts",
|
23
|
+
"import": "./dist/base.config.js"
|
24
|
+
},
|
25
|
+
"./source": {
|
26
|
+
"types": "./eslint.config.ts",
|
27
|
+
"import": "./eslint.config.ts"
|
28
|
+
},
|
29
|
+
"./react/source": {
|
30
|
+
"types": "./react.config.ts",
|
31
|
+
"import": "./react.config.ts"
|
32
|
+
},
|
33
|
+
"./vue/source": {
|
34
|
+
"types": "./vue.config.ts",
|
35
|
+
"import": "./vue.config.ts"
|
36
|
+
},
|
37
|
+
"./base/source": {
|
38
|
+
"types": "./base.config.ts",
|
39
|
+
"import": "./base.config.ts"
|
40
|
+
}
|
41
|
+
},
|
42
|
+
"files": [
|
43
|
+
"dist/**/*",
|
44
|
+
"*.ts"
|
45
|
+
],
|
46
|
+
"engines": {
|
47
|
+
"node": ">=18.0.0"
|
48
|
+
},
|
49
|
+
"scripts": {
|
50
|
+
"build": "tsup",
|
51
|
+
"dev": "tsup --watch",
|
52
|
+
"type-check": "tsc --project tsconfig.check.json",
|
53
|
+
"test": "node --test",
|
54
|
+
"clean": "rm -rf dist"
|
55
|
+
},
|
56
|
+
"dependencies": {
|
57
|
+
"@eslint/js": "^9.31.0",
|
58
|
+
"typescript-eslint": "^8.36.0",
|
59
|
+
"eslint-plugin-import": "^2.32.0",
|
60
|
+
"eslint-plugin-promise": "^7.2.1",
|
61
|
+
"eslint-plugin-unicorn": "^59.0.1",
|
62
|
+
"eslint-plugin-react-hooks": "^5.1.0",
|
63
|
+
"eslint-plugin-react-refresh": "^0.4.16",
|
64
|
+
"eslint-plugin-vue": "^9.32.0"
|
65
|
+
},
|
66
|
+
"devDependencies": {
|
67
|
+
"tsup": "^8.5.0",
|
68
|
+
"typescript": "^5.8.3"
|
69
|
+
},
|
70
|
+
"peerDependencies": {
|
71
|
+
"eslint": "^9.0.0",
|
72
|
+
"typescript": ">=5.0.0"
|
73
|
+
},
|
74
|
+
"peerDependenciesMeta": {
|
75
|
+
"typescript": {
|
76
|
+
"optional": true
|
77
|
+
}
|
78
|
+
},
|
79
|
+
"keywords": [
|
80
|
+
"eve",
|
81
|
+
"eslint",
|
82
|
+
"config",
|
83
|
+
"typescript",
|
84
|
+
"javascript"
|
85
|
+
],
|
86
|
+
"author": "Hest Team",
|
87
|
+
"license": "MIT",
|
88
|
+
"homepage": "https://hest.dev",
|
89
|
+
"repository": {
|
90
|
+
"type": "git",
|
91
|
+
"url": "https://github.com/hest-framework/hest.git",
|
92
|
+
"directory": "packages/@hestjs/eslint-config"
|
93
|
+
},
|
94
|
+
"bugs": {
|
95
|
+
"url": "https://github.com/hest-framework/hest/issues"
|
96
|
+
}
|
97
|
+
}
|
package/react.config.ts
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
import * as js from '@eslint/js';
|
2
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
3
|
+
import reactRefresh from 'eslint-plugin-react-refresh';
|
4
|
+
import tseslint from 'typescript-eslint';
|
5
|
+
|
6
|
+
export default tseslint.config(
|
7
|
+
js.configs.recommended,
|
8
|
+
...tseslint.configs.recommended,
|
9
|
+
...tseslint.configs.strict,
|
10
|
+
{
|
11
|
+
files: ['**/*.ts', '**/*.tsx'],
|
12
|
+
languageOptions: {
|
13
|
+
parser: tseslint.parser,
|
14
|
+
parserOptions: {
|
15
|
+
project: './tsconfig.json',
|
16
|
+
tsconfigRootDir: import.meta.dirname,
|
17
|
+
ecmaFeatures: {
|
18
|
+
jsx: true,
|
19
|
+
},
|
20
|
+
},
|
21
|
+
},
|
22
|
+
plugins: {
|
23
|
+
'react-hooks': reactHooks,
|
24
|
+
'react-refresh': reactRefresh,
|
25
|
+
},
|
26
|
+
rules: {
|
27
|
+
// 基础规则
|
28
|
+
'no-console': 'warn',
|
29
|
+
'no-unused-vars': 'off',
|
30
|
+
'prefer-const': 'error',
|
31
|
+
'no-var': 'error',
|
32
|
+
eqeqeq: ['error', 'always'],
|
33
|
+
curly: ['error', 'all'],
|
34
|
+
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1 }],
|
35
|
+
'no-trailing-spaces': 'error',
|
36
|
+
'comma-dangle': ['error', 'always-multiline'],
|
37
|
+
quotes: ['error', 'single', { avoidEscape: true }],
|
38
|
+
semi: ['error', 'always'],
|
39
|
+
'object-curly-spacing': ['error', 'always'],
|
40
|
+
'array-bracket-spacing': ['error', 'never'],
|
41
|
+
'space-before-blocks': 'error',
|
42
|
+
'keyword-spacing': 'error',
|
43
|
+
|
44
|
+
// TypeScript 规则
|
45
|
+
'@typescript-eslint/no-unused-vars': [
|
46
|
+
'error',
|
47
|
+
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
|
48
|
+
],
|
49
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
50
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
51
|
+
'@typescript-eslint/prefer-nullish-coalescing': 'error',
|
52
|
+
'@typescript-eslint/prefer-optional-chain': 'error',
|
53
|
+
'@typescript-eslint/no-non-null-assertion': 'error',
|
54
|
+
'@typescript-eslint/consistent-type-imports': [
|
55
|
+
'error',
|
56
|
+
{ prefer: 'type-imports' },
|
57
|
+
],
|
58
|
+
'@typescript-eslint/no-import-type-side-effects': 'error',
|
59
|
+
|
60
|
+
// React 规则
|
61
|
+
...reactHooks.configs.recommended.rules,
|
62
|
+
'react-refresh/only-export-components': [
|
63
|
+
'warn',
|
64
|
+
{ allowConstantExport: true },
|
65
|
+
],
|
66
|
+
},
|
67
|
+
},
|
68
|
+
{
|
69
|
+
files: ['**/*.js', '**/*.mjs'],
|
70
|
+
...tseslint.configs.disableTypeChecked,
|
71
|
+
},
|
72
|
+
{
|
73
|
+
ignores: [
|
74
|
+
'node_modules/**',
|
75
|
+
'dist/**',
|
76
|
+
'build/**',
|
77
|
+
'*.d.ts',
|
78
|
+
'.bun/**',
|
79
|
+
'bun.lockb',
|
80
|
+
],
|
81
|
+
},
|
82
|
+
);
|
package/tsup.config.ts
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
import { defineConfig } from 'tsup';
|
2
|
+
|
3
|
+
export default defineConfig({
|
4
|
+
entry: [
|
5
|
+
'eslint.config.ts',
|
6
|
+
'react.config.ts',
|
7
|
+
'vue.config.ts',
|
8
|
+
'base.config.ts',
|
9
|
+
],
|
10
|
+
format: ['esm'],
|
11
|
+
dts: true, // 启用类型声明文件生成
|
12
|
+
clean: true,
|
13
|
+
minify: false,
|
14
|
+
target: 'es2022', // 使用更现代的目标
|
15
|
+
platform: 'node',
|
16
|
+
outDir: 'dist',
|
17
|
+
splitting: false, // ESLint 配置不需要代码分割
|
18
|
+
sourcemap: false, // 配置文件不需要 sourcemap
|
19
|
+
treeshake: true, // 启用 tree shaking
|
20
|
+
external: [
|
21
|
+
// ESLint 相关依赖标记为外部依赖,避免打包
|
22
|
+
'@eslint/js',
|
23
|
+
'typescript-eslint',
|
24
|
+
'eslint-plugin-import',
|
25
|
+
'eslint-plugin-promise',
|
26
|
+
'eslint-plugin-unicorn',
|
27
|
+
'eslint-plugin-react-hooks',
|
28
|
+
'eslint-plugin-react-refresh',
|
29
|
+
'eslint-plugin-vue',
|
30
|
+
],
|
31
|
+
});
|
package/vue.config.ts
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
import * as js from '@eslint/js';
|
2
|
+
import pluginVue from 'eslint-plugin-vue';
|
3
|
+
import tseslint from 'typescript-eslint';
|
4
|
+
|
5
|
+
export default tseslint.config(
|
6
|
+
js.configs.recommended,
|
7
|
+
...tseslint.configs.recommended,
|
8
|
+
...tseslint.configs.strict,
|
9
|
+
...pluginVue.configs['flat/recommended'],
|
10
|
+
{
|
11
|
+
files: ['**/*.ts', '**/*.tsx', '**/*.vue'],
|
12
|
+
languageOptions: {
|
13
|
+
parser: tseslint.parser,
|
14
|
+
parserOptions: {
|
15
|
+
project: './tsconfig.json',
|
16
|
+
tsconfigRootDir: import.meta.dirname,
|
17
|
+
parser: '@typescript-eslint/parser',
|
18
|
+
extraFileExtensions: ['.vue'],
|
19
|
+
},
|
20
|
+
},
|
21
|
+
rules: {
|
22
|
+
// 基础规则
|
23
|
+
'no-console': 'warn',
|
24
|
+
'no-unused-vars': 'off',
|
25
|
+
'prefer-const': 'error',
|
26
|
+
'no-var': 'error',
|
27
|
+
eqeqeq: ['error', 'always'],
|
28
|
+
curly: ['error', 'all'],
|
29
|
+
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1 }],
|
30
|
+
'no-trailing-spaces': 'error',
|
31
|
+
'comma-dangle': ['error', 'always-multiline'],
|
32
|
+
quotes: ['error', 'single', { avoidEscape: true }],
|
33
|
+
semi: ['error', 'always'],
|
34
|
+
'object-curly-spacing': ['error', 'always'],
|
35
|
+
'array-bracket-spacing': ['error', 'never'],
|
36
|
+
'space-before-blocks': 'error',
|
37
|
+
'keyword-spacing': 'error',
|
38
|
+
|
39
|
+
// TypeScript 规则
|
40
|
+
'@typescript-eslint/no-unused-vars': [
|
41
|
+
'error',
|
42
|
+
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
|
43
|
+
],
|
44
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
45
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
46
|
+
'@typescript-eslint/prefer-nullish-coalescing': 'error',
|
47
|
+
'@typescript-eslint/prefer-optional-chain': 'error',
|
48
|
+
'@typescript-eslint/no-non-null-assertion': 'error',
|
49
|
+
'@typescript-eslint/consistent-type-imports': [
|
50
|
+
'error',
|
51
|
+
{ prefer: 'type-imports' },
|
52
|
+
],
|
53
|
+
'@typescript-eslint/no-import-type-side-effects': 'error',
|
54
|
+
|
55
|
+
// Vue 规则
|
56
|
+
'vue/multi-word-component-names': 'off',
|
57
|
+
'vue/no-unused-vars': 'error',
|
58
|
+
'vue/prefer-import-from-vue': 'error',
|
59
|
+
'vue/prefer-separate-static-class': 'error',
|
60
|
+
'vue/prefer-true-attribute-shorthand': 'error',
|
61
|
+
'vue/v-on-function-call': 'error',
|
62
|
+
'vue/no-useless-v-bind': 'error',
|
63
|
+
'vue/no-unused-refs': 'error',
|
64
|
+
'vue/padding-line-between-blocks': 'error',
|
65
|
+
'vue/component-tags-order': [
|
66
|
+
'error',
|
67
|
+
{
|
68
|
+
order: ['script', 'template', 'style'],
|
69
|
+
},
|
70
|
+
],
|
71
|
+
},
|
72
|
+
},
|
73
|
+
{
|
74
|
+
files: ['**/*.js', '**/*.mjs'],
|
75
|
+
...tseslint.configs.disableTypeChecked,
|
76
|
+
},
|
77
|
+
{
|
78
|
+
ignores: [
|
79
|
+
'node_modules/**',
|
80
|
+
'dist/**',
|
81
|
+
'build/**',
|
82
|
+
'*.d.ts',
|
83
|
+
'.bun/**',
|
84
|
+
'bun.lockb',
|
85
|
+
],
|
86
|
+
},
|
87
|
+
);
|