@purea/eslint-config 0.0.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/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/README.md +463 -0
- package/dist/index.d.ts +133 -0
- package/dist/index.js +1118 -0
- package/eslint.config.ts +12 -0
- package/package.json +42 -0
- package/src/configs/ignores.ts +17 -0
- package/src/configs/imports.ts +104 -0
- package/src/configs/index.ts +7 -0
- package/src/configs/javascript.ts +268 -0
- package/src/configs/jsonc.ts +66 -0
- package/src/configs/stylistic.ts +278 -0
- package/src/configs/typescript.ts +263 -0
- package/src/configs/vue.ts +69 -0
- package/src/factory.ts +70 -0
- package/src/index.ts +9 -0
- package/src/types.ts +82 -0
- package/src/utils.ts +19 -0
- package/test/javascript-rules.test.ts +1134 -0
- package/tsconfig.json +14 -0
- package/tsdown.config.ts +7 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.0.1] - 2026-01-02
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of @purea/eslint-config
|
|
12
|
+
- ESLint 9+ flat config format support
|
|
13
|
+
- TypeScript configuration with strict type checking
|
|
14
|
+
- JavaScript modern ES6+ rules
|
|
15
|
+
- Stylistic code formatting rules
|
|
16
|
+
- Import/Export organization rules
|
|
17
|
+
- File ignore patterns
|
|
18
|
+
- TypeScript compilation with tsdown
|
|
19
|
+
- MIT license
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
- Zero-configuration setup with sensible defaults
|
|
23
|
+
- Modular config exports for flexible usage
|
|
24
|
+
- Factory function for easy configuration composition
|
|
25
|
+
- Type-safe configuration API
|
|
26
|
+
- Support for both JavaScript and TypeScript projects
|
|
27
|
+
- Optimized rule sets for modern development
|
|
28
|
+
|
|
29
|
+
### Configurations
|
|
30
|
+
- `javascript`: Core JavaScript rules and best practices
|
|
31
|
+
- `typescript`: TypeScript-specific type safety rules
|
|
32
|
+
- `stylistic`: Code style and formatting rules
|
|
33
|
+
- `imports`: Import/export organization and ordering
|
|
34
|
+
- `ignores`: File and directory ignore patterns
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Pure Anin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
# @purea/eslint-config
|
|
2
|
+
|
|
3
|
+
> 一款现代化的、开箱即用的 ESLint 配置库,专为 JavaScript 和 TypeScript 项目设计。
|
|
4
|
+
|
|
5
|
+
A comprehensive, opinionated ESLint configuration library for modern JavaScript and TypeScript projects.
|
|
6
|
+
|
|
7
|
+
## ✨ 特性 Features
|
|
8
|
+
|
|
9
|
+
- 🎯 **零配置** 开箱即用,提供合理的默认设置
|
|
10
|
+
- 🔧 **TypeScript 支持** 完整的 TypeScript 集成和严格规则
|
|
11
|
+
- 📦 **现代化** 使用最新的 ESLint Flat Config 格式
|
|
12
|
+
- 🚀 **高性能** 通过动态导入优化加载速度
|
|
13
|
+
- 🎨 **一致性** 在整个项目中强制执行统一的代码风格
|
|
14
|
+
- 🛠️ **可扩展** 易于自定义和扩展
|
|
15
|
+
- 📝 **完善文档** 所有规则都包含中文注释
|
|
16
|
+
|
|
17
|
+
## 📦 安装 Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install --save-dev @purea/eslint-config
|
|
21
|
+
# or
|
|
22
|
+
pnpm add -D @purea/eslint-config
|
|
23
|
+
# or
|
|
24
|
+
yarn add -D @purea/eslint-config
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 🚀 快速开始 Quick Start
|
|
28
|
+
|
|
29
|
+
### 基础用法 Basic Usage
|
|
30
|
+
|
|
31
|
+
在项目根目录创建 `eslint.config.js` 文件:
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
import config from '@purea/eslint-config'
|
|
35
|
+
|
|
36
|
+
export default config()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
这将使用默认配置,自动启用 JavaScript、Stylistic、TypeScript、JSONC、Vue 和导入规则。
|
|
40
|
+
|
|
41
|
+
This uses the default configuration with JavaScript, Stylistic, TypeScript, JSONC, Vue, and import rules enabled.
|
|
42
|
+
|
|
43
|
+
### 高级用法 Advanced Usage
|
|
44
|
+
|
|
45
|
+
根据项目需求自定义配置:
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
import config from '@purea/eslint-config'
|
|
49
|
+
|
|
50
|
+
export default config({
|
|
51
|
+
typescript: true, // 启用 TypeScript 规则
|
|
52
|
+
imports: true, // 启用导入规则
|
|
53
|
+
jsonc: true, // 启用 JSONC 规则
|
|
54
|
+
vue: true, // 启用 Vue 规则
|
|
55
|
+
ignores: ['dist', 'build'], // 自定义忽略模式
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**注意**:`stylistic`(代码风格规则)默认启用,无法通过配置选项禁用。
|
|
60
|
+
|
|
61
|
+
### 直接使用 useConfig Using useConfig Directly
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
import { useConfig } from '@purea/eslint-config'
|
|
65
|
+
|
|
66
|
+
export default useConfig({
|
|
67
|
+
typescript: true,
|
|
68
|
+
imports: true
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
JavaScript 和 Stylistic 配置默认启用,无需额外配置。
|
|
73
|
+
|
|
74
|
+
### 使用独立配置 Using Individual Configs
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
import { javascript, typescript, imports, stylistic, ignores } from '@purea/eslint-config'
|
|
78
|
+
|
|
79
|
+
export default [
|
|
80
|
+
ignores(['dist', 'node_modules']),
|
|
81
|
+
javascript(),
|
|
82
|
+
stylistic(),
|
|
83
|
+
typescript(),
|
|
84
|
+
imports(),
|
|
85
|
+
{
|
|
86
|
+
// 自定义规则
|
|
87
|
+
rules: {
|
|
88
|
+
'no-console': 'off'
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 添加自定义规则 Adding Custom Rules
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
import { useConfig } from '@purea/eslint-config'
|
|
98
|
+
|
|
99
|
+
export default useConfig({
|
|
100
|
+
typescript: true,
|
|
101
|
+
imports: true,
|
|
102
|
+
ignores: ['dist', 'node_modules', '*.config.js']
|
|
103
|
+
}, {
|
|
104
|
+
// 额外配置
|
|
105
|
+
rules: {
|
|
106
|
+
'no-console': 'off',
|
|
107
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
108
|
+
'@stylistic/quotes': 'off' // 覆盖默认的stylistic规则
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## ⚙️ 配置选项 Configuration Options
|
|
114
|
+
|
|
115
|
+
| 选项 Option | 类型 Type | 默认值 Default | 描述 Description |
|
|
116
|
+
|------------|---------|---------------|-----------------|
|
|
117
|
+
| `typescript` | `boolean \| object` | `auto` | 启用 TypeScript 特定规则,自动检测 TypeScript 是否安装 |
|
|
118
|
+
| `imports` | `boolean` | `true` | 启用导入组织规则 |
|
|
119
|
+
| `jsonc` | `boolean` | `true` | 启用 JSON/JSONC 文件规则 |
|
|
120
|
+
| `vue` | `boolean \| object` | `auto` | 启用 Vue.js 特定规则,自动检测 Vue 是否安装 |
|
|
121
|
+
| `ignores` | `string[]` | `[]` | 自定义忽略模式 |
|
|
122
|
+
|
|
123
|
+
## 📋 可用配置 Available Configs
|
|
124
|
+
|
|
125
|
+
所有配置函数都返回 Promise,由 ESLint 自动处理:
|
|
126
|
+
|
|
127
|
+
- `javascript()` - 基础 JavaScript 规则,支持现代 ES6+ 语法(350+ 规则)
|
|
128
|
+
- `typescript()` - TypeScript 特定规则,包含类型检查
|
|
129
|
+
- `imports()` - 导入组织和依赖管理规则
|
|
130
|
+
- `stylistic()` - 代码风格规则,基于 @stylistic/eslint-plugin(100+ 规则)
|
|
131
|
+
- `jsonc()` - JSON/JSONC 文件规则
|
|
132
|
+
- `vue()` - Vue.js 特定规则
|
|
133
|
+
- `ignores(patterns)` - 文件和目录忽略模式(同步函数)
|
|
134
|
+
|
|
135
|
+
**注意**:`javascript()` 和 `stylistic()` 配置默认启用,无法通过配置选项禁用。
|
|
136
|
+
|
|
137
|
+
## 📝 规则概览 Rules Overview
|
|
138
|
+
|
|
139
|
+
### JavaScript 规则 JavaScript Rules
|
|
140
|
+
|
|
141
|
+
JavaScript 配置包含 350+ 条规则,涵盖:
|
|
142
|
+
|
|
143
|
+
**可能的错误 Possible Errors**
|
|
144
|
+
- 捕获常见的编程错误
|
|
145
|
+
- `no-console` (warn): 禁用 console 语句
|
|
146
|
+
- `no-debugger` (error): 禁用 debugger 语句
|
|
147
|
+
- `no-dupe-args` (error): 防止重复的函数参数
|
|
148
|
+
|
|
149
|
+
**最佳实践 Best Practices**
|
|
150
|
+
- 强制执行现代 JavaScript 最佳实践
|
|
151
|
+
- `eqeqeq` (error): 要求使用 `===` 和 `!==`
|
|
152
|
+
- `no-eval` (error): 禁用 `eval()` 使用
|
|
153
|
+
- `prefer-const` (error): 优先对不重新赋值的变量使用 `const`
|
|
154
|
+
|
|
155
|
+
**变量 Variables**
|
|
156
|
+
- 正确的变量声明和使用
|
|
157
|
+
- `no-unused-vars` (warn): 禁止未使用的变量
|
|
158
|
+
- `no-shadow` (warn): 禁止变量遮蔽
|
|
159
|
+
|
|
160
|
+
**环境支持 Environment Support**
|
|
161
|
+
- Node.js 全局变量
|
|
162
|
+
- ES2023 全局变量
|
|
163
|
+
- 浏览器全局变量(window, document, navigator)
|
|
164
|
+
|
|
165
|
+
### Stylistic 规则 Stylistic Rules
|
|
166
|
+
|
|
167
|
+
Stylistic 配置基于 `@stylistic/eslint-plugin`,包含 100+ 条代码风格规则:
|
|
168
|
+
|
|
169
|
+
**数组规则 Array Rules**
|
|
170
|
+
- `@stylistic/array-bracket-spacing`: 强制数组括号内无空格
|
|
171
|
+
- `@stylistic/array-element-newline`: 控制数组元素换行
|
|
172
|
+
|
|
173
|
+
**箭头函数规则 Arrow Function Rules**
|
|
174
|
+
- `@stylistic/arrow-parens`: 强制箭头函数参数使用括号
|
|
175
|
+
- `@stylistic/arrow-spacing`: 强制箭头函数箭头前后空格
|
|
176
|
+
|
|
177
|
+
**块规则 Block Rules**
|
|
178
|
+
- `@stylistic/block-spacing`: 强制块内空格
|
|
179
|
+
- `@stylistic/brace-style`: 强制大括号风格(1TBS)
|
|
180
|
+
|
|
181
|
+
**逗号规则 Comma Rules**
|
|
182
|
+
- `@stylistic/comma-dangle`: 强制在多行中使用尾随逗号
|
|
183
|
+
- `@stylistic/comma-spacing`: 强制逗号前后空格
|
|
184
|
+
|
|
185
|
+
**缩进规则 Indent Rules**
|
|
186
|
+
- `@stylistic/indent`: 强制缩进为2空格
|
|
187
|
+
- 支持多种代码结构的智能缩进
|
|
188
|
+
|
|
189
|
+
**引号规则 Quotes Rules**
|
|
190
|
+
- `@stylistic/quotes`: 强制使用单引号
|
|
191
|
+
- `@stylistic/quote-props`: 强制对象属性引号
|
|
192
|
+
|
|
193
|
+
**分号规则 Semi Rules**
|
|
194
|
+
- `@stylistic/semi`: 强制使用分号
|
|
195
|
+
- `@stylistic/semi-spacing`: 强制分号前后空格
|
|
196
|
+
|
|
197
|
+
**空格规则 Space Rules**
|
|
198
|
+
- `@stylistic/space-before-blocks`: 强制块前空格
|
|
199
|
+
- `@stylistic/space-infix-ops`: 强制运算符周围空格
|
|
200
|
+
- `@stylistic/space-before-function-paren`: 强制函数括号前空格
|
|
201
|
+
|
|
202
|
+
**其他规则 Other Rules**
|
|
203
|
+
- `@stylistic/max-len`: 强制最大行长度为120
|
|
204
|
+
- `@stylistic/no-trailing-spaces`: 禁止行尾空格
|
|
205
|
+
- `@stylistic/no-tabs`: 禁止制表符
|
|
206
|
+
- `@stylistic/linebreak-style`: 强制换行符风格(Unix)
|
|
207
|
+
|
|
208
|
+
### TypeScript 规则 TypeScript Rules
|
|
209
|
+
|
|
210
|
+
TypeScript 配置包含:
|
|
211
|
+
|
|
212
|
+
- 自动检测 `tsconfigRootDir` 的解析器配置
|
|
213
|
+
- 源代码类型:ES Module
|
|
214
|
+
- 类型检查规则
|
|
215
|
+
- `@typescript-eslint/no-explicit-any` (warn): 对 `any` 类型使用发出警告
|
|
216
|
+
|
|
217
|
+
### 导入规则 Import Rules
|
|
218
|
+
|
|
219
|
+
导入配置包含全面的规则:
|
|
220
|
+
|
|
221
|
+
**静态分析 Static Analysis**
|
|
222
|
+
- 确保导入存在且有效
|
|
223
|
+
- `import/named` (error): 确保命名导入存在
|
|
224
|
+
- `import/default` (error): 确保默认导入存在
|
|
225
|
+
|
|
226
|
+
**代码风格 Code Style**
|
|
227
|
+
- 组织和格式化导入
|
|
228
|
+
- `import/first` (error): 确保导入在文件顶部
|
|
229
|
+
- `import/no-duplicates` (error): 防止重复导入
|
|
230
|
+
- `import/order` (error): 强制导入顺序(内置 → 外部 → 内部)
|
|
231
|
+
|
|
232
|
+
**依赖管理 Dependency Management**
|
|
233
|
+
- 管理模块依赖
|
|
234
|
+
- `import/no-extraneous-dependencies` (error): 防止导入额外的依赖
|
|
235
|
+
- `import/no-cycle` (warn): 对循环依赖发出警告
|
|
236
|
+
|
|
237
|
+
### JSONC 规则 JSONC Rules
|
|
238
|
+
|
|
239
|
+
JSONC 配置包含 JSON 和 JSONC 文件的规则:
|
|
240
|
+
|
|
241
|
+
- 支持 `.json`、`.jsonc`、`.json5` 文件
|
|
242
|
+
- 确保有效的 JSON 语法
|
|
243
|
+
- 强制一致的 JSON 格式
|
|
244
|
+
|
|
245
|
+
### Vue 规则 Vue Rules
|
|
246
|
+
|
|
247
|
+
Vue 配置包含 Vue.js 特定规则:
|
|
248
|
+
|
|
249
|
+
- 支持 `.vue` 单文件组件
|
|
250
|
+
- Vue 3 Composition API 支持
|
|
251
|
+
- 与 TypeScript 集成(当启用 TypeScript 时)
|
|
252
|
+
|
|
253
|
+
### 忽略模式 Ignore Patterns
|
|
254
|
+
|
|
255
|
+
默认忽略模式包括:
|
|
256
|
+
- `node_modules`
|
|
257
|
+
- `dist`
|
|
258
|
+
- 锁文件(`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, `bun.lockb`)
|
|
259
|
+
|
|
260
|
+
## 💡 使用示例 Examples
|
|
261
|
+
|
|
262
|
+
### TypeScript 项目
|
|
263
|
+
|
|
264
|
+
```javascript
|
|
265
|
+
// eslint.config.js
|
|
266
|
+
import { useConfig } from '@purea/eslint-config'
|
|
267
|
+
|
|
268
|
+
export default useConfig({
|
|
269
|
+
typescript: true,
|
|
270
|
+
imports: true
|
|
271
|
+
})
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### 纯 JavaScript 项目
|
|
275
|
+
|
|
276
|
+
```javascript
|
|
277
|
+
// eslint.config.js
|
|
278
|
+
import config from '@purea/eslint-config'
|
|
279
|
+
|
|
280
|
+
export default config()
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### 自定义配置
|
|
284
|
+
|
|
285
|
+
```javascript
|
|
286
|
+
// eslint.config.js
|
|
287
|
+
import { useConfig } from '@purea/eslint-config'
|
|
288
|
+
|
|
289
|
+
export default useConfig({
|
|
290
|
+
typescript: true,
|
|
291
|
+
imports: true,
|
|
292
|
+
ignores: ['dist', 'coverage']
|
|
293
|
+
}, {
|
|
294
|
+
// 覆盖特定规则
|
|
295
|
+
rules: {
|
|
296
|
+
'no-console': 'off',
|
|
297
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
298
|
+
'@stylistic/quotes': 'off' // 禁用特定的代码风格规则
|
|
299
|
+
}
|
|
300
|
+
})
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
JavaScript 和 Stylistic 配置默认启用,但可以通过规则覆盖来自定义特定规则。
|
|
304
|
+
|
|
305
|
+
### Vue 项目
|
|
306
|
+
|
|
307
|
+
```javascript
|
|
308
|
+
// eslint.config.js
|
|
309
|
+
import { useConfig } from '@purea/eslint-config'
|
|
310
|
+
|
|
311
|
+
export default useConfig({
|
|
312
|
+
typescript: true,
|
|
313
|
+
imports: true,
|
|
314
|
+
vue: true,
|
|
315
|
+
jsonc: true
|
|
316
|
+
})
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### 使用独立配置函数
|
|
320
|
+
|
|
321
|
+
```javascript
|
|
322
|
+
// eslint.config.js
|
|
323
|
+
import { javascript, typescript, imports, stylistic, ignores, jsonc, vue } from '@purea/eslint-config'
|
|
324
|
+
|
|
325
|
+
export default [
|
|
326
|
+
ignores(['dist', 'node_modules']),
|
|
327
|
+
javascript(),
|
|
328
|
+
stylistic(),
|
|
329
|
+
typescript(),
|
|
330
|
+
imports(),
|
|
331
|
+
jsonc(),
|
|
332
|
+
vue(),
|
|
333
|
+
{
|
|
334
|
+
rules: {
|
|
335
|
+
'no-console': 'off'
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
]
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## 🔧 技术细节 Technical Details
|
|
342
|
+
|
|
343
|
+
### 动态导入 Dynamic Imports
|
|
344
|
+
|
|
345
|
+
配置使用动态导入以获得更好的性能:
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
const [globals] = await Promise.all([
|
|
349
|
+
importDefault(import('globals')),
|
|
350
|
+
] as const);
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
插件仅在需要时加载,减少初始加载时间。
|
|
354
|
+
|
|
355
|
+
### 异步配置支持 Async Configuration Support
|
|
356
|
+
|
|
357
|
+
ESLint 支持异步配置函数。`useConfig()` 函数返回 `Promise<FlatConfigItem[]>`,ESLint 会自动处理 Promise 解析。在配置文件中无需使用 `await`。
|
|
358
|
+
|
|
359
|
+
### Flat Config 格式 Flat Config Format
|
|
360
|
+
|
|
361
|
+
使用 ESLint 9.x 的 Flat Config 格式,比传统的 `.eslintrc` 文件更灵活。
|
|
362
|
+
|
|
363
|
+
### 可组合设计 Composable Design
|
|
364
|
+
|
|
365
|
+
轻松组合多个配置:
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
export default useConfig({
|
|
369
|
+
typescript: true,
|
|
370
|
+
imports: true,
|
|
371
|
+
}, {
|
|
372
|
+
// 自定义配置
|
|
373
|
+
rules: {
|
|
374
|
+
'no-console': 'off',
|
|
375
|
+
'@stylistic/quotes': 'off' // 可以覆盖默认的stylistic规则
|
|
376
|
+
}
|
|
377
|
+
})
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
JavaScript 和 Stylistic 配置默认启用,TypeScript 和 Imports 配置可通过选项控制。
|
|
381
|
+
|
|
382
|
+
## 📦 依赖 Dependencies
|
|
383
|
+
|
|
384
|
+
### 同伴依赖 Peer Dependencies
|
|
385
|
+
|
|
386
|
+
此配置需要以下同伴依赖:
|
|
387
|
+
|
|
388
|
+
```json
|
|
389
|
+
{
|
|
390
|
+
"eslint": "^9.39.1",
|
|
391
|
+
"typescript": ">=5.0.0"
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
**注意**:TypeScript 是可选的,仅当项目中安装时才会使用。
|
|
396
|
+
|
|
397
|
+
### 运行时依赖 Runtime Dependencies
|
|
398
|
+
- `globals`: 提供全局变量定义
|
|
399
|
+
- `eslint-plugin-import`: 导入组织规则
|
|
400
|
+
- `@stylistic/eslint-plugin`: 代码风格规则
|
|
401
|
+
- `@typescript-eslint/eslint-plugin`: TypeScript 规则
|
|
402
|
+
- `@typescript-eslint/parser`: TypeScript 解析器
|
|
403
|
+
|
|
404
|
+
### 开发依赖 Development Dependencies
|
|
405
|
+
- `eslint@^9.39.1`: ESLint 核心
|
|
406
|
+
- `tsdown`: 构建工具
|
|
407
|
+
- `jiti`: TypeScript 运行时加载器
|
|
408
|
+
- `typescript`: TypeScript 编译器
|
|
409
|
+
|
|
410
|
+
## 🛠️ 开发 Development
|
|
411
|
+
|
|
412
|
+
```bash
|
|
413
|
+
# 安装依赖
|
|
414
|
+
pnpm install
|
|
415
|
+
|
|
416
|
+
# 构建项目
|
|
417
|
+
pnpm run build
|
|
418
|
+
|
|
419
|
+
# 检查代码
|
|
420
|
+
pnpm run lint
|
|
421
|
+
|
|
422
|
+
# 开发模式(监听文件变化)
|
|
423
|
+
pnpm run dev
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
## 📁 项目结构 Project Structure
|
|
427
|
+
|
|
428
|
+
```
|
|
429
|
+
eslint-config/
|
|
430
|
+
├── src/
|
|
431
|
+
│ ├── index.ts # 主入口
|
|
432
|
+
│ ├── factory.ts # 配置工厂
|
|
433
|
+
│ ├── types.ts # TypeScript 类型定义
|
|
434
|
+
│ ├── utils.ts # 工具函数
|
|
435
|
+
│ └── configs/ # 配置模块
|
|
436
|
+
│ ├── ignores.ts # 忽略模式
|
|
437
|
+
│ ├── imports.ts # 导入规则
|
|
438
|
+
│ ├── javascript.ts # JavaScript 基础规则
|
|
439
|
+
│ ├── stylistic.ts # 代码风格规则
|
|
440
|
+
│ └── typescript.ts # TypeScript 规则
|
|
441
|
+
├── eslint.config.ts # 项目自身的 ESLint 配置
|
|
442
|
+
├── tsdown.config.ts # 构建配置
|
|
443
|
+
├── tsconfig.json # TypeScript 配置
|
|
444
|
+
└── package.json # 包配置
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
## 🤝 贡献 Contributing
|
|
448
|
+
|
|
449
|
+
欢迎贡献!请随时提交 Pull Request。
|
|
450
|
+
|
|
451
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
452
|
+
|
|
453
|
+
## 📄 许可证 License
|
|
454
|
+
|
|
455
|
+
MIT License - 详见 [LICENSE](LICENSE) 文件。
|
|
456
|
+
|
|
457
|
+
## 📝 更新日志 Changelog
|
|
458
|
+
|
|
459
|
+
查看 [CHANGELOG.md](CHANGELOG.md) 了解变更列表。
|
|
460
|
+
|
|
461
|
+
---
|
|
462
|
+
|
|
463
|
+
Made with ❤️ by Pure Anin
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Linter } from "eslint";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A type that represents a value that can be either a Promise of T or T itself.
|
|
7
|
+
*/
|
|
8
|
+
type Awaitable<T> = Promise<T> | T;
|
|
9
|
+
/** Configuration options for the ESLint config */
|
|
10
|
+
interface ConfigOptions {
|
|
11
|
+
/**
|
|
12
|
+
* User ignores patterns
|
|
13
|
+
* @default []
|
|
14
|
+
*/
|
|
15
|
+
ignores?: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Enable imports rules
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
imports?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Enable TypeScript rules
|
|
23
|
+
* @default true (if TypeScript is detected in the project)
|
|
24
|
+
*/
|
|
25
|
+
typescript?: boolean | OptionsTypeScriptWithTypes;
|
|
26
|
+
/**
|
|
27
|
+
* Enable JSONC rules
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
jsonc?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Enable Vue rules
|
|
33
|
+
* @default true (if Vue is detected in the project)
|
|
34
|
+
*/
|
|
35
|
+
vue?: boolean | VueOptions;
|
|
36
|
+
}
|
|
37
|
+
type FlatConfigItem = Omit<Linter.Config, 'plugins'> & {
|
|
38
|
+
/**
|
|
39
|
+
* An object containing a name-value mapping of plugin names to plugin objects.
|
|
40
|
+
* When `files` is specified, these plugins are only available to the matching files.
|
|
41
|
+
*
|
|
42
|
+
* @see [Using plugins in your configuration](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#using-plugins-in-your-configuration)
|
|
43
|
+
*/
|
|
44
|
+
plugins?: Record<string, unknown>;
|
|
45
|
+
};
|
|
46
|
+
/** TypeScript options. */
|
|
47
|
+
type TypeScriptOptions = OptionsTypeScriptWithTypes;
|
|
48
|
+
/** Options for TypeScript with types. */
|
|
49
|
+
interface OptionsTypeScriptWithTypes {
|
|
50
|
+
/**
|
|
51
|
+
* When this options is provided, type aware rules will be enabled.
|
|
52
|
+
* @see https://typescript-eslint.io/linting/typed-linting/
|
|
53
|
+
*/
|
|
54
|
+
tsconfigPath?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Override type aware rules.
|
|
57
|
+
*/
|
|
58
|
+
overridesTypeAwareRules?: FlatConfigItem['rules'];
|
|
59
|
+
}
|
|
60
|
+
/** Vue options. */
|
|
61
|
+
interface VueOptions {
|
|
62
|
+
/**
|
|
63
|
+
* Vue version
|
|
64
|
+
* @default 3
|
|
65
|
+
*/
|
|
66
|
+
vueVersion?: 2 | 3;
|
|
67
|
+
/**
|
|
68
|
+
* Override Vue-specific rules.
|
|
69
|
+
*/
|
|
70
|
+
overridesRules?: FlatConfigItem['rules'];
|
|
71
|
+
/**
|
|
72
|
+
* Enable TypeScript rules for Vue SFC
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
typescript?: boolean;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/factory.d.ts
|
|
79
|
+
/**
|
|
80
|
+
* Create ESLint configuration based on provided options
|
|
81
|
+
*
|
|
82
|
+
* @param options - Configuration options
|
|
83
|
+
* @returns Array of ESLint configurations
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* import { useConfig } from '@purea/eslint-config'
|
|
88
|
+
*
|
|
89
|
+
* export default useConfig({
|
|
90
|
+
* typescript: true,
|
|
91
|
+
* })
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare function useConfig(options?: ConfigOptions, ...extraConfigs: Awaitable<FlatConfigItem | FlatConfigItem[] | Linter.Config[]>[]): Promise<FlatConfigItem[]>;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/configs/ignores.d.ts
|
|
97
|
+
declare function ignores(userIgnores?: string[]): FlatConfigItem;
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/configs/imports.d.ts
|
|
100
|
+
declare function imports(): Promise<FlatConfigItem[]>;
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/configs/javascript.d.ts
|
|
103
|
+
declare function javascript(): Promise<FlatConfigItem[]>;
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/configs/typescript.d.ts
|
|
106
|
+
declare function typescript(options?: TypeScriptOptions): Promise<FlatConfigItem[]>;
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/configs/stylistic.d.ts
|
|
109
|
+
declare function stylistic(): Promise<FlatConfigItem[]>;
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/configs/jsonc.d.ts
|
|
112
|
+
declare function jsonc(): Promise<FlatConfigItem[]>;
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/configs/vue.d.ts
|
|
115
|
+
declare function vue(options?: VueOptions): Promise<FlatConfigItem[]>;
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/utils.d.ts
|
|
118
|
+
/**
|
|
119
|
+
* 检查值是否为非空对象
|
|
120
|
+
* @param value - 要检查的值
|
|
121
|
+
* @returns 如果值是非空对象则返回 true,否则返回 false
|
|
122
|
+
*/
|
|
123
|
+
declare const isObject: (value: unknown) => value is Record<string, unknown>;
|
|
124
|
+
/**
|
|
125
|
+
* 导入默认导出
|
|
126
|
+
* @param importable - 动态导入的 Promise
|
|
127
|
+
* @returns 返回模块的默认导出或整个模块对象
|
|
128
|
+
*/
|
|
129
|
+
declare function importDefault<T>(importable: Awaitable<T>): Promise<T extends {
|
|
130
|
+
default: infer U;
|
|
131
|
+
} ? U : T>;
|
|
132
|
+
//#endregion
|
|
133
|
+
export { Awaitable, ConfigOptions, FlatConfigItem, TypeScriptOptions, VueOptions, useConfig as default, useConfig, ignores, importDefault, imports, isObject, javascript, jsonc, stylistic, typescript, vue };
|