@eslint-react/kit 4.0.0-beta.1 → 4.0.0-beta.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/README.md +37 -0
- package/dist/index.d.ts +5 -6
- package/dist/index.js +4 -2
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ ESLint React's toolkit for building custom React lint rules right inside your `e
|
|
|
14
14
|
- [`kit.is`](#kitis) — Predicates
|
|
15
15
|
- [`kit.hint`](#kithint) — Detection hint bit-flags
|
|
16
16
|
- [`kit.flag`](#kitflag) — Component characteristic flags
|
|
17
|
+
- [`kit.settings`](#kitsettings) — Normalized ESLint React settings
|
|
17
18
|
- [Examples](#examples)
|
|
18
19
|
- [Simple: Ban `forwardRef`](#simple-ban-forwardref)
|
|
19
20
|
- [Component: Destructure component props](#component-destructure-component-props)
|
|
@@ -115,6 +116,7 @@ kit
|
|
|
115
116
|
├── is -> All predicates (component, hook, React API, import source)
|
|
116
117
|
├── hint -> Detection hint bit-flags
|
|
117
118
|
├── flag -> Component characteristic bit-flags
|
|
119
|
+
├── settings -> Normalized ESLint React settings
|
|
118
120
|
```
|
|
119
121
|
|
|
120
122
|
---
|
|
@@ -253,6 +255,41 @@ for (const component of query.all(program)) {
|
|
|
253
255
|
}
|
|
254
256
|
```
|
|
255
257
|
|
|
258
|
+
#### `kit.settings`
|
|
259
|
+
|
|
260
|
+
Exposes the normalized `react-x` settings from the ESLint shared configuration (`context.settings["react-x"]`). This lets your custom rules read and react to the same project-level settings used by the built-in rules.
|
|
261
|
+
|
|
262
|
+
| Property | Type | Default | Description |
|
|
263
|
+
| ----------------------- | ------------------------------------------------------- | ----------- | --------------------------------------------------------- |
|
|
264
|
+
| `version` | `string` | auto-detect | Resolved React version (e.g. `"19.2.4"`). |
|
|
265
|
+
| `importSource` | `string` | `"react"` | The module React is imported from (e.g. `"@pika/react"`). |
|
|
266
|
+
| `compilationMode` | `"infer" \| "annotation" \| "syntax" \| "all" \| "off"` | `"off"` | The React Compiler compilation mode the project uses. |
|
|
267
|
+
| `polymorphicPropName` | `string \| null` | `"as"` | Prop name used for polymorphic components. |
|
|
268
|
+
| `additionalStateHooks` | `RegExpLike` | — | Pattern matching custom hooks treated as state hooks. |
|
|
269
|
+
| `additionalEffectHooks` | `RegExpLike` | — | Pattern matching custom hooks treated as effect hooks. |
|
|
270
|
+
|
|
271
|
+
`RegExpLike` is an object with a `test(s: string) => boolean` method (same interface as `RegExp`).
|
|
272
|
+
|
|
273
|
+
**Usage:**
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
defineReactConfig({
|
|
277
|
+
name: "require-react-19",
|
|
278
|
+
make: (context, { settings }) => ({
|
|
279
|
+
Program(program) {
|
|
280
|
+
if (!settings.version.startsWith("19.")) {
|
|
281
|
+
context.report({
|
|
282
|
+
node: program,
|
|
283
|
+
message: `This project requires React 19, but detected version ${settings.version}.`,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
}),
|
|
288
|
+
});
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
256
293
|
## Examples
|
|
257
294
|
|
|
258
295
|
### Simple: Ban `forwardRef`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as core from "@eslint-react/core";
|
|
2
|
+
import { ESLintReactSettingsNormalized } from "@eslint-react/shared";
|
|
2
3
|
import { TSESTreeFunction } from "@eslint-react/ast";
|
|
3
4
|
import { TSESTree } from "@typescript-eslint/utils";
|
|
4
5
|
import { RuleContext, RuleFix, RuleFixer, RuleListener } from "@typescript-eslint/utils/ts-eslint";
|
|
@@ -11,7 +12,7 @@ interface Collector<T> {
|
|
|
11
12
|
};
|
|
12
13
|
visitor: RuleListener;
|
|
13
14
|
}
|
|
14
|
-
interface CollectorWithContext<T
|
|
15
|
+
interface CollectorWithContext<T> extends Collector<T> {
|
|
15
16
|
query: {
|
|
16
17
|
all(program: TSESTree.Program): T[];
|
|
17
18
|
};
|
|
@@ -19,11 +20,8 @@ interface CollectorWithContext<T, E> extends Collector<T> {
|
|
|
19
20
|
declare function components(ctx: RuleContext<string, unknown[]>, options?: {
|
|
20
21
|
collectDisplayName?: boolean;
|
|
21
22
|
hint?: bigint;
|
|
22
|
-
}): CollectorWithContext<core.FunctionComponentSemanticNode
|
|
23
|
-
declare function hooks(ctx: RuleContext<string, unknown[]>): CollectorWithContext<core.HookSemanticNode
|
|
24
|
-
key: string;
|
|
25
|
-
node: TSESTree.Node;
|
|
26
|
-
}>;
|
|
23
|
+
}): CollectorWithContext<core.FunctionComponentSemanticNode>;
|
|
24
|
+
declare function hooks(ctx: RuleContext<string, unknown[]>): CollectorWithContext<core.HookSemanticNode>;
|
|
27
25
|
interface RuleToolkit {
|
|
28
26
|
is: {
|
|
29
27
|
componentDefinition: (node: TSESTreeFunction, hint: bigint) => boolean;
|
|
@@ -101,6 +99,7 @@ interface RuleToolkit {
|
|
|
101
99
|
components: typeof components;
|
|
102
100
|
hooks: typeof hooks;
|
|
103
101
|
};
|
|
102
|
+
settings: ESLintReactSettingsNormalized;
|
|
104
103
|
}
|
|
105
104
|
interface RuleDefinition {
|
|
106
105
|
name: string;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as core from "@eslint-react/core";
|
|
2
|
+
import { getSettingsFromContext } from "@eslint-react/shared";
|
|
2
3
|
|
|
3
4
|
//#region package.json
|
|
4
5
|
var name = "@eslint-react/kit";
|
|
5
|
-
var version = "4.0.0-beta.
|
|
6
|
+
var version = "4.0.0-beta.2";
|
|
6
7
|
|
|
7
8
|
//#endregion
|
|
8
9
|
//#region src/index.ts
|
|
@@ -94,7 +95,8 @@ function createKit(ctx) {
|
|
|
94
95
|
collect: {
|
|
95
96
|
components,
|
|
96
97
|
hooks
|
|
97
|
-
}
|
|
98
|
+
},
|
|
99
|
+
settings: getSettingsFromContext(ctx)
|
|
98
100
|
};
|
|
99
101
|
}
|
|
100
102
|
function defineConfig(...rules) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/kit",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.2",
|
|
4
4
|
"description": "ESLint React's utility module for building custom rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -37,14 +37,15 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@typescript-eslint/utils": "^8.57.2",
|
|
40
|
-
"@eslint-react/ast": "4.0.0-beta.
|
|
41
|
-
"@eslint-react/
|
|
40
|
+
"@eslint-react/ast": "4.0.0-beta.2",
|
|
41
|
+
"@eslint-react/shared": "4.0.0-beta.2",
|
|
42
|
+
"@eslint-react/core": "4.0.0-beta.2"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"eslint": "^10.1.0",
|
|
45
|
-
"tsdown": "^0.21.
|
|
46
|
-
"@local/
|
|
47
|
-
"@local/
|
|
46
|
+
"tsdown": "^0.21.5",
|
|
47
|
+
"@local/configs": "0.0.0",
|
|
48
|
+
"@local/eff": "3.0.0-beta.72"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
51
|
"eslint": "^10.0.0",
|