@pawover/kit-eslint-rules 0.2.0-alpha.0 → 0.2.0-alpha.2

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 CHANGED
@@ -161,6 +161,7 @@ interface ReactOptions extends RulesOverrideOptions {
161
161
  *
162
162
  * react 组启用时默认开启(`true` 等价 `"recommended"`):将 10 条与 `@eslint-react` 重叠的
163
163
  * Compiler 规则切换为 `eslint-plugin-react-hooks` 官方实现,并关闭 `@eslint-react` 等价规则;
164
+ * 同时关闭 `react/no-unstable-context-value`(React Compiler 会自动记忆化 Context value);
164
165
  * 传 `false` 回退到 `@eslint-react` 实现,传 `"latest"` 额外启用实验性 `react-hooks/void-use-memo`。
165
166
  *
166
167
  * 仅控制这 10 条重叠规则;官方独有的 `config` / `gating` / `incompatible-library` /
package/dist/index.js CHANGED
@@ -4211,6 +4211,12 @@ const REACT_COMPILER_RULE_MAP = {
4211
4211
  "unsupported-syntax": "unsupported-syntax",
4212
4212
  "use-memo": "use-memo"
4213
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"];
4214
4220
  /** 仅官方 `recommended-latest` 预设包含的实验性 Compiler 规则。 */
4215
4221
  const REACT_COMPILER_LATEST_ONLY_RULES = ["void-use-memo"];
4216
4222
  /** 官方 flat config 预设名。 */
@@ -4250,6 +4256,7 @@ function getReactCompilerRuleMap(preset) {
4250
4256
  off[`react/${eslintReactRule}`] = 0;
4251
4257
  on[ruleId] = normalizeRuleLevel(level);
4252
4258
  }
4259
+ for (const rule of REACT_COMPILER_DISABLED_REACT_RULES) off[`react/${rule}`] = 0;
4253
4260
  if (preset === "latest") for (const rule of REACT_COMPILER_LATEST_ONLY_RULES) {
4254
4261
  const ruleId = `react-hooks/${rule}`;
4255
4262
  const level = presetRules[ruleId];
package/package.json CHANGED
@@ -6,11 +6,12 @@
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.2.0-alpha.0",
9
+ "version": "0.2.0-alpha.2",
10
10
  "type": "module",
11
11
  "keywords": [
12
12
  "pawover",
13
- "pawover-kit-eslint-rules"
13
+ "pawover-kit-eslint-rules",
14
+ "tanstack-intent"
14
15
  ],
15
16
  "homepage": "https://github.com/pawover/pawover-kit/packages/eslint-rules#readme",
16
17
  "repository": {
@@ -25,7 +26,8 @@
25
26
  "module": "./dist/index.js",
26
27
  "types": "./dist/index.d.ts",
27
28
  "files": [
28
- "dist"
29
+ "dist",
30
+ "skills/eslint-preset"
29
31
  ],
30
32
  "exports": {
31
33
  ".": {
@@ -0,0 +1,294 @@
1
+ ---
2
+ name: eslint-preset
3
+ description: >-
4
+ Use when configuring ESLint flat config with @pawover/kit-eslint-rules,
5
+ including enabling TypeScript, React, Vue, stylistic, antfu, imports, or
6
+ importsSort groups; overriding rules per group or per layer; and handling React
7
+ Compiler rules.
8
+ metadata:
9
+ purpose: Configure ESLint flat config with the self-contained
10
+ @pawover/kit-eslint-rules preset.
11
+ type: core
12
+ library: "@pawover/kit-eslint-rules"
13
+ library_version: "0.2.0-alpha.1"
14
+ sources:
15
+ - src/index.ts
16
+ - src/config.ts
17
+ - src/globs.ts
18
+ - src/globExclude.ts
19
+ - src/reactCompiler.ts
20
+ - src/core.javascript.ts
21
+ - src/core.typescript.ts
22
+ - src/core.react.ts
23
+ - src/core.vue.ts
24
+ ---
25
+
26
+ # Configure `@pawover/kit-eslint-rules`
27
+
28
+ The package is a self-contained ESLint flat config preset. Every upstream plugin
29
+ it uses is a dependency and is registered by the factory; do not install or
30
+ register the preset's plugins manually.
31
+
32
+ The default export is `pawover(options?, ...userConfigs)`. It returns an
33
+ `eslint-flat-config-utils` `FlatConfigComposer`, which extends `Promise` and can
34
+ be exported directly from `eslint.config.js`.
35
+
36
+ ## Setup
37
+
38
+ ```ts
39
+ // eslint.config.js
40
+ import pawover from "@pawover/kit-eslint-rules";
41
+
42
+ export default pawover();
43
+ ```
44
+
45
+ With no options, the preset returns the global ignore layer, the JavaScript
46
+ parser layer, and the JavaScript rules layer. `javascript` is always enabled.
47
+ Every other group is opt-in.
48
+
49
+ ```ts
50
+ // eslint.config.js
51
+ import pawover from "@pawover/kit-eslint-rules";
52
+
53
+ const fullConfig = pawover({
54
+ typescript: true,
55
+ stylistic: true,
56
+ antfu: true,
57
+ imports: true,
58
+ importsSort: true,
59
+ react: true,
60
+ });
61
+ ```
62
+
63
+ ## Core patterns
64
+
65
+ ### Enable the groups the project needs
66
+
67
+ | Option | Enables | Files |
68
+ | --- | --- | --- |
69
+ | `typescript` | TypeScript plugin, parser, and rules | `**/*.{ts,tsx}`; adds `*.vue` when `vue` is enabled |
70
+ | `stylistic` | Stylistic rules | source files |
71
+ | `antfu` | `eslint-plugin-antfu` rules | source files |
72
+ | `imports` | `eslint-plugin-import-lite` rules | source files |
73
+ | `importsSort` | `eslint-plugin-simple-import-sort` rules | source files |
74
+ | `react` | `@eslint-react` + `eslint-plugin-react-hooks` | source files; type-aware rules also cover `*.jsx` |
75
+ | `vue` | Vue parser and rules | `**/*.vue` |
76
+
77
+ `typescript` defaults the parser to `projectService: true`. Pass parser options
78
+ to match the project:
79
+
80
+ ```ts
81
+ // eslint.config.js
82
+ import pawover from "@pawover/kit-eslint-rules";
83
+
84
+ const parserConfig = pawover({
85
+ typescript: {
86
+ parserOptions: { tsconfigRootDir: process.cwd() },
87
+ },
88
+ });
89
+ ```
90
+
91
+ The passed `parserOptions` are shallow-merged over the defaults; a same-named key
92
+ wins. Use `filesTypeAware` to narrow the type-aware file range; the default is
93
+ `GLOB_TYPESCRIPT` (`**/*.{ts,tsx}`).
94
+
95
+ ### Override rules at the group level
96
+
97
+ Every group accepts `{ overrides }`. The override is merged into the preset's
98
+ rule map at generation time, so it inherits the group's file range and plugin
99
+ registration. This avoids the flat-config plugin-scope problem that occurs when
100
+ a later config layer uses a rule without registering its plugin.
101
+
102
+ ```ts
103
+ // eslint.config.js
104
+ import pawover from "@pawover/kit-eslint-rules";
105
+
106
+ const overrideConfig = pawover({
107
+ typescript: {
108
+ overrides: {
109
+ "ts/strict-void-return": [1, { allowReturnAny: true }],
110
+ },
111
+ },
112
+ react: {
113
+ overrides: {
114
+ "react/no-implicit-key": "warn",
115
+ },
116
+ },
117
+ });
118
+ ```
119
+
120
+ Type-aware rules use `overridesTypeAware`. They only apply inside
121
+ `filesTypeAware`; React's type-aware layer also includes `GLOB_JSX`:
122
+
123
+ ```ts
124
+ import pawover, { GLOB_TYPESCRIPT } from "@pawover/kit-eslint-rules";
125
+
126
+ const typeAwareConfig = pawover({
127
+ typescript: {
128
+ filesTypeAware: GLOB_TYPESCRIPT,
129
+ overridesTypeAware: {
130
+ "ts/no-unsafe-assignment": "warn",
131
+ },
132
+ },
133
+ });
134
+ ```
135
+
136
+ ### Control React Compiler rules
137
+
138
+ When `react` is enabled, the preset switches ten overlapping rules from
139
+ `@eslint-react` to the official `eslint-plugin-react-hooks` implementations and
140
+ turns off the `@eslint-react` equivalents. This avoids duplicate diagnostics and
141
+ also disables `react/no-unstable-context-value` because React Compiler memoizes
142
+ context values.
143
+
144
+ ```ts
145
+ // Default: official recommended Compiler rules
146
+ const recommendedConfig = pawover({ typescript: true, react: true });
147
+
148
+ // Keep the @eslint-react implementations instead
149
+ const legacyConfig = pawover({ typescript: true, react: { compiler: false } });
150
+
151
+ // Add the experimental void-use-memo rule
152
+ const latestConfig = pawover({ typescript: true, react: { compiler: "latest" } });
153
+ ```
154
+
155
+ `react.overrides` is applied last, so it can override any switched rule. The
156
+ official-only `config`, `gating`, `incompatible-library`, and
157
+ `preserve-manual-memoization` rules are always provided by `react-hooks`.
158
+
159
+ Without `typescript`, the React group disables the type-aware rules and registers
160
+ a no-op plugin implementation. A later override that forces one of those rules
161
+ on will not throw "requires type information". With `typescript` enabled, the
162
+ type-aware rules apply to `filesTypeAware` plus `*.jsx`; the `.jsx` type
163
+ availability still depends on the project's `tsconfig` `include` / `allowJs`.
164
+
165
+ ### Override a specific generated layer
166
+
167
+ Each layer has a unique name. Use the composer's `override(name, config)` to
168
+ target it precisely:
169
+
170
+ ```ts
171
+ import pawover from "@pawover/kit-eslint-rules";
172
+
173
+ const layerConfig = pawover({ typescript: true }).override(
174
+ "pawover/typescript/rules",
175
+ {
176
+ rules: {
177
+ "ts/consistent-type-definitions": ["error", "interface"],
178
+ },
179
+ },
180
+ );
181
+ ```
182
+
183
+ Layer names are `pawover/<group>/<setup|parser|rules|type-aware>`; group names use
184
+ kebab-case (`importsSort` → `imports-sort`). The global ignore layer is
185
+ `pawover/ignores`. See
186
+ [the options reference](references/options.md) for the complete layer list.
187
+
188
+ ### Append or prepend your own config
189
+
190
+ The second and later arguments are appended as flat configs. They can be a
191
+ single object, an array, a composer, or a Promise of an array. You can also use
192
+ the composer methods directly.
193
+
194
+ ```ts
195
+ import pawover from "@pawover/kit-eslint-rules";
196
+
197
+ const appendedConfig = pawover(
198
+ { typescript: true },
199
+ { rules: { "no-console": "error" } },
200
+ );
201
+
202
+ // Equivalent composition style
203
+ const composerConfig = pawover({ typescript: true }).append({
204
+ rules: { "no-console": "error" },
205
+ });
206
+ ```
207
+
208
+ ### Use the exported glob constants
209
+
210
+ `GLOB_SOURCE`, `GLOB_TYPESCRIPT`, `GLOB_JSX`, `GLOB_VUE`, and `GLOB_EXCLUDE` are
211
+ available for custom layers and overrides.
212
+
213
+ ```ts
214
+ import pawover, { GLOB_JSX, GLOB_TYPESCRIPT } from "@pawover/kit-eslint-rules";
215
+
216
+ const globConfig = pawover({ typescript: true }).append({
217
+ files: [...GLOB_TYPESCRIPT, GLOB_JSX],
218
+ rules: {
219
+ "no-console": "warn",
220
+ },
221
+ });
222
+ ```
223
+
224
+ `GLOB_EXCLUDE` already covers dependency directories, build outputs, lockfiles,
225
+ editor directories, caches, and generated declaration files. Extend ignores by
226
+ appending a layer or overriding `pawover/ignores`; the factory does not accept an
227
+ `ignores` option.
228
+
229
+ ## Common mistakes
230
+
231
+ ### Passing `javascript: true`
232
+
233
+ The JavaScript group is always on and is not a switch. Use its option object only
234
+ for overrides:
235
+
236
+ ```ts no-check
237
+ pawover({ javascript: true }); // javascript is always enabled
238
+ ```
239
+
240
+ ```ts
241
+ pawover({ javascript: { overrides: { "no-console": "error" } } });
242
+ ```
243
+
244
+ ### Passing `ignores` or `renamePlugins` to the factory
245
+
246
+ The factory does not accept these options. Append a config layer for ignores, or
247
+ use the composer's `.renamePlugins()`:
248
+
249
+ ```ts no-check
250
+ pawover({ ignores: ["dist/**"] });
251
+ pawover({ renamePlugins: { ts: "typescript" } });
252
+ ```
253
+
254
+ Use:
255
+
256
+ ```ts
257
+ import pawover from "@pawover/kit-eslint-rules";
258
+
259
+ const customConfig = pawover({ typescript: true })
260
+ .append({ ignores: ["dist/**"] })
261
+ .renamePlugins({ ts: "typescript" });
262
+ ```
263
+
264
+ ### Installing the preset's plugins manually
265
+
266
+ The preset is self-contained. Installing `@eslint-react`, `typescript-eslint`,
267
+ `eslint-plugin-vue`, and the rest separately can produce a second copy or a
268
+ different version than the one the preset registers. Install only
269
+ `@pawover/kit-eslint-rules` (plus ESLint itself), then add custom plugins in your
270
+ own config layer when needed.
271
+
272
+ ### Enabling React type-aware rules without TypeScript
273
+
274
+ The React group only enables type-aware rules when `typescript` is also enabled.
275
+ Without it, the preset registers no-op implementations so forced rules do not
276
+ throw. If the project needs those checks, enable `typescript` and ensure the
277
+ files are covered by the project's `tsconfig`.
278
+
279
+ ### Assuming `.jsx` is type-aware in a TS project
280
+
281
+ React's type-aware range adds `*.jsx`, but TypeScript only has type information
282
+ for those files when the project's `tsconfig` includes them and `allowJs` allows
283
+ them. Files outside the project are reported as "not in the project".
284
+
285
+ ## Completion
286
+
287
+ - `pawover()` is the default export of `eslint.config.js`.
288
+ - Only the needed groups are enabled; `javascript` is left implicit.
289
+ - Group overrides use `overrides` / `overridesTypeAware`, not a separate layer
290
+ that lacks plugin registration.
291
+ - Layer overrides use the exact generated layer name.
292
+ - The project does not install the preset's upstream plugins separately.
293
+ - The config runs with the project's package manager and the ESLint version the
294
+ preset supports.
@@ -0,0 +1,124 @@
1
+ # Preset options and layers
2
+
3
+ This reference lists the generated layers, the option shapes, and the glob
4
+ constants. Use it when a layer name or option boundary is not obvious from the
5
+ main skill.
6
+
7
+ ## Generated layer names
8
+
9
+ The factory emits layers in this order when the corresponding group is enabled:
10
+
11
+ | Layer name | Contents |
12
+ | --- | --- |
13
+ | `pawover/ignores` | The `GLOB_EXCLUDE` ignore list. |
14
+ | `pawover/javascript/parser` | JavaScript parser settings (`ecmaVersion: "latest"`, `sourceType: "module"`, JSX enabled). |
15
+ | `pawover/javascript/rules` | JavaScript rule map and `javascript.overrides`. |
16
+ | `pawover/typescript/setup` | Registers the `ts` plugin. |
17
+ | `pawover/typescript/parser` | TypeScript parser with `projectService: true` and `typescript.parserOptions`. |
18
+ | `pawover/typescript/rules` | TypeScript rule map and `typescript.overrides`. |
19
+ | `pawover/typescript/type-aware` | `typescript.overridesTypeAware` on `filesTypeAware`. |
20
+ | `pawover/stylistic/setup` / `rules` | Registers the `stylistic` plugin and applies its rules. |
21
+ | `pawover/antfu/setup` / `rules` | Registers the `antfu` plugin and applies its rules. |
22
+ | `pawover/imports/setup` / `rules` | Registers the `imports` plugin and applies its rules. |
23
+ | `pawover/imports-sort/setup` / `rules` | Registers the `importsSort` plugin and applies its rules. |
24
+ | `pawover/react/setup` | Registers `react` and `react-hooks` (or the no-op `react` implementation without TypeScript). |
25
+ | `pawover/react/rules` | React base rules, hooks rules, compiler switch, and `react.overrides`. |
26
+ | `pawover/react/type-aware` | React type-aware rules and `react.overridesTypeAware`. |
27
+ | `pawover/vue/setup` | Registers the `vue` plugin. |
28
+ | `pawover/vue/parser` | `vue-eslint-parser`, optionally delegating `<script>` to the TypeScript parser. |
29
+ | `pawover/vue/rules` | Vue rule map and `vue.overrides`. |
30
+
31
+ Group names in layer names use kebab-case: `importsSort` becomes
32
+ `imports-sort`.
33
+
34
+ ## Option shapes
35
+
36
+ ```ts
37
+ import type { PawoverOptions } from "@pawover/kit-eslint-rules";
38
+
39
+ const options: PawoverOptions = {
40
+ javascript: { overrides: { "no-console": "error" } },
41
+ typescript: {
42
+ overrides: { "ts/consistent-type-definitions": ["error", "interface"] },
43
+ overridesTypeAware: { "ts/no-unsafe-assignment": "warn" },
44
+ filesTypeAware: ["**/*.{ts,tsx}"],
45
+ parserOptions: { tsconfigRootDir: "/repo" },
46
+ },
47
+ stylistic: true,
48
+ antfu: true,
49
+ imports: true,
50
+ importsSort: true,
51
+ react: {
52
+ compiler: "latest",
53
+ overrides: { "react/no-implicit-key": "warn" },
54
+ overridesTypeAware: { "react/no-unused-props": "off" },
55
+ },
56
+ vue: { overrides: { "vue/multi-word-component-names": "off" } },
57
+ };
58
+ ```
59
+
60
+ `javascript` is always enabled; its option only accepts overrides. All other
61
+ groups accept `true` or an options object. Each group's `overrides` is merged
62
+ into that group's rule map at generation time.
63
+
64
+ ## Glob constants
65
+
66
+ | Constant | Value | Meaning |
67
+ | --- | --- | --- |
68
+ | `GLOB_SOURCE` | `["**/*.{js,cjs,mjs,jsx,ts,tsx}"]` | All source files. Append `GLOB_VUE` when customizing Vue sources. |
69
+ | `GLOB_TYPESCRIPT` | `["**/*.{ts,tsx}"]` | TypeScript files; default for type-aware layers. |
70
+ | `GLOB_JSX` | `"**/*.jsx"` | JSX files; added to React's type-aware range. |
71
+ | `GLOB_VUE` | `"**/*.vue"` | Vue single-file components. |
72
+ | `GLOB_EXCLUDE` | Array of ignore globs | Dependencies, build outputs, lockfiles, caches, editor directories, generated declarations. |
73
+
74
+ ## React Compiler switch
75
+
76
+ The switch covers ten rules that exist in both `@eslint-react` and
77
+ `eslint-plugin-react-hooks`:
78
+
79
+ `error-boundaries`, `globals`, `immutability`, `purity`, `refs`,
80
+ `set-state-in-effect`, `set-state-in-render`, `static-components`,
81
+ `unsupported-syntax`, `use-memo`.
82
+
83
+ When enabled, the `@eslint-react` equivalents are set to `0` and the
84
+ `react-hooks` implementations are enabled at the level from the official
85
+ `recommended` preset. It also disables `react/no-unstable-context-value`.
86
+ `compiler: "latest"` adds the experimental `react-hooks/void-use-memo`.
87
+
88
+ `compiler: false` turns off the ten `react-hooks` compiler rules and leaves the
89
+ `@eslint-react` implementations in place. The official-only rules (`config`,
90
+ `gating`, `incompatible-library`, `preserve-manual-memoization`) remain from
91
+ `react-hooks` in all modes.
92
+
93
+ ## Composer operations
94
+
95
+ The returned value is a `FlatConfigComposer` and inherits `Promise`. Useful
96
+ methods:
97
+
98
+ ```ts
99
+ import pawover from "@pawover/kit-eslint-rules";
100
+
101
+ const config = pawover({ typescript: true })
102
+ .append({ rules: { "no-console": "error" } })
103
+ .prepend({ files: ["**/*.ts"], rules: { "no-console": "warn" } })
104
+ .override("pawover/typescript/rules", {
105
+ rules: { "ts/consistent-type-definitions": ["error", "interface"] },
106
+ })
107
+ .renamePlugins({ ts: "typescript" });
108
+ ```
109
+
110
+ `append` and `prepend` accept a config, an array, a composer, or a Promise of an
111
+ array. `override` targets a layer by its generated name. `renamePlugins` renames
112
+ matching plugin keys and rule prefixes across all configurations in the
113
+ composer.
114
+
115
+ ## Common option mistakes
116
+
117
+ - `javascript` is not a boolean switch; passing `true` is not meaningful.
118
+ - `filesTypeAware` only accepts `string[]`; a single glob string is invalid.
119
+ - `parserOptions` is shallow-merged, so nested objects are replaced rather than
120
+ deep-merged.
121
+ - `ignores` and `renamePlugins` are composer concerns, not factory options.
122
+ - `react.compiler` accepts `true`, `false`, `"recommended"`, or `"latest"`.
123
+ - A custom plugin layer must register the plugin before using its rules; the
124
+ preset's setup layers only cover the preset's own plugins.