@coderwyd/eslint-config 4.11.1 → 5.0.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 +228 -142
- package/dist/index.d.mts +26 -14994
- package/dist/index.mjs +67 -1881
- package/package.json +16 -81
- package/bin/index.mjs +0 -3
- package/dist/cli.d.mts +0 -1
- package/dist/cli.mjs +0 -184
package/README.md
CHANGED
|
@@ -2,35 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/coderwyd/eslint-config/actions/workflows/release.yml)
|
|
4
4
|
[](https://npmjs.org/package/@coderwyd/eslint-config)
|
|
5
|
-
[](https://npmjs.org/package/@coderwyd/eslint-config)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
高度可配置的 ESLint 配置预设,开箱即用,支持 Vue、React、Svelte、TypeScript 等多个框架和语言。基于 [@antfu/eslint-config](https://github.com/antfu/eslint-config) 构建。
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- ✨ Support Vue, React, Svelte.
|
|
11
|
-
- 🎯 Designed to work with TypeScript, Vue out-of-box
|
|
12
|
-
- 🏆 Reasonable defaults, best practices, only one-line of config
|
|
9
|
+
English | [简体中文](#简体中文)
|
|
13
10
|
|
|
14
|
-
##
|
|
11
|
+
## ✨ 特性
|
|
15
12
|
|
|
16
|
-
|
|
13
|
+
- 🛠️ **开箱即用** - 合理的默认配置,无需复杂设置
|
|
14
|
+
- 🎯 **多框架支持** - Vue、React、Svelte、TypeScript 等
|
|
15
|
+
- 🔧 **自动修复** - 一键修复代码风格问题
|
|
16
|
+
- 📦 **自动检测** - 根据项目依赖自动启用相关规则
|
|
17
|
+
- 🎨 **Flat Config** - 基于 ESLint 新的 Flat Config 体系
|
|
18
|
+
- 🚀 **高性能** - 优化的规则合并策略
|
|
19
|
+
- 🧩 **可组合** - 灵活的配置组合和自定义
|
|
20
|
+
|
|
21
|
+
## 📦 快速开始
|
|
22
|
+
|
|
23
|
+
### 安装
|
|
24
|
+
|
|
25
|
+
使用你喜欢的包管理器安装:
|
|
17
26
|
|
|
18
27
|
```bash
|
|
28
|
+
# pnpm
|
|
19
29
|
pnpm i -D eslint @coderwyd/eslint-config
|
|
30
|
+
|
|
31
|
+
# npm
|
|
32
|
+
npm i -D eslint @coderwyd/eslint-config
|
|
33
|
+
|
|
34
|
+
# yarn
|
|
35
|
+
yarn add -D eslint @coderwyd/eslint-config
|
|
20
36
|
```
|
|
21
37
|
|
|
22
|
-
###
|
|
38
|
+
### 创建配置文件
|
|
39
|
+
|
|
40
|
+
在项目根目录创建 `eslint.config.js`(或 `eslint.config.mjs`):
|
|
23
41
|
|
|
24
42
|
```js
|
|
25
|
-
// eslint.config.js
|
|
26
43
|
import { defineConfig } from '@coderwyd/eslint-config'
|
|
27
44
|
|
|
28
45
|
export default defineConfig()
|
|
29
46
|
```
|
|
30
47
|
|
|
31
|
-
###
|
|
48
|
+
### 添加 npm 脚本
|
|
32
49
|
|
|
33
|
-
|
|
50
|
+
在 `package.json` 中添加以下脚本:
|
|
34
51
|
|
|
35
52
|
```json
|
|
36
53
|
{
|
|
@@ -41,26 +58,136 @@ For example:
|
|
|
41
58
|
}
|
|
42
59
|
```
|
|
43
60
|
|
|
44
|
-
|
|
61
|
+
完成!现在你可以运行 `npm run lint` 来检查代码风格。
|
|
62
|
+
|
|
63
|
+
## 🎯 框架支持
|
|
64
|
+
|
|
65
|
+
### Vue
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
import { defineConfig } from '@coderwyd/eslint-config'
|
|
69
|
+
|
|
70
|
+
export default defineConfig({
|
|
71
|
+
vue: true, // 支持 Vue 版本 (2 或 3)
|
|
72
|
+
})
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### React
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
import { defineConfig } from '@coderwyd/eslint-config'
|
|
79
|
+
|
|
80
|
+
export default defineConfig({
|
|
81
|
+
react: true,
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### TypeScript
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import { defineConfig } from '@coderwyd/eslint-config'
|
|
89
|
+
|
|
90
|
+
export default defineConfig({
|
|
91
|
+
typescript: true,
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 组合使用
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
import { defineConfig } from '@coderwyd/eslint-config'
|
|
99
|
+
|
|
100
|
+
export default defineConfig({
|
|
101
|
+
vue: true,
|
|
102
|
+
typescript: true,
|
|
103
|
+
react: false, // 显式禁用
|
|
104
|
+
})
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## ⚙️ 配置选项
|
|
108
|
+
|
|
109
|
+
### 基础选项
|
|
110
|
+
|
|
111
|
+
| 选项 | 说明 | 默认值 |
|
|
112
|
+
| ------------- | ---------------------- | -------- |
|
|
113
|
+
| `typescript` | 启用 TypeScript 支持 | 自动检测 |
|
|
114
|
+
| `vue` | 启用 Vue 支持 | `true` 3 |
|
|
115
|
+
| `react` | 启用 React 支持 | `false` |
|
|
116
|
+
| `svelte` | 启用 Svelte 支持 | `false` |
|
|
117
|
+
| `tailwindcss` | 启用 Tailwind CSS 验证 | 自动检测 |
|
|
118
|
+
| `test` | 启用测试文件支持 | `true` |
|
|
119
|
+
|
|
120
|
+
### 规则覆盖
|
|
121
|
+
|
|
122
|
+
自定义 ESLint 规则:
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
import { defineConfig } from '@coderwyd/eslint-config'
|
|
126
|
+
|
|
127
|
+
export default defineConfig({
|
|
128
|
+
typescript: {
|
|
129
|
+
overrides: {
|
|
130
|
+
'ts/no-explicit-any': 'warn',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
vue: {
|
|
134
|
+
overrides: {
|
|
135
|
+
'vue/multi-word-component-names': 'off',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
})
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 追加自定义配置
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
import { defineConfig } from '@coderwyd/eslint-config'
|
|
145
|
+
|
|
146
|
+
export default defineConfig(
|
|
147
|
+
{
|
|
148
|
+
typescript: true,
|
|
149
|
+
vue: true,
|
|
150
|
+
},
|
|
151
|
+
// 追加自定义配置
|
|
152
|
+
{
|
|
153
|
+
files: ['src/**/*.vue'],
|
|
154
|
+
rules: {
|
|
155
|
+
'vue/block-order': ['error', { order: ['script', 'template', 'style'] }],
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
ignores: ['dist', 'node_modules'],
|
|
160
|
+
},
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 🔧 编辑器集成
|
|
165
|
+
|
|
166
|
+
### VS Code
|
|
45
167
|
|
|
46
|
-
|
|
168
|
+
在 `.vscode/settings.json` 中添加以下配置以启用自动修复:
|
|
47
169
|
|
|
48
|
-
```
|
|
170
|
+
```json
|
|
49
171
|
{
|
|
50
|
-
"prettier.enable": true,
|
|
51
172
|
"editor.formatOnSave": false,
|
|
52
|
-
|
|
53
|
-
// Auto fix
|
|
54
173
|
"editor.codeActionsOnSave": {
|
|
55
174
|
"source.fixAll": "explicit",
|
|
56
|
-
"source.organizeImports": "never"
|
|
57
|
-
}
|
|
175
|
+
"source.organizeImports": "never"
|
|
176
|
+
}
|
|
58
177
|
}
|
|
59
178
|
```
|
|
60
179
|
|
|
61
|
-
|
|
180
|
+
## 📋 Git Hooks
|
|
62
181
|
|
|
63
|
-
|
|
182
|
+
使用 lint-staged 在提交前自动检查和修复代码:
|
|
183
|
+
|
|
184
|
+
### 安装依赖
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
pnpm i -D lint-staged simple-git-hooks
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### 配置 package.json
|
|
64
191
|
|
|
65
192
|
```json
|
|
66
193
|
{
|
|
@@ -73,136 +200,95 @@ If you want to apply lint and auto-fix before every commit, you can add the foll
|
|
|
73
200
|
}
|
|
74
201
|
```
|
|
75
202
|
|
|
76
|
-
|
|
203
|
+
### 初始化 Git Hooks
|
|
77
204
|
|
|
78
205
|
```bash
|
|
79
|
-
|
|
206
|
+
pnpm simple-git-hooks
|
|
80
207
|
```
|
|
81
208
|
|
|
82
|
-
##
|
|
209
|
+
## 📂 项目结构
|
|
210
|
+
|
|
211
|
+
本项目代码组织清晰,职责划分明确:
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
src/
|
|
215
|
+
├── index.ts # 主入口,导出 defineConfig() 和公共类型
|
|
216
|
+
├── types.ts # 统一管理所有类型定义
|
|
217
|
+
├── merge-options.ts # 配置选项合并和规范化逻辑
|
|
218
|
+
├── utils.ts # 工具函数(包管理检测等)
|
|
219
|
+
└── configs/
|
|
220
|
+
├── index.ts # 配置模块导出
|
|
221
|
+
└── tailwindcss.ts # Tailwind CSS ESLint 规则配置
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## 🔌 API 参考
|
|
225
|
+
|
|
226
|
+
### `defineConfig(options?, ...userConfigs?)`
|
|
83
227
|
|
|
84
|
-
|
|
228
|
+
创建 ESLint Flat Config 配置。
|
|
229
|
+
|
|
230
|
+
**参数:**
|
|
231
|
+
|
|
232
|
+
- `options?` (`Options`) - 配置选项对象
|
|
233
|
+
- `...userConfigs?` - 追加的 ESLint 配置对象
|
|
234
|
+
|
|
235
|
+
**返回值:** `FlatConfigComposer` - 可进一步自定义的配置对象
|
|
236
|
+
|
|
237
|
+
**类型导出:**
|
|
85
238
|
|
|
86
239
|
```ts
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* The current working directory
|
|
90
|
-
*
|
|
91
|
-
* @default process.cwd()
|
|
92
|
-
*/
|
|
93
|
-
cwd?: string
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Enable gitignore support.
|
|
97
|
-
*
|
|
98
|
-
* Passing an object to configure the options.
|
|
99
|
-
*
|
|
100
|
-
* @see https://github.com/antfu/eslint-config-flat-gitignore
|
|
101
|
-
* @default true
|
|
102
|
-
*/
|
|
103
|
-
gitignore?: boolean | FlatGitignoreOptions
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Core rules. Can't be disabled.
|
|
107
|
-
*/
|
|
108
|
-
javascript?: OptionsOverrides
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Enable TypeScript support.
|
|
112
|
-
*
|
|
113
|
-
* Passing an object to enable TypeScript Language Server support.
|
|
114
|
-
*
|
|
115
|
-
* @default auto-detect based on the dependencies
|
|
116
|
-
*/
|
|
117
|
-
typescript?: boolean | OptionsTypescript
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Enable test support.
|
|
121
|
-
*
|
|
122
|
-
* @default true
|
|
123
|
-
*/
|
|
124
|
-
test?: boolean | OptionsOverrides
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Enable Vue support.
|
|
128
|
-
*
|
|
129
|
-
* @default auto-detect based on the dependencies
|
|
130
|
-
*/
|
|
131
|
-
vue?: boolean | OptionsVue
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Enable JSONC support.
|
|
135
|
-
*
|
|
136
|
-
* @default true
|
|
137
|
-
*/
|
|
138
|
-
jsonc?: boolean | OptionsOverrides
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Enable react rules.
|
|
142
|
-
*
|
|
143
|
-
* Requires installing:
|
|
144
|
-
* - `@eslint-react/eslint-plugin`
|
|
145
|
-
* - `eslint-plugin-react-hooks`
|
|
146
|
-
* - `eslint-plugin-react-refresh`
|
|
147
|
-
*
|
|
148
|
-
* @default false
|
|
149
|
-
*/
|
|
150
|
-
react?: boolean | OptionsOverrides
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Enable svelte rules.
|
|
154
|
-
*
|
|
155
|
-
* Requires installing:
|
|
156
|
-
* - `eslint-plugin-svelte`
|
|
157
|
-
*
|
|
158
|
-
* @default false
|
|
159
|
-
*/
|
|
160
|
-
svelte?: boolean | OptionsOverrides
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Enable tainwindcss rules.
|
|
164
|
-
*
|
|
165
|
-
* @default auto-detect based on the dependencies
|
|
166
|
-
*/
|
|
167
|
-
tailwindcss?: boolean | OptionsOverrides
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Enable unocss rules.
|
|
171
|
-
*
|
|
172
|
-
* Requires installing:
|
|
173
|
-
* - `@unocss/eslint-plugin`
|
|
174
|
-
*
|
|
175
|
-
* @default false
|
|
176
|
-
*/
|
|
177
|
-
unocss?: boolean | OptionsUnoCSS
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Enable regexp rules.
|
|
181
|
-
*
|
|
182
|
-
* @see https://ota-meshi.github.io/eslint-plugin-regexp/
|
|
183
|
-
* @default true
|
|
184
|
-
*/
|
|
185
|
-
regexp?: boolean | (OptionsRegExp & OptionsOverrides)
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Control to disable some rules in editors.
|
|
189
|
-
* @default auto-detect based on the process.env
|
|
190
|
-
*/
|
|
191
|
-
isInEditor?: boolean
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Automatically rename plugins in the config.
|
|
195
|
-
*
|
|
196
|
-
* @default true
|
|
197
|
-
*/
|
|
198
|
-
autoRenamePlugins?: boolean
|
|
199
|
-
}
|
|
240
|
+
import type { Options, OptionsAddons, OptionsTailwindcss } from '@coderwyd/eslint-config'
|
|
200
241
|
```
|
|
201
242
|
|
|
202
|
-
|
|
243
|
+
**完整示例:**
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
import { defineConfig } from '@coderwyd/eslint-config'
|
|
247
|
+
|
|
248
|
+
export default defineConfig(
|
|
249
|
+
{
|
|
250
|
+
typescript: true,
|
|
251
|
+
vue: true,
|
|
252
|
+
tailwindcss: true,
|
|
253
|
+
typescript: {
|
|
254
|
+
overrides: {
|
|
255
|
+
'ts/no-explicit-any': 'warn',
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
// 自定义 Vue 文件规则
|
|
260
|
+
{
|
|
261
|
+
files: ['src/**/*.vue'],
|
|
262
|
+
rules: {
|
|
263
|
+
'vue/multi-word-component-names': 'off',
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
)
|
|
267
|
+
```
|
|
203
268
|
|
|
204
|
-
|
|
269
|
+
## 🤝 贡献
|
|
205
270
|
|
|
206
|
-
|
|
271
|
+
欢迎提交 Issue 和 Pull Request!
|
|
272
|
+
|
|
273
|
+
## 📄 许可证
|
|
207
274
|
|
|
208
275
|
[MIT](./LICENSE) License © 2023-PRESENT [Donny Wang](https://github.com/coderwyd)
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## 简体中文
|
|
280
|
+
|
|
281
|
+
本项目为开箱即用的 ESLint 配置预设。更详细内容请查看上方英文文档。
|
|
282
|
+
|
|
283
|
+
### 快速开始
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
# 安装
|
|
287
|
+
pnpm i -D eslint @coderwyd/eslint-config
|
|
288
|
+
|
|
289
|
+
# 创建 eslint.config.js
|
|
290
|
+
echo "import { defineConfig } from '@coderwyd/eslint-config'; export default defineConfig()" > eslint.config.js
|
|
291
|
+
|
|
292
|
+
# 使用
|
|
293
|
+
pnpm eslint .
|
|
294
|
+
```
|