@fast-china/eslint-config 1.1.0 → 2.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/CHANGELOG.md +25 -0
- package/README.md +106 -80
- package/README.zh.md +107 -81
- package/dist/index.d.ts +110 -236
- package/dist/index.js +241 -218
- package/dist/index.js.map +1 -1
- package/dist/rules/index.d.ts +41 -36
- package/dist/rules/index.js +62 -48
- package/dist/rules/index.js.map +1 -1
- package/docs/engineering-audit.zh.md +73 -82
- package/docs/rules-risk.md +33 -44
- package/docs/rules-risk.zh.md +34 -45
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,259 +1,133 @@
|
|
|
1
|
-
import
|
|
2
|
-
export {
|
|
3
|
-
import 'eslint';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 公共配置
|
|
7
|
-
* @description 最佳实践
|
|
8
|
-
*/
|
|
9
|
-
declare const createCommonConfigs: (files?: readonly string[]) => eslint_config.Config[];
|
|
10
|
-
declare const commonConfigs: eslint_config.Config[];
|
|
1
|
+
import { R as RuleOptions } from './define-rules-CSwQ8C1q.js';
|
|
2
|
+
export { d as defineRules } from './define-rules-CSwQ8C1q.js';
|
|
3
|
+
import { Config } from 'eslint/config';
|
|
4
|
+
import { Linter } from 'eslint';
|
|
11
5
|
|
|
12
6
|
type RuntimeEnvironment = "browser" | "node" | "universal";
|
|
13
|
-
/**
|
|
14
|
-
* 创建运行时环境相关的 ESLint 配置。
|
|
15
|
-
*
|
|
16
|
-
* 用于为应用源码配置对应运行环境的全局变量,
|
|
17
|
-
* 同时为 Node.js 工程脚本单独启用 Node.js 全局变量。
|
|
18
|
-
*
|
|
19
|
-
* @param environment 运行时环境,默认为浏览器环境
|
|
20
|
-
* @param files 应用源码匹配规则,默认为所有代码文件
|
|
21
|
-
* @returns ESLint Flat Config 配置数组
|
|
22
|
-
*/
|
|
23
|
-
declare const createEnvironmentConfigs: (environment?: RuntimeEnvironment, files?: readonly string[]) => eslint_config.Config[];
|
|
24
|
-
/**
|
|
25
|
-
* 浏览器应用环境配置。
|
|
26
|
-
*
|
|
27
|
-
* 适用于普通 Vue、React 等浏览器端项目。
|
|
28
|
-
*/
|
|
29
|
-
declare const browserConfigs: eslint_config.Config[];
|
|
30
|
-
/**
|
|
31
|
-
* Node.js 应用环境配置。
|
|
32
|
-
*
|
|
33
|
-
* 适用于 Node.js 服务、CLI 工具等项目。
|
|
34
|
-
*/
|
|
35
|
-
declare const nodeConfigs: eslint_config.Config[];
|
|
36
|
-
/**
|
|
37
|
-
* 通用运行环境配置。
|
|
38
|
-
*
|
|
39
|
-
* 同时启用浏览器和 Node.js 全局变量,
|
|
40
|
-
* 适用于 SSR、同构应用或跨运行时共享代码。
|
|
41
|
-
*/
|
|
42
|
-
declare const universalConfigs: eslint_config.Config[];
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 忽略配置
|
|
46
|
-
*/
|
|
47
|
-
declare const globalIgnoresConfigs: eslint_config.Config[];
|
|
48
|
-
declare const gitignoreConfigs: eslint_config.Config[];
|
|
49
|
-
declare const ignoresConfigs: eslint_config.Config[];
|
|
50
7
|
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
*/
|
|
54
|
-
declare const createImportConfigs: (files?: readonly string[]) => eslint_config.Config[];
|
|
55
|
-
declare const importConfigs: eslint_config.Config[];
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* JavaScript配置
|
|
59
|
-
*/
|
|
60
|
-
declare const javascriptConfigs: eslint_config.Config[];
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Json配置
|
|
64
|
-
*/
|
|
65
|
-
declare const jsonConfigs: eslint_config.Config[];
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* markdown配置
|
|
69
|
-
*/
|
|
70
|
-
declare const markdownConfigs: eslint_config.Config[];
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* prettier配置
|
|
74
|
-
*/
|
|
75
|
-
declare const prettierConfigs: eslint_config.Config[];
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* regexp配置
|
|
79
|
-
*/
|
|
80
|
-
declare const createRegexpConfigs: (files?: readonly string[]) => eslint_config.Config[];
|
|
81
|
-
declare const regexpConfigs: eslint_config.Config[];
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* package.json 属性排序
|
|
85
|
-
*/
|
|
86
|
-
declare const packageJsonSortConfigs: eslint_config.Config[];
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* tsconfig.json 属性排序
|
|
90
|
-
*/
|
|
91
|
-
declare const tsconfigJsonSortConfigs: eslint_config.Config[];
|
|
8
|
+
/** 项目允许使用的 Lodash 导入来源。 */
|
|
9
|
+
type LodashPreference = "lodash" | "lodash-unified";
|
|
92
10
|
|
|
93
11
|
interface TypeScriptConfigOptions {
|
|
12
|
+
/**
|
|
13
|
+
* 是否启用依赖 TypeScript 类型信息的规则;开启后会增加启动和检查成本。
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
94
16
|
typeChecked?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 查找 tsconfig.json 的根目录。
|
|
19
|
+
*
|
|
20
|
+
* typescript-eslint 通常可从 `eslint.config.*` 调用栈推断;复杂 monorepo 可显式传入
|
|
21
|
+
* `import.meta.dirname`,避免从错误目录启动 Project Service。
|
|
22
|
+
* @default undefined
|
|
23
|
+
*/
|
|
24
|
+
tsconfigRootDir?: string;
|
|
95
25
|
}
|
|
96
|
-
/**
|
|
97
|
-
* TypeScript 核心配置
|
|
98
|
-
*/
|
|
99
|
-
declare const createTypeScriptCoreConfigs: ({ typeChecked }?: TypeScriptConfigOptions) => eslint_config.Config[];
|
|
100
|
-
declare const typescriptCoreConfigs: eslint_config.Config[];
|
|
101
|
-
/**
|
|
102
|
-
* TypeScript配置
|
|
103
|
-
*/
|
|
104
|
-
declare const createTypeScriptConfigs: (options?: TypeScriptConfigOptions) => eslint_config.Config[];
|
|
105
|
-
declare const typescriptConfigs: eslint_config.Config[];
|
|
106
|
-
declare const typescriptTypeCheckedConfigs: eslint_config.Config[];
|
|
107
|
-
|
|
108
|
-
interface VueConfigOptions {
|
|
109
|
-
typeChecked?: boolean;
|
|
110
|
-
version?: 2 | 3;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* vue配置
|
|
114
|
-
*/
|
|
115
|
-
declare const createVueConfigs: ({ typeChecked, version }?: VueConfigOptions) => eslint_config.Config[];
|
|
116
|
-
declare const vueConfigs: eslint_config.Config[];
|
|
117
|
-
declare const vue2Configs: eslint_config.Config[];
|
|
118
|
-
declare const vueTypeCheckedConfigs: eslint_config.Config[];
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* JS
|
|
122
|
-
*/
|
|
123
|
-
declare const CONST_JS = "**/*.?([cm])js";
|
|
124
|
-
/**
|
|
125
|
-
* JSX
|
|
126
|
-
*/
|
|
127
|
-
declare const CONST_JSX = "**/*.?([cm])jsx";
|
|
128
|
-
/**
|
|
129
|
-
* TS
|
|
130
|
-
*/
|
|
131
|
-
declare const CONST_TS = "**/*.?([cm])ts";
|
|
132
|
-
/**
|
|
133
|
-
* TSX
|
|
134
|
-
*/
|
|
135
|
-
declare const CONST_TSX = "**/*.?([cm])tsx";
|
|
136
|
-
/**
|
|
137
|
-
* .d.ts
|
|
138
|
-
*/
|
|
139
|
-
declare const CONST_DTS = "**/*.d.ts";
|
|
140
|
-
/**
|
|
141
|
-
* JSON
|
|
142
|
-
*/
|
|
143
|
-
declare const CONST_JSON = "**/*.json";
|
|
144
|
-
/**
|
|
145
|
-
* JSONC
|
|
146
|
-
*/
|
|
147
|
-
declare const CONST_JSONC = "**/*.jsonc";
|
|
148
|
-
/**
|
|
149
|
-
* JSON5
|
|
150
|
-
*/
|
|
151
|
-
declare const CONST_JSON5 = "**/*.json5";
|
|
152
|
-
/**
|
|
153
|
-
* MD
|
|
154
|
-
*/
|
|
155
|
-
declare const CONST_MD = "**/*.md";
|
|
156
|
-
/**
|
|
157
|
-
* VUE
|
|
158
|
-
*/
|
|
159
|
-
declare const CONST_VUE = "**/*.vue";
|
|
160
|
-
/**
|
|
161
|
-
* YAML
|
|
162
|
-
*/
|
|
163
|
-
declare const CONST_YAML = "**/*.y?(a)ml";
|
|
164
|
-
/**
|
|
165
|
-
* node_modules
|
|
166
|
-
*/
|
|
167
|
-
declare const CONST_NODE_MODULES = "**/node_modules/**";
|
|
168
|
-
/**
|
|
169
|
-
* 打包目录 dist
|
|
170
|
-
*/
|
|
171
|
-
declare const CONST_DIST = "**/dist/**";
|
|
172
|
-
/**
|
|
173
|
-
* 包管理 lock 文件
|
|
174
|
-
*/
|
|
175
|
-
declare const CONST_LOCKFILE: string[];
|
|
176
|
-
/**
|
|
177
|
-
* public
|
|
178
|
-
*/
|
|
179
|
-
declare const CONST_PUBLIC = "**/public";
|
|
180
|
-
/**
|
|
181
|
-
* TS 配置文件
|
|
182
|
-
*/
|
|
183
|
-
declare const CONST_TSCONFIG: string[];
|
|
184
|
-
/** JavaScript 文件 */
|
|
185
|
-
declare const GLOB_JAVASCRIPT: readonly ["**/*.?([cm])js", "**/*.?([cm])jsx"];
|
|
186
|
-
/** TypeScript 文件 */
|
|
187
|
-
declare const GLOB_TYPESCRIPT: readonly ["**/*.?([cm])ts", "**/*.?([cm])tsx"];
|
|
188
|
-
/** ESLint 可处理的源码文件 */
|
|
189
|
-
declare const GLOB_CODE: readonly ["**/*.?([cm])js", "**/*.?([cm])jsx", "**/*.?([cm])ts", "**/*.?([cm])tsx", "**/*.vue"];
|
|
190
|
-
/** 默认按 Node.js 环境处理的工程文件 */
|
|
191
|
-
declare const GLOB_NODE: readonly ["**/*.{config,setup}.{js,cjs,mjs,ts,cts,mts}", "**/{scripts,bin}/**/*.{js,cjs,mjs,ts,cts,mts}", "**/{test,tests}/**/*.{js,cjs,mjs,ts,cts,mts}", "**/cli.{js,cjs,mjs,ts,cts,mts}"];
|
|
192
26
|
|
|
193
27
|
interface FastConfigOptions {
|
|
194
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* 应用代码的运行环境;Vue/Vite 项目通常使用 `browser`。
|
|
30
|
+
* @default "browser"
|
|
31
|
+
*/
|
|
195
32
|
environment?: RuntimeEnvironment;
|
|
196
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* 项目额外提供的全局变量,例如测试运行器或宿主平台 API。
|
|
35
|
+
* @default undefined
|
|
36
|
+
*/
|
|
37
|
+
globals?: Linter.Globals;
|
|
38
|
+
/**
|
|
39
|
+
* 是否读取项目根目录的 .gitignore。
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
197
42
|
gitignore?: boolean;
|
|
198
|
-
/**
|
|
199
|
-
|
|
200
|
-
|
|
43
|
+
/**
|
|
44
|
+
* 追加到内置集合的全局忽略模式。
|
|
45
|
+
* @default []
|
|
46
|
+
*/
|
|
47
|
+
ignores?: readonly string[];
|
|
48
|
+
/**
|
|
49
|
+
* 是否启用 import-x 规则。
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
201
52
|
imports?: boolean;
|
|
202
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* 是否处理 JavaScript 与 JSX 文件。
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
javascript?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* 是否启用 JSON、JSONC 与 JSON5 推荐规则;清单排序由独立选项控制。
|
|
60
|
+
* @default true
|
|
61
|
+
*/
|
|
203
62
|
json?: boolean;
|
|
204
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* 统一项目使用的 Lodash 包;`false` 表示不限制 `lodash`、`lodash-es` 或 `lodash-unified`。
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
lodash?: false | LodashPreference;
|
|
68
|
+
/**
|
|
69
|
+
* 是否启用 Markdown 规则。
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
205
72
|
markdown?: boolean;
|
|
206
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* 是否在末尾关闭与 Prettier 冲突的格式规则。
|
|
75
|
+
* @default true
|
|
76
|
+
*/
|
|
207
77
|
prettier?: boolean;
|
|
208
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* 是否启用正则表达式规则。
|
|
80
|
+
* @default true
|
|
81
|
+
*/
|
|
209
82
|
regexp?: boolean;
|
|
210
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* 应用于全部已启用代码文件的项目级规则,提供精确规则名与选项类型。
|
|
85
|
+
* @default undefined
|
|
86
|
+
*/
|
|
87
|
+
rules?: RuleOptions;
|
|
88
|
+
/**
|
|
89
|
+
* 是否按安全的固定顺序整理 package.json;启用后首次运行可能产生较大 diff。
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
sortPackageJson?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* 是否按 TypeScript 文档主题整理 tsconfig*.json。
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
sortTsconfig?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* TypeScript 支持;传入对象可开启类型感知规则。
|
|
100
|
+
* @default true
|
|
101
|
+
*/
|
|
211
102
|
typescript?: boolean | TypeScriptConfigOptions;
|
|
212
|
-
/**
|
|
213
|
-
|
|
103
|
+
/**
|
|
104
|
+
* 是否启用 Vue 3 单文件组件支持。
|
|
105
|
+
* @default true
|
|
106
|
+
*/
|
|
107
|
+
vue?: boolean;
|
|
214
108
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
109
|
+
/** `fastConfig()` 使用的稳定默认值;对象被冻结,避免运行时被意外修改。 */
|
|
110
|
+
declare const defaultConfigOptions: Readonly<{
|
|
111
|
+
readonly environment: "browser";
|
|
112
|
+
readonly gitignore: true;
|
|
113
|
+
readonly imports: true;
|
|
114
|
+
readonly javascript: true;
|
|
115
|
+
readonly json: true;
|
|
116
|
+
readonly lodash: false;
|
|
117
|
+
readonly markdown: true;
|
|
118
|
+
readonly prettier: true;
|
|
119
|
+
readonly regexp: true;
|
|
120
|
+
readonly sortPackageJson: false;
|
|
121
|
+
readonly sortTsconfig: false;
|
|
122
|
+
readonly typescript: true;
|
|
123
|
+
readonly vue: true;
|
|
225
124
|
}>;
|
|
226
125
|
/**
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* 返回普通配置数组,可直接展开,也可继续通过 defineConfig 追加项目规则。
|
|
230
|
-
*/
|
|
231
|
-
declare const createConfig: (options?: FastConfigOptions) => eslint_config.Config[];
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* JavaScript 预置配置
|
|
235
|
-
*
|
|
236
|
-
* @description ignores,common,javascript,import,regexp
|
|
237
|
-
*/
|
|
238
|
-
declare const PresetJavascriptConfigs: eslint_config.Config[];
|
|
239
|
-
/**
|
|
240
|
-
* JSON 预置配置
|
|
241
|
-
*/
|
|
242
|
-
declare const PresetJsonConfigs: eslint_config.Config[];
|
|
243
|
-
/**
|
|
244
|
-
* TypeScript 预置配置(不包含 Vue、JSON 和 Markdown)。
|
|
245
|
-
*/
|
|
246
|
-
declare const PresetTypescriptConfigs: eslint_config.Config[];
|
|
247
|
-
declare const PresetTypeScriptConfigs: eslint_config.Config[];
|
|
248
|
-
/**
|
|
249
|
-
* 基础预置配置
|
|
126
|
+
* 创建面向 Vue 3、Vite、TypeScript、JavaScript 与 Node.js 项目的 ESLint Flat Config。
|
|
250
127
|
*
|
|
251
|
-
*
|
|
252
|
-
|
|
253
|
-
declare const PresetBasicConfigs: eslint_config.Config[];
|
|
254
|
-
/**
|
|
255
|
-
* Vue 3 + TypeScript 完整预置配置。
|
|
128
|
+
* 默认导出就是此函数。额外配置参数会放在内置配置之后,因此项目可以按文件范围
|
|
129
|
+
* 覆盖任何默认规则,而无需再次调用 ESLint 的 `defineConfig()`。
|
|
256
130
|
*/
|
|
257
|
-
declare const
|
|
131
|
+
declare const fastConfig: (options?: FastConfigOptions, ...overrides: Config[]) => Config[];
|
|
258
132
|
|
|
259
|
-
export {
|
|
133
|
+
export { type FastConfigOptions, type LodashPreference, RuleOptions, type RuntimeEnvironment, type TypeScriptConfigOptions, fastConfig as default, defaultConfigOptions, fastConfig };
|