@pawover/kit-eslint-rules 0.1.0 → 0.2.0-alpha.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/dist/index.d.ts +272 -31
- package/dist/index.js +367 -81
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,82 +1,273 @@
|
|
|
1
|
+
import { FlatConfigComposer } from "eslint-flat-config-utils";
|
|
1
2
|
import { Linter } from "eslint";
|
|
3
|
+
/**
|
|
4
|
+
* React Compiler 规则预设
|
|
5
|
+
*
|
|
6
|
+
* - `"recommended"`:eslint-plugin-react-hooks 官方稳定预设
|
|
7
|
+
* - `"latest"`:官方实验预设,额外包含 `react-hooks/void-use-memo`
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const preset: ReactCompilerPreset = "latest";
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
type ReactCompilerPreset = "recommended" | "latest";
|
|
15
|
+
/**
|
|
16
|
+
* flat config 规则表类型(规则映射统一转换的目标类型)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import type { RuleMap } from "@pawover/kit-eslint-rules";
|
|
21
|
+
*
|
|
22
|
+
* const rules: RuleMap = { "no-console": "error" };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
type RuleMap = NonNullable<Linter.Config["rules"]>;
|
|
26
|
+
/**
|
|
27
|
+
* 单个 flat config 配置层
|
|
28
|
+
*
|
|
29
|
+
* 每个配置层都带唯一 `name`,可配合 composer 的 `override(name, config)` 精确定位并覆盖。
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import type { ConfigLayer } from "@pawover/kit-eslint-rules";
|
|
34
|
+
*
|
|
35
|
+
* const layer: ConfigLayer = {
|
|
36
|
+
* name: "custom/rules",
|
|
37
|
+
* rules: { "no-console": "error" },
|
|
38
|
+
* };
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
type ConfigLayer = Linter.Config;
|
|
42
|
+
/** 层名字典:预设产出的全部唯一配置层名称。 */
|
|
43
|
+
declare const LAYER_NAMES: {
|
|
44
|
+
readonly ignores: "pawover/ignores";
|
|
45
|
+
readonly javascript: {
|
|
46
|
+
readonly parser: "pawover/javascript/parser";
|
|
47
|
+
readonly rules: "pawover/javascript/rules";
|
|
48
|
+
};
|
|
49
|
+
readonly typescript: {
|
|
50
|
+
readonly setup: "pawover/typescript/setup";
|
|
51
|
+
readonly parser: "pawover/typescript/parser";
|
|
52
|
+
readonly rules: "pawover/typescript/rules";
|
|
53
|
+
readonly typeAware: "pawover/typescript/type-aware";
|
|
54
|
+
};
|
|
55
|
+
readonly stylistic: {
|
|
56
|
+
readonly setup: "pawover/stylistic/setup";
|
|
57
|
+
readonly rules: "pawover/stylistic/rules";
|
|
58
|
+
};
|
|
59
|
+
readonly antfu: {
|
|
60
|
+
readonly setup: "pawover/antfu/setup";
|
|
61
|
+
readonly rules: "pawover/antfu/rules";
|
|
62
|
+
};
|
|
63
|
+
readonly imports: {
|
|
64
|
+
readonly setup: "pawover/imports/setup";
|
|
65
|
+
readonly rules: "pawover/imports/rules";
|
|
66
|
+
};
|
|
67
|
+
readonly importsSort: {
|
|
68
|
+
readonly setup: "pawover/imports-sort/setup";
|
|
69
|
+
readonly rules: "pawover/imports-sort/rules";
|
|
70
|
+
};
|
|
71
|
+
readonly react: {
|
|
72
|
+
readonly setup: "pawover/react/setup";
|
|
73
|
+
readonly rules: "pawover/react/rules";
|
|
74
|
+
readonly typeAware: "pawover/react/type-aware";
|
|
75
|
+
};
|
|
76
|
+
readonly vue: {
|
|
77
|
+
readonly setup: "pawover/vue/setup";
|
|
78
|
+
readonly parser: "pawover/vue/parser";
|
|
79
|
+
readonly rules: "pawover/vue/rules";
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
/** 递归提取对象字面量的全部值类型。 */
|
|
83
|
+
type DeepValue<T> = T extends object ? { [K in keyof T]: DeepValue<T[K]>; }[keyof T] : T;
|
|
84
|
+
/**
|
|
85
|
+
* 各配置层名称
|
|
86
|
+
*
|
|
87
|
+
* 每层配置都带唯一 `name`,可配合 composer 的 `override(name, config)` 精确定位并覆盖。
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import type { ConfigNames } from "@pawover/kit-eslint-rules";
|
|
92
|
+
*
|
|
93
|
+
* const name: ConfigNames = "pawover/typescript/rules";
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
type ConfigNames = DeepValue<typeof LAYER_NAMES>;
|
|
97
|
+
/**
|
|
98
|
+
* 用户追加的 flat config
|
|
99
|
+
*
|
|
100
|
+
* 可以是单个配置对象、配置数组、composer,或配置数组的 Promise。
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import type { PawoverUserConfig } from "@pawover/kit-eslint-rules";
|
|
105
|
+
*
|
|
106
|
+
* const config: PawoverUserConfig = { rules: { "no-console": "error" } };
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
type PawoverUserConfig = ConfigLayer | ConfigLayer[] | FlatConfigComposer<any> | Promise<ConfigLayer[]>;
|
|
110
|
+
/**
|
|
111
|
+
* 规则组覆盖选项
|
|
112
|
+
*
|
|
113
|
+
* 覆盖规则会与预设规则表合并,同名规则以 `overrides` 为准。
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const options: RulesOverrideOptions = {
|
|
118
|
+
* overrides: { "ts/consistent-type-definitions": ["error", "interface"] },
|
|
119
|
+
* };
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
interface RulesOverrideOptions {
|
|
123
|
+
/** 覆盖该规则组的规则(与预设规则表浅合并,同名规则以本参数为准) */
|
|
124
|
+
overrides?: RuleMap;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* TypeScript 规则组选项
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const options: TypeScriptOptions = {
|
|
132
|
+
* overrides: { "ts/consistent-type-definitions": ["error", "interface"] },
|
|
133
|
+
* overridesTypeAware: { "ts/no-unsafe-assignment": "warn" },
|
|
134
|
+
* parserOptions: { tsconfigRootDir: import.meta.dirname },
|
|
135
|
+
* };
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
interface TypeScriptOptions extends RulesOverrideOptions {
|
|
139
|
+
/** 仅覆盖类型感知规则(作用于 `filesTypeAware` 限定的文件) */
|
|
140
|
+
overridesTypeAware?: RuleMap;
|
|
141
|
+
/** 类型感知规则的文件范围;默认 {@link GLOB_TYPESCRIPT} */
|
|
142
|
+
filesTypeAware?: string[];
|
|
143
|
+
/** 透传给 TypeScript parser 的解析选项;与默认值浅合并,同名键以本参数为准 */
|
|
144
|
+
parserOptions?: Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* React 规则组选项
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const options: ReactOptions = {
|
|
152
|
+
* compiler: "latest",
|
|
153
|
+
* overrides: { "react/no-implicit-key": "warn" },
|
|
154
|
+
* overridesTypeAware: { "react/no-unused-props": "off" },
|
|
155
|
+
* };
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
interface ReactOptions extends RulesOverrideOptions {
|
|
159
|
+
/**
|
|
160
|
+
* React Compiler 规则切换
|
|
161
|
+
*
|
|
162
|
+
* react 组启用时默认开启(`true` 等价 `"recommended"`):将 10 条与 `@eslint-react` 重叠的
|
|
163
|
+
* Compiler 规则切换为 `eslint-plugin-react-hooks` 官方实现,并关闭 `@eslint-react` 等价规则;
|
|
164
|
+
* 同时关闭 `react/no-unstable-context-value`(React Compiler 会自动记忆化 Context value);
|
|
165
|
+
* 传 `false` 回退到 `@eslint-react` 实现,传 `"latest"` 额外启用实验性 `react-hooks/void-use-memo`。
|
|
166
|
+
*
|
|
167
|
+
* 仅控制这 10 条重叠规则;官方独有的 `config` / `gating` / `incompatible-library` /
|
|
168
|
+
* `preserve-manual-memoization` 始终由 `react-hooks` 提供。
|
|
169
|
+
*
|
|
170
|
+
* @default true
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const options: ReactOptions = { compiler: "latest" };
|
|
175
|
+
* const legacy: ReactOptions = { compiler: false };
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
compiler?: boolean | ReactCompilerPreset;
|
|
179
|
+
/** 仅覆盖依赖类型信息的 react 规则(仅在开启 `typescript` 时生效) */
|
|
180
|
+
overridesTypeAware?: RuleMap;
|
|
181
|
+
}
|
|
2
182
|
/**
|
|
3
183
|
* 预设工厂选项
|
|
4
184
|
*
|
|
5
|
-
* 除 `javascript`
|
|
185
|
+
* 除 `javascript` 规则组常开外,其余规则组均通过对应字段显式开启。
|
|
186
|
+
* 每个规则组都接受 `{ overrides }` 形式,在预设内部完成规则覆盖,避免后置配置层与 flat config 插件作用域的问题。
|
|
6
187
|
*
|
|
7
188
|
* @example
|
|
8
189
|
* ```ts
|
|
9
190
|
* const options: PawoverOptions = {
|
|
10
|
-
* typescript:
|
|
191
|
+
* typescript: {
|
|
192
|
+
* overrides: { "ts/strict-void-return": [1, { allowReturnAny: true }] },
|
|
193
|
+
* },
|
|
11
194
|
* react: true,
|
|
12
|
-
* parserOptions: { tsconfigRootDir: import.meta.dirname },
|
|
13
195
|
* };
|
|
14
196
|
* ```
|
|
15
197
|
*/
|
|
16
198
|
interface PawoverOptions {
|
|
199
|
+
/** javascript 规则组覆盖选项(该组常开) */
|
|
200
|
+
javascript?: RulesOverrideOptions;
|
|
17
201
|
/** 启用 `typescript` 规则组(ts / tsx 文件;同时注册 TypeScript parser,默认启用 type-aware 解析) */
|
|
18
|
-
typescript?: boolean;
|
|
202
|
+
typescript?: boolean | TypeScriptOptions;
|
|
19
203
|
/** 启用 `stylistic` 规则组 */
|
|
20
|
-
stylistic?: boolean;
|
|
204
|
+
stylistic?: boolean | RulesOverrideOptions;
|
|
21
205
|
/** 启用 `antfu` 规则组 */
|
|
22
|
-
antfu?: boolean;
|
|
206
|
+
antfu?: boolean | RulesOverrideOptions;
|
|
23
207
|
/** 启用 `imports` 规则组(eslint-plugin-import-lite) */
|
|
24
|
-
imports?: boolean;
|
|
208
|
+
imports?: boolean | RulesOverrideOptions;
|
|
25
209
|
/** 启用 `importsSort` 规则组(eslint-plugin-simple-import-sort) */
|
|
26
|
-
importsSort?: boolean;
|
|
27
|
-
/** 启用 `react` 规则组(注册 `@eslint-react` 与 `eslint-plugin-react-hooks`
|
|
28
|
-
react?: boolean;
|
|
210
|
+
importsSort?: boolean | RulesOverrideOptions;
|
|
211
|
+
/** 启用 `react` 规则组(注册 `@eslint-react` 与 `eslint-plugin-react-hooks` 两个插件,默认开启 React Compiler 规则切换);与 `typescript` 同开时,依赖类型信息的规则作用于 ts/tsx/jsx */
|
|
212
|
+
react?: boolean | ReactOptions;
|
|
29
213
|
/** 启用 `vue` 规则组(vue / vue+ts 单文件组件;同时接入 vue-eslint-parser) */
|
|
30
|
-
vue?: boolean;
|
|
31
|
-
/** 透传给 TypeScript parser 的解析选项;与默认值浅合并,同名键以本参数为准(默认 `{ projectService: true }`) */
|
|
32
|
-
parserOptions?: Record<string, unknown>;
|
|
214
|
+
vue?: boolean | RulesOverrideOptions;
|
|
33
215
|
}
|
|
34
216
|
/**
|
|
35
217
|
* 创建 ESLint flat config 预设
|
|
36
218
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
219
|
+
* 返回 composer(继承 Promise,可直接用于 `eslint.config.js` 的默认导出),也可链式调用
|
|
220
|
+
* `append` / `prepend` / `override` / `renamePlugins` 等能力继续组合。
|
|
221
|
+
*
|
|
222
|
+
* 各规则组拆为 `setup` 层(只注册插件,不带 `files`)、`parser` 层(解析器)与
|
|
223
|
+
* `rules` / `type-aware` 层(规则与文件范围),因此后置配置可以直接使用预设已注册的插件规则;
|
|
224
|
+
* 若需注册自定义插件,在自己的配置层中挂载即可。
|
|
39
225
|
*
|
|
40
|
-
* @param options
|
|
41
|
-
* @
|
|
226
|
+
* @param options 预设选项;缺省时返回忽略层与 `javascript` parser/rules 层
|
|
227
|
+
* @param userConfigs 追加在预设之后的 flat config(单个对象、数组、composer 或 Promise)
|
|
228
|
+
* @returns 可直接导出或继续链式组合的 flat config composer
|
|
42
229
|
*
|
|
43
230
|
* @example
|
|
44
231
|
* ```ts
|
|
45
|
-
* // TypeScript + React
|
|
46
|
-
* import pawover from "@pawover/kit
|
|
232
|
+
* // TypeScript + React 项目,使用按组 overrides 覆盖规则
|
|
233
|
+
* import pawover from "@pawover/kit/eslint-rules";
|
|
47
234
|
*
|
|
48
235
|
* export default pawover({
|
|
49
|
-
* typescript:
|
|
236
|
+
* typescript: {
|
|
237
|
+
* overrides: { "ts/strict-void-return": [1, { allowReturnAny: true }] },
|
|
238
|
+
* },
|
|
50
239
|
* react: true,
|
|
51
|
-
* parserOptions: { tsconfigRootDir: import.meta.dirname },
|
|
52
240
|
* });
|
|
53
241
|
* ```
|
|
54
242
|
*
|
|
55
243
|
* @example
|
|
56
244
|
* ```ts
|
|
57
|
-
* //
|
|
245
|
+
* // 追加自定义配置层
|
|
58
246
|
* import pawover from "@pawover/kit-eslint-rules";
|
|
59
247
|
*
|
|
60
|
-
* export default pawover(
|
|
248
|
+
* export default pawover(
|
|
249
|
+
* { typescript: true },
|
|
250
|
+
* { rules: { "no-console": "error" } },
|
|
251
|
+
* );
|
|
61
252
|
* ```
|
|
62
253
|
*
|
|
63
254
|
* @example
|
|
64
255
|
* ```ts
|
|
65
|
-
* //
|
|
256
|
+
* // 按层名称覆盖
|
|
66
257
|
* import pawover from "@pawover/kit-eslint-rules";
|
|
67
258
|
*
|
|
68
|
-
* export default
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
259
|
+
* export default pawover({ typescript: true })
|
|
260
|
+
* .override("pawover/typescript/rules", {
|
|
261
|
+
* rules: { "ts/consistent-type-definitions": ["error", "interface"] },
|
|
262
|
+
* });
|
|
72
263
|
* ```
|
|
73
264
|
*/
|
|
74
|
-
declare function pawover(options?: PawoverOptions
|
|
265
|
+
declare function pawover(options?: PawoverOptions, ...userConfigs: PawoverUserConfig[]): FlatConfigComposer<ConfigLayer, ConfigNames>;
|
|
75
266
|
/**
|
|
76
267
|
* 全局忽略目录列表
|
|
77
268
|
*
|
|
78
269
|
* 在 ESLint 配置中直接忽略的目录与文件 glob 集合,包含依赖、构建产物、锁文件、编辑器目录、缓存等。
|
|
79
|
-
* 预设工厂(`src/config.ts
|
|
270
|
+
* 预设工厂(`src/config.ts`)将其作为 `pawover/ignores` 配置层的 `ignores` 值。
|
|
80
271
|
*
|
|
81
272
|
* @example
|
|
82
273
|
* ```ts
|
|
@@ -89,6 +280,56 @@ declare function pawover(options?: PawoverOptions): Linter.Config[];
|
|
|
89
280
|
* ```
|
|
90
281
|
*/
|
|
91
282
|
declare const GLOB_EXCLUDE: string[];
|
|
283
|
+
/**
|
|
284
|
+
* 全部源文件(js / cjs / mjs / jsx / ts / tsx)
|
|
285
|
+
*
|
|
286
|
+
* 各规则组共享的基础文件范围;启用 `vue` 时工厂会在其后追加 {@link GLOB_VUE}。
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* import { GLOB_SOURCE, GLOB_VUE } from "@pawover/kit-eslint-rules";
|
|
291
|
+
*
|
|
292
|
+
* const files = [...GLOB_SOURCE, GLOB_VUE];
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
declare const GLOB_SOURCE: string[];
|
|
296
|
+
/**
|
|
297
|
+
* TypeScript 源文件(ts / tsx)
|
|
298
|
+
*
|
|
299
|
+
* 类型感知规则与 TypeScript parser 的默认作用范围;后置覆盖 `ts/*` 类型感知规则时应使用该常量限定 `files`。
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* import { GLOB_TYPESCRIPT } from "@pawover/kit-eslint-rules";
|
|
304
|
+
*
|
|
305
|
+
* const files = GLOB_TYPESCRIPT;
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
declare const GLOB_TYPESCRIPT: string[];
|
|
309
|
+
/**
|
|
310
|
+
* Vue 单文件组件
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```ts
|
|
314
|
+
* import { GLOB_VUE } from "@pawover/kit-eslint-rules";
|
|
315
|
+
*
|
|
316
|
+
* const files = [GLOB_VUE];
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
declare const GLOB_VUE = "**/*.vue";
|
|
320
|
+
/**
|
|
321
|
+
* JSX 组件文件
|
|
322
|
+
*
|
|
323
|
+
* react 的 type-aware 规则在启用 `typescript` 时作用于 jsx;类型是否可用由项目 tsconfig 的 include / allowJs 决定。
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```ts
|
|
327
|
+
* import { GLOB_JSX } from "@pawover/kit-eslint-rules";
|
|
328
|
+
*
|
|
329
|
+
* const files = [GLOB_JSX];
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
declare const GLOB_JSX = "**/*.jsx";
|
|
92
333
|
/**
|
|
93
334
|
* 规则严重级别(数字形式)
|
|
94
335
|
*
|
|
@@ -137,4 +378,4 @@ export type Severity = SeverityName | SeverityLevel;
|
|
|
137
378
|
* ```
|
|
138
379
|
*/
|
|
139
380
|
export type RuleConfig<RuleOptions extends unknown[] = unknown[]> = Severity | [Severity, ...Partial<RuleOptions>];
|
|
140
|
-
export { GLOB_EXCLUDE, type PawoverOptions, pawover as default };
|
|
381
|
+
export { type ConfigLayer, type ConfigNames, GLOB_EXCLUDE, GLOB_JSX, GLOB_SOURCE, GLOB_TYPESCRIPT, GLOB_VUE, type PawoverOptions, type PawoverUserConfig, type ReactCompilerPreset, type ReactOptions, type RuleMap, type RulesOverrideOptions, type TypeScriptOptions, pawover as default };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { composer } from "eslint-flat-config-utils";
|
|
1
2
|
import eslintReact from "@eslint-react/eslint-plugin";
|
|
2
3
|
import stylistic from "@stylistic/eslint-plugin";
|
|
3
4
|
import antfu from "eslint-plugin-antfu";
|
|
@@ -16,6 +17,8 @@ import typescriptEslint from "typescript-eslint";
|
|
|
16
17
|
var preset_default = {
|
|
17
18
|
/** 缩进大小 */
|
|
18
19
|
indent: 2,
|
|
20
|
+
/** 常规文件行宽 */
|
|
21
|
+
printWidth: 120,
|
|
19
22
|
/** TypeScript 类成员排序 */
|
|
20
23
|
tsMemberOrder: [
|
|
21
24
|
"signature",
|
|
@@ -175,7 +178,12 @@ const rules$8 = {
|
|
|
175
178
|
* @descEN Enforce multiline objects, arrays and ternaries when they are complex
|
|
176
179
|
* @see https://github.com/antfu/eslint-plugin-antfu/blob/main/src/rules/reasonable-newline.md
|
|
177
180
|
*/
|
|
178
|
-
"antfu/reasonable-newline":
|
|
181
|
+
"antfu/reasonable-newline": [2, {
|
|
182
|
+
minObjectProperties: 4,
|
|
183
|
+
objectLineLength: preset_default.printWidth,
|
|
184
|
+
minArrayItems: 4,
|
|
185
|
+
arrayLineLength: preset_default.printWidth
|
|
186
|
+
}],
|
|
179
187
|
/**
|
|
180
188
|
* @desc 强制顶层函数使用 function 关键字声明
|
|
181
189
|
* @descEN Enforce top-level functions to be declared with the `function` keyword
|
|
@@ -1508,7 +1516,7 @@ const rules$4 = {
|
|
|
1508
1516
|
* @descEN Validates against assignment/mutation of globals during render
|
|
1509
1517
|
* @see https://www.eslint-react.xyz/docs/rules/globals
|
|
1510
1518
|
*/
|
|
1511
|
-
"react/globals":
|
|
1519
|
+
"react/globals": 2,
|
|
1512
1520
|
/**
|
|
1513
1521
|
* @desc 禁止修改 props、state 等不可变值
|
|
1514
1522
|
* @descEN Validates against mutating props, state, and other values that are immutable
|
|
@@ -2074,7 +2082,7 @@ const rules$3 = {
|
|
|
2074
2082
|
* @descEN Validates against usage of libraries which are incompatible with memoization
|
|
2075
2083
|
* @see https://react.dev/reference/eslint-plugin-react-hooks/lints/incompatible-library
|
|
2076
2084
|
*/
|
|
2077
|
-
"react-hooks/incompatible-library":
|
|
2085
|
+
"react-hooks/incompatible-library": 1,
|
|
2078
2086
|
/**
|
|
2079
2087
|
* @desc 验证现有手动的记忆化被编译器保留
|
|
2080
2088
|
* @descEN Validates that existing manual memoization is preserved by the compiler
|
|
@@ -2122,7 +2130,13 @@ const rules$3 = {
|
|
|
2122
2130
|
* @descEN Validates usage of the useMemo hook without a return value
|
|
2123
2131
|
* @see https://react.dev/reference/eslint-plugin-react-hooks/lints/use-memo
|
|
2124
2132
|
*/
|
|
2125
|
-
"react-hooks/use-memo": 0
|
|
2133
|
+
"react-hooks/use-memo": 0,
|
|
2134
|
+
/**
|
|
2135
|
+
* @desc 验证 useMemo 始终返回值且结果被组件或 Hook 使用
|
|
2136
|
+
* @descEN Validates that useMemos always return a value and that the result of the useMemo is used by the component/hook
|
|
2137
|
+
* @see https://react.dev/reference/eslint-plugin-react-hooks/lints/void-use-memo
|
|
2138
|
+
*/
|
|
2139
|
+
"react-hooks/void-use-memo": 0
|
|
2126
2140
|
};
|
|
2127
2141
|
// src/core.stylistic.ts
|
|
2128
2142
|
/**
|
|
@@ -3644,7 +3658,7 @@ const rules$1 = {
|
|
|
3644
3658
|
* @descEN Disallow passing a value-returning function in a position accepting a void function
|
|
3645
3659
|
* @see https://typescript-eslint.io/rules/strict-void-return
|
|
3646
3660
|
*/
|
|
3647
|
-
"ts/strict-void-return": 1,
|
|
3661
|
+
"ts/strict-void-return": [1, { allowReturnAny: true }],
|
|
3648
3662
|
/**
|
|
3649
3663
|
* @desc 要求 switch-case 语句穷尽所有可能
|
|
3650
3664
|
* @descEN Require switch-case statements to be exhaustive
|
|
@@ -4022,7 +4036,7 @@ const rules = {
|
|
|
4022
4036
|
* 全局忽略目录列表
|
|
4023
4037
|
*
|
|
4024
4038
|
* 在 ESLint 配置中直接忽略的目录与文件 glob 集合,包含依赖、构建产物、锁文件、编辑器目录、缓存等。
|
|
4025
|
-
* 预设工厂(`src/config.ts
|
|
4039
|
+
* 预设工厂(`src/config.ts`)将其作为 `pawover/ignores` 配置层的 `ignores` 值。
|
|
4026
4040
|
*
|
|
4027
4041
|
* @example
|
|
4028
4042
|
* ```ts
|
|
@@ -4068,6 +4082,57 @@ const GLOB_EXCLUDE = [
|
|
|
4068
4082
|
"**/auto-component?(s).d.ts",
|
|
4069
4083
|
"**/auto-router?(s).d.ts"
|
|
4070
4084
|
];
|
|
4085
|
+
// src/globs.ts
|
|
4086
|
+
/**
|
|
4087
|
+
* 全部源文件(js / cjs / mjs / jsx / ts / tsx)
|
|
4088
|
+
*
|
|
4089
|
+
* 各规则组共享的基础文件范围;启用 `vue` 时工厂会在其后追加 {@link GLOB_VUE}。
|
|
4090
|
+
*
|
|
4091
|
+
* @example
|
|
4092
|
+
* ```ts
|
|
4093
|
+
* import { GLOB_SOURCE, GLOB_VUE } from "@pawover/kit-eslint-rules";
|
|
4094
|
+
*
|
|
4095
|
+
* const files = [...GLOB_SOURCE, GLOB_VUE];
|
|
4096
|
+
* ```
|
|
4097
|
+
*/
|
|
4098
|
+
const GLOB_SOURCE = ["**/*.{js,cjs,mjs,jsx,ts,tsx}"];
|
|
4099
|
+
/**
|
|
4100
|
+
* TypeScript 源文件(ts / tsx)
|
|
4101
|
+
*
|
|
4102
|
+
* 类型感知规则与 TypeScript parser 的默认作用范围;后置覆盖 `ts/*` 类型感知规则时应使用该常量限定 `files`。
|
|
4103
|
+
*
|
|
4104
|
+
* @example
|
|
4105
|
+
* ```ts
|
|
4106
|
+
* import { GLOB_TYPESCRIPT } from "@pawover/kit-eslint-rules";
|
|
4107
|
+
*
|
|
4108
|
+
* const files = GLOB_TYPESCRIPT;
|
|
4109
|
+
* ```
|
|
4110
|
+
*/
|
|
4111
|
+
const GLOB_TYPESCRIPT = ["**/*.{ts,tsx}"];
|
|
4112
|
+
/**
|
|
4113
|
+
* Vue 单文件组件
|
|
4114
|
+
*
|
|
4115
|
+
* @example
|
|
4116
|
+
* ```ts
|
|
4117
|
+
* import { GLOB_VUE } from "@pawover/kit-eslint-rules";
|
|
4118
|
+
*
|
|
4119
|
+
* const files = [GLOB_VUE];
|
|
4120
|
+
* ```
|
|
4121
|
+
*/
|
|
4122
|
+
const GLOB_VUE = "**/*.vue";
|
|
4123
|
+
/**
|
|
4124
|
+
* JSX 组件文件
|
|
4125
|
+
*
|
|
4126
|
+
* react 的 type-aware 规则在启用 `typescript` 时作用于 jsx;类型是否可用由项目 tsconfig 的 include / allowJs 决定。
|
|
4127
|
+
*
|
|
4128
|
+
* @example
|
|
4129
|
+
* ```ts
|
|
4130
|
+
* import { GLOB_JSX } from "@pawover/kit-eslint-rules";
|
|
4131
|
+
*
|
|
4132
|
+
* const files = [GLOB_JSX];
|
|
4133
|
+
* ```
|
|
4134
|
+
*/
|
|
4135
|
+
const GLOB_JSX = "**/*.jsx";
|
|
4071
4136
|
// src/plugins.ts
|
|
4072
4137
|
/**
|
|
4073
4138
|
* 内嵌插件注册表
|
|
@@ -4127,7 +4192,127 @@ const reactWithoutTypeChecked = {
|
|
|
4127
4192
|
}))
|
|
4128
4193
|
}
|
|
4129
4194
|
};
|
|
4195
|
+
// src/reactCompiler.ts
|
|
4196
|
+
/**
|
|
4197
|
+
* `react-hooks` 与 `@eslint-react` 共享的 Compiler 规则映射
|
|
4198
|
+
*
|
|
4199
|
+
* 键为 `eslint-plugin-react-hooks` 的规则名,值为 `@eslint-react` 的等价规则名;
|
|
4200
|
+
* 切换时关闭后者、启用前者,避免同一问题重复报告。
|
|
4201
|
+
*/
|
|
4202
|
+
const REACT_COMPILER_RULE_MAP = {
|
|
4203
|
+
"error-boundaries": "error-boundaries",
|
|
4204
|
+
"globals": "globals",
|
|
4205
|
+
"immutability": "immutability",
|
|
4206
|
+
"purity": "purity",
|
|
4207
|
+
"refs": "refs",
|
|
4208
|
+
"set-state-in-effect": "set-state-in-effect",
|
|
4209
|
+
"set-state-in-render": "set-state-in-render",
|
|
4210
|
+
"static-components": "static-components",
|
|
4211
|
+
"unsupported-syntax": "unsupported-syntax",
|
|
4212
|
+
"use-memo": "use-memo"
|
|
4213
|
+
};
|
|
4214
|
+
/**
|
|
4215
|
+
* React Compiler 开启时需要额外关闭的 `@eslint-react` 规则
|
|
4216
|
+
*
|
|
4217
|
+
* React Compiler 会自动记忆化 Context value,`no-unstable-context-value` 的告警不再适用。
|
|
4218
|
+
*/
|
|
4219
|
+
const REACT_COMPILER_DISABLED_REACT_RULES = ["no-unstable-context-value"];
|
|
4220
|
+
/** 仅官方 `recommended-latest` 预设包含的实验性 Compiler 规则。 */
|
|
4221
|
+
const REACT_COMPILER_LATEST_ONLY_RULES = ["void-use-memo"];
|
|
4222
|
+
/** 官方 flat config 预设名。 */
|
|
4223
|
+
const REACT_HOOKS_FLAT_CONFIG_NAMES = {
|
|
4224
|
+
recommended: "recommended",
|
|
4225
|
+
latest: "recommended-latest"
|
|
4226
|
+
};
|
|
4227
|
+
/** 将官方严重级别归一化为 preset 使用的数字形式。 */
|
|
4228
|
+
function normalizeRuleLevel(level) {
|
|
4229
|
+
if (level === "error") return 2;
|
|
4230
|
+
if (level === "warn") return 1;
|
|
4231
|
+
if (level === "off") return 0;
|
|
4232
|
+
return level;
|
|
4233
|
+
}
|
|
4234
|
+
/** 读取官方 `eslint-plugin-react-hooks` 预设的规则表。 */
|
|
4235
|
+
function getReactHooksPresetRules(preset) {
|
|
4236
|
+
const configs = plugins.reactHooks.configs.flat;
|
|
4237
|
+
const configName = REACT_HOOKS_FLAT_CONFIG_NAMES[preset];
|
|
4238
|
+
const rules = configs[configName]?.rules;
|
|
4239
|
+
if (!rules) throw new Error(`[pawover] 无法读取 eslint-plugin-react-hooks 的 "${configName}" 预设规则。`);
|
|
4240
|
+
return rules;
|
|
4241
|
+
}
|
|
4242
|
+
/**
|
|
4243
|
+
* 生成 React Compiler 切换规则
|
|
4244
|
+
*
|
|
4245
|
+
* 返回 `off`(需关闭的 `@eslint-react` 等价规则)与 `on`(需开启的 `react-hooks` 规则):
|
|
4246
|
+
* 严重级别直接取官方预设,避免与上游版本漂移。
|
|
4247
|
+
*/
|
|
4248
|
+
function getReactCompilerRuleMap(preset) {
|
|
4249
|
+
const presetRules = getReactHooksPresetRules(preset);
|
|
4250
|
+
const off = {};
|
|
4251
|
+
const on = {};
|
|
4252
|
+
for (const [hooksRule, eslintReactRule] of Object.entries(REACT_COMPILER_RULE_MAP)) {
|
|
4253
|
+
const ruleId = `react-hooks/${hooksRule}`;
|
|
4254
|
+
const level = presetRules[ruleId];
|
|
4255
|
+
if (level === void 0) throw new Error(`[pawover] eslint-plugin-react-hooks 的 "${preset}" 预设缺少规则 ${ruleId}。`);
|
|
4256
|
+
off[`react/${eslintReactRule}`] = 0;
|
|
4257
|
+
on[ruleId] = normalizeRuleLevel(level);
|
|
4258
|
+
}
|
|
4259
|
+
for (const rule of REACT_COMPILER_DISABLED_REACT_RULES) off[`react/${rule}`] = 0;
|
|
4260
|
+
if (preset === "latest") for (const rule of REACT_COMPILER_LATEST_ONLY_RULES) {
|
|
4261
|
+
const ruleId = `react-hooks/${rule}`;
|
|
4262
|
+
const level = presetRules[ruleId];
|
|
4263
|
+
if (level === void 0) throw new Error(`[pawover] eslint-plugin-react-hooks 的 "latest" 预设缺少规则 ${ruleId}。`);
|
|
4264
|
+
on[ruleId] = normalizeRuleLevel(level);
|
|
4265
|
+
}
|
|
4266
|
+
return {
|
|
4267
|
+
off,
|
|
4268
|
+
on
|
|
4269
|
+
};
|
|
4270
|
+
}
|
|
4271
|
+
/** 关闭全部 10 条重叠规则(`compiler: false` 回退到 `@eslint-react` 时使用)。 */
|
|
4272
|
+
function getReactCompilerDisabledRuleMap() {
|
|
4273
|
+
return Object.fromEntries(Object.keys(REACT_COMPILER_RULE_MAP).map((rule) => [`react-hooks/${rule}`, 0]));
|
|
4274
|
+
}
|
|
4130
4275
|
// src/config.ts
|
|
4276
|
+
/** 层名字典:预设产出的全部唯一配置层名称。 */
|
|
4277
|
+
const LAYER_NAMES = {
|
|
4278
|
+
ignores: "pawover/ignores",
|
|
4279
|
+
javascript: {
|
|
4280
|
+
parser: "pawover/javascript/parser",
|
|
4281
|
+
rules: "pawover/javascript/rules"
|
|
4282
|
+
},
|
|
4283
|
+
typescript: {
|
|
4284
|
+
setup: "pawover/typescript/setup",
|
|
4285
|
+
parser: "pawover/typescript/parser",
|
|
4286
|
+
rules: "pawover/typescript/rules",
|
|
4287
|
+
typeAware: "pawover/typescript/type-aware"
|
|
4288
|
+
},
|
|
4289
|
+
stylistic: {
|
|
4290
|
+
setup: "pawover/stylistic/setup",
|
|
4291
|
+
rules: "pawover/stylistic/rules"
|
|
4292
|
+
},
|
|
4293
|
+
antfu: {
|
|
4294
|
+
setup: "pawover/antfu/setup",
|
|
4295
|
+
rules: "pawover/antfu/rules"
|
|
4296
|
+
},
|
|
4297
|
+
imports: {
|
|
4298
|
+
setup: "pawover/imports/setup",
|
|
4299
|
+
rules: "pawover/imports/rules"
|
|
4300
|
+
},
|
|
4301
|
+
importsSort: {
|
|
4302
|
+
setup: "pawover/imports-sort/setup",
|
|
4303
|
+
rules: "pawover/imports-sort/rules"
|
|
4304
|
+
},
|
|
4305
|
+
react: {
|
|
4306
|
+
setup: "pawover/react/setup",
|
|
4307
|
+
rules: "pawover/react/rules",
|
|
4308
|
+
typeAware: "pawover/react/type-aware"
|
|
4309
|
+
},
|
|
4310
|
+
vue: {
|
|
4311
|
+
setup: "pawover/vue/setup",
|
|
4312
|
+
parser: "pawover/vue/parser",
|
|
4313
|
+
rules: "pawover/vue/rules"
|
|
4314
|
+
}
|
|
4315
|
+
};
|
|
4131
4316
|
const javascript = rules$5;
|
|
4132
4317
|
const typescript = rules$1;
|
|
4133
4318
|
const stylistic$1 = rules$2;
|
|
@@ -4139,81 +4324,137 @@ const reactHooks$1 = rules$3;
|
|
|
4139
4324
|
const vue$1 = rules;
|
|
4140
4325
|
/** react 映射中依赖类型信息的规则 id(`react/` 前缀) */
|
|
4141
4326
|
const reactTypeCheckedRuleIds = new Set(reactTypeCheckedNames.map((name) => `react/${name}`));
|
|
4142
|
-
/** react 映射中的 type-aware 规则子集(仅在 ts/tsx 层启用) */
|
|
4327
|
+
/** react 映射中的 type-aware 规则子集(仅在 ts/tsx/jsx 层启用) */
|
|
4143
4328
|
const reactTypeCheckedRules = Object.fromEntries([...reactTypeCheckedRuleIds].flatMap((ruleId) => {
|
|
4144
4329
|
const rule = react[ruleId];
|
|
4145
4330
|
return rule === void 0 ? [] : [[ruleId, rule]];
|
|
4146
4331
|
}));
|
|
4147
4332
|
/** react 映射中剔除 type-aware 规则后的基础规则表(作用于全部源文件) */
|
|
4148
4333
|
const reactBase = Object.fromEntries(Object.entries(react).filter(([ruleId]) => !reactTypeCheckedRuleIds.has(ruleId)));
|
|
4149
|
-
/**
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4334
|
+
/** 追加「setup(注册插件)→ parser(可选)→ rules(规则与文件范围)」三层。 */
|
|
4335
|
+
function addGroup(configs, options) {
|
|
4336
|
+
configs.push({
|
|
4337
|
+
name: options.setup,
|
|
4338
|
+
plugins: { [options.plugin]: options.pluginImpl }
|
|
4339
|
+
});
|
|
4340
|
+
if (options.parserLayer) configs.push(options.parserLayer);
|
|
4341
|
+
configs.push({
|
|
4342
|
+
name: options.rules,
|
|
4343
|
+
files: [...options.files],
|
|
4344
|
+
rules: {
|
|
4345
|
+
...options.ruleMap,
|
|
4346
|
+
...options.overrides ?? {}
|
|
4347
|
+
}
|
|
4348
|
+
});
|
|
4349
|
+
}
|
|
4350
|
+
/** 将布尔 / 对象选项归一化为选项对象。 */
|
|
4351
|
+
function resolveOptions(value) {
|
|
4352
|
+
return typeof value === "object" && value !== null ? value : {};
|
|
4353
|
+
}
|
|
4354
|
+
/** 将 React Compiler 开关归一化为官方预设名;`false` 表示回退到 `@eslint-react` 实现。 */
|
|
4355
|
+
function resolveReactCompilerPreset(value) {
|
|
4356
|
+
if (value === false) return;
|
|
4357
|
+
return value === "latest" ? "latest" : "recommended";
|
|
4358
|
+
}
|
|
4157
4359
|
/**
|
|
4158
4360
|
* 创建 ESLint flat config 预设
|
|
4159
4361
|
*
|
|
4160
|
-
*
|
|
4161
|
-
*
|
|
4362
|
+
* 返回 composer(继承 Promise,可直接用于 `eslint.config.js` 的默认导出),也可链式调用
|
|
4363
|
+
* `append` / `prepend` / `override` / `renamePlugins` 等能力继续组合。
|
|
4162
4364
|
*
|
|
4163
|
-
*
|
|
4164
|
-
*
|
|
4365
|
+
* 各规则组拆为 `setup` 层(只注册插件,不带 `files`)、`parser` 层(解析器)与
|
|
4366
|
+
* `rules` / `type-aware` 层(规则与文件范围),因此后置配置可以直接使用预设已注册的插件规则;
|
|
4367
|
+
* 若需注册自定义插件,在自己的配置层中挂载即可。
|
|
4368
|
+
*
|
|
4369
|
+
* @param options 预设选项;缺省时返回忽略层与 `javascript` parser/rules 层
|
|
4370
|
+
* @param userConfigs 追加在预设之后的 flat config(单个对象、数组、composer 或 Promise)
|
|
4371
|
+
* @returns 可直接导出或继续链式组合的 flat config composer
|
|
4165
4372
|
*
|
|
4166
4373
|
* @example
|
|
4167
4374
|
* ```ts
|
|
4168
|
-
* // TypeScript + React
|
|
4169
|
-
* import pawover from "@pawover/kit
|
|
4375
|
+
* // TypeScript + React 项目,使用按组 overrides 覆盖规则
|
|
4376
|
+
* import pawover from "@pawover/kit/eslint-rules";
|
|
4170
4377
|
*
|
|
4171
4378
|
* export default pawover({
|
|
4172
|
-
* typescript:
|
|
4379
|
+
* typescript: {
|
|
4380
|
+
* overrides: { "ts/strict-void-return": [1, { allowReturnAny: true }] },
|
|
4381
|
+
* },
|
|
4173
4382
|
* react: true,
|
|
4174
|
-
* parserOptions: { tsconfigRootDir: import.meta.dirname },
|
|
4175
4383
|
* });
|
|
4176
4384
|
* ```
|
|
4177
4385
|
*
|
|
4178
4386
|
* @example
|
|
4179
4387
|
* ```ts
|
|
4180
|
-
* //
|
|
4388
|
+
* // 追加自定义配置层
|
|
4181
4389
|
* import pawover from "@pawover/kit-eslint-rules";
|
|
4182
4390
|
*
|
|
4183
|
-
* export default pawover(
|
|
4391
|
+
* export default pawover(
|
|
4392
|
+
* { typescript: true },
|
|
4393
|
+
* { rules: { "no-console": "error" } },
|
|
4394
|
+
* );
|
|
4184
4395
|
* ```
|
|
4185
4396
|
*
|
|
4186
4397
|
* @example
|
|
4187
4398
|
* ```ts
|
|
4188
|
-
* //
|
|
4399
|
+
* // 按层名称覆盖
|
|
4189
4400
|
* import pawover from "@pawover/kit-eslint-rules";
|
|
4190
4401
|
*
|
|
4191
|
-
* export default
|
|
4192
|
-
*
|
|
4193
|
-
*
|
|
4194
|
-
*
|
|
4402
|
+
* export default pawover({ typescript: true })
|
|
4403
|
+
* .override("pawover/typescript/rules", {
|
|
4404
|
+
* rules: { "ts/consistent-type-definitions": ["error", "interface"] },
|
|
4405
|
+
* });
|
|
4195
4406
|
* ```
|
|
4196
4407
|
*/
|
|
4197
|
-
function pawover(options = {}) {
|
|
4198
|
-
const {
|
|
4408
|
+
function pawover(options = {}, ...userConfigs) {
|
|
4409
|
+
const { javascript: javascriptOptions, stylistic: enableStylistic = false, antfu: enableAntfu = false, imports: enableImports = false, importsSort: enableImportsSort = false, react: enableReact = false, vue: enableVue = false } = options;
|
|
4410
|
+
const enableTypescript = Boolean(options.typescript);
|
|
4411
|
+
const typescriptOptions = resolveOptions(options.typescript);
|
|
4412
|
+
const stylisticOptions = resolveOptions(options.stylistic);
|
|
4413
|
+
const antfuOptions = resolveOptions(options.antfu);
|
|
4414
|
+
const importsOptions = resolveOptions(options.imports);
|
|
4415
|
+
const importsSortOptions = resolveOptions(options.importsSort);
|
|
4416
|
+
const reactOptions = resolveOptions(options.react);
|
|
4417
|
+
const reactCompilerPreset = resolveReactCompilerPreset(reactOptions.compiler);
|
|
4418
|
+
const vueOptions = resolveOptions(options.vue);
|
|
4199
4419
|
const sourceFiles = enableVue ? [...GLOB_SOURCE, GLOB_VUE] : [...GLOB_SOURCE];
|
|
4200
4420
|
const typescriptParserOptions = {
|
|
4201
4421
|
projectService: true,
|
|
4202
|
-
...parserOptions
|
|
4422
|
+
...typescriptOptions.parserOptions ?? {}
|
|
4203
4423
|
};
|
|
4204
|
-
const
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4424
|
+
const filesTypeAware = typescriptOptions.filesTypeAware ?? [...GLOB_TYPESCRIPT];
|
|
4425
|
+
const reactTypeAwareFiles = [.../* @__PURE__ */ new Set([...filesTypeAware, GLOB_JSX])];
|
|
4426
|
+
const configs = [
|
|
4427
|
+
{
|
|
4428
|
+
name: LAYER_NAMES.ignores,
|
|
4429
|
+
ignores: [...GLOB_EXCLUDE]
|
|
4430
|
+
},
|
|
4431
|
+
{
|
|
4432
|
+
name: LAYER_NAMES.javascript.parser,
|
|
4433
|
+
files: [...sourceFiles],
|
|
4434
|
+
languageOptions: {
|
|
4435
|
+
ecmaVersion: "latest",
|
|
4436
|
+
sourceType: "module",
|
|
4437
|
+
parserOptions: { ecmaFeatures: { jsx: true } }
|
|
4438
|
+
}
|
|
4210
4439
|
},
|
|
4211
|
-
|
|
4212
|
-
|
|
4440
|
+
{
|
|
4441
|
+
name: LAYER_NAMES.javascript.rules,
|
|
4442
|
+
files: [...sourceFiles],
|
|
4443
|
+
rules: {
|
|
4444
|
+
...javascript,
|
|
4445
|
+
...javascriptOptions?.overrides ?? {}
|
|
4446
|
+
}
|
|
4447
|
+
}
|
|
4448
|
+
];
|
|
4213
4449
|
if (enableTypescript) {
|
|
4214
4450
|
const typescriptRuleFiles = enableVue ? [...GLOB_TYPESCRIPT, GLOB_VUE] : [...GLOB_TYPESCRIPT];
|
|
4215
4451
|
const typescriptParserFiles = enableReact ? [...typescriptRuleFiles, GLOB_JSX] : [...typescriptRuleFiles];
|
|
4216
4452
|
configs.push({
|
|
4453
|
+
name: LAYER_NAMES.typescript.setup,
|
|
4454
|
+
plugins: { ts: plugins.typescript }
|
|
4455
|
+
});
|
|
4456
|
+
configs.push({
|
|
4457
|
+
name: LAYER_NAMES.typescript.parser,
|
|
4217
4458
|
files: [...typescriptParserFiles],
|
|
4218
4459
|
languageOptions: {
|
|
4219
4460
|
parser: plugins.typescriptParser,
|
|
@@ -4221,67 +4462,112 @@ function pawover(options = {}) {
|
|
|
4221
4462
|
}
|
|
4222
4463
|
});
|
|
4223
4464
|
configs.push({
|
|
4465
|
+
name: LAYER_NAMES.typescript.rules,
|
|
4224
4466
|
files: [...typescriptRuleFiles],
|
|
4225
|
-
|
|
4226
|
-
|
|
4467
|
+
rules: {
|
|
4468
|
+
...typescript,
|
|
4469
|
+
...typescriptOptions.overrides ?? {}
|
|
4470
|
+
}
|
|
4471
|
+
});
|
|
4472
|
+
if (typescriptOptions.overridesTypeAware) configs.push({
|
|
4473
|
+
name: LAYER_NAMES.typescript.typeAware,
|
|
4474
|
+
files: [...filesTypeAware],
|
|
4475
|
+
rules: { ...typescriptOptions.overridesTypeAware }
|
|
4227
4476
|
});
|
|
4228
4477
|
}
|
|
4229
|
-
if (enableStylistic) configs
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4478
|
+
if (enableStylistic) addGroup(configs, {
|
|
4479
|
+
setup: LAYER_NAMES.stylistic.setup,
|
|
4480
|
+
rules: LAYER_NAMES.stylistic.rules,
|
|
4481
|
+
plugin: "stylistic",
|
|
4482
|
+
pluginImpl: plugins.stylistic,
|
|
4483
|
+
ruleMap: stylistic$1,
|
|
4484
|
+
overrides: stylisticOptions.overrides,
|
|
4485
|
+
files: sourceFiles
|
|
4233
4486
|
});
|
|
4234
|
-
if (enableAntfu) configs
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4487
|
+
if (enableAntfu) addGroup(configs, {
|
|
4488
|
+
setup: LAYER_NAMES.antfu.setup,
|
|
4489
|
+
rules: LAYER_NAMES.antfu.rules,
|
|
4490
|
+
plugin: "antfu",
|
|
4491
|
+
pluginImpl: plugins.antfu,
|
|
4492
|
+
ruleMap: antfu$1,
|
|
4493
|
+
overrides: antfuOptions.overrides,
|
|
4494
|
+
files: sourceFiles
|
|
4238
4495
|
});
|
|
4239
|
-
if (enableImports) configs
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4496
|
+
if (enableImports) addGroup(configs, {
|
|
4497
|
+
setup: LAYER_NAMES.imports.setup,
|
|
4498
|
+
rules: LAYER_NAMES.imports.rules,
|
|
4499
|
+
plugin: "imports",
|
|
4500
|
+
pluginImpl: plugins.imports,
|
|
4501
|
+
ruleMap: imports,
|
|
4502
|
+
overrides: importsOptions.overrides,
|
|
4503
|
+
files: sourceFiles
|
|
4243
4504
|
});
|
|
4244
|
-
if (enableImportsSort) configs
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4505
|
+
if (enableImportsSort) addGroup(configs, {
|
|
4506
|
+
setup: LAYER_NAMES.importsSort.setup,
|
|
4507
|
+
rules: LAYER_NAMES.importsSort.rules,
|
|
4508
|
+
plugin: "importsSort",
|
|
4509
|
+
pluginImpl: plugins.importsSort,
|
|
4510
|
+
ruleMap: importsSort,
|
|
4511
|
+
overrides: importsSortOptions.overrides,
|
|
4512
|
+
files: sourceFiles
|
|
4248
4513
|
});
|
|
4249
4514
|
if (enableReact) {
|
|
4515
|
+
const reactCompilerRules = reactCompilerPreset ? getReactCompilerRuleMap(reactCompilerPreset) : {
|
|
4516
|
+
off: {},
|
|
4517
|
+
on: getReactCompilerDisabledRuleMap()
|
|
4518
|
+
};
|
|
4250
4519
|
configs.push({
|
|
4251
|
-
|
|
4520
|
+
name: LAYER_NAMES.react.setup,
|
|
4252
4521
|
plugins: {
|
|
4253
4522
|
"react": enableTypescript ? plugins.react : reactWithoutTypeChecked,
|
|
4254
4523
|
"react-hooks": plugins.reactHooks
|
|
4255
|
-
}
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4524
|
+
}
|
|
4525
|
+
});
|
|
4526
|
+
configs.push({
|
|
4527
|
+
name: LAYER_NAMES.react.rules,
|
|
4528
|
+
files: [...GLOB_SOURCE],
|
|
4529
|
+
rules: {
|
|
4260
4530
|
...reactBase,
|
|
4261
4531
|
...reactHooks$1,
|
|
4262
|
-
...reactTypeCheckedOff
|
|
4532
|
+
...enableTypescript ? {} : reactTypeCheckedOff,
|
|
4533
|
+
...reactCompilerRules.off,
|
|
4534
|
+
...reactCompilerRules.on,
|
|
4535
|
+
...reactOptions.overrides ?? {}
|
|
4263
4536
|
}
|
|
4264
4537
|
});
|
|
4265
4538
|
if (enableTypescript) configs.push({
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
rules: {
|
|
4539
|
+
name: LAYER_NAMES.react.typeAware,
|
|
4540
|
+
files: [...reactTypeAwareFiles],
|
|
4541
|
+
rules: {
|
|
4542
|
+
...reactTypeCheckedRules,
|
|
4543
|
+
...reactOptions.overridesTypeAware ?? {}
|
|
4544
|
+
}
|
|
4269
4545
|
});
|
|
4270
4546
|
}
|
|
4271
|
-
if (enableVue) configs
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4547
|
+
if (enableVue) addGroup(configs, {
|
|
4548
|
+
setup: LAYER_NAMES.vue.setup,
|
|
4549
|
+
parserLayer: {
|
|
4550
|
+
name: LAYER_NAMES.vue.parser,
|
|
4551
|
+
files: [GLOB_VUE],
|
|
4552
|
+
languageOptions: {
|
|
4553
|
+
parser: plugins.vueParser,
|
|
4554
|
+
parserOptions: enableTypescript ? {
|
|
4555
|
+
parser: plugins.typescriptParser,
|
|
4556
|
+
...typescriptParserOptions
|
|
4557
|
+
} : {}
|
|
4558
|
+
}
|
|
4279
4559
|
},
|
|
4280
|
-
|
|
4281
|
-
|
|
4560
|
+
rules: LAYER_NAMES.vue.rules,
|
|
4561
|
+
plugin: "vue",
|
|
4562
|
+
pluginImpl: plugins.vue,
|
|
4563
|
+
ruleMap: vue$1,
|
|
4564
|
+
overrides: vueOptions.overrides,
|
|
4565
|
+
files: [GLOB_VUE]
|
|
4282
4566
|
});
|
|
4283
|
-
|
|
4567
|
+
let result = composer(...configs);
|
|
4568
|
+
if (userConfigs.length > 0) result = result.append(...userConfigs);
|
|
4569
|
+
return result;
|
|
4284
4570
|
}
|
|
4285
4571
|
// src/index.ts
|
|
4286
4572
|
var src_default = pawover;
|
|
4287
|
-
export { GLOB_EXCLUDE, src_default as default };
|
|
4573
|
+
export { GLOB_EXCLUDE, GLOB_JSX, GLOB_SOURCE, GLOB_TYPESCRIPT, GLOB_VUE, src_default as default };
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"url": "https://github.com/pawover"
|
|
7
7
|
},
|
|
8
8
|
"description": "Self-contained ESLint flat config preset: javascript, typescript, react, vue, stylistic, antfu and import rules, with pinned bundled plugins",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.2.0-alpha.1",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"keywords": [
|
|
12
12
|
"pawover",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@eslint-react/eslint-plugin": "5.28.8",
|
|
48
48
|
"@stylistic/eslint-plugin": "6.0.0-beta.6",
|
|
49
|
+
"eslint-flat-config-utils": "3.2.0",
|
|
49
50
|
"eslint-plugin-antfu": "3.3.1",
|
|
50
51
|
"eslint-plugin-import-lite": "0.6.0",
|
|
51
52
|
"eslint-plugin-react-hooks": "7.1.1",
|