@eslint-react/kit 5.21.3 → 5.22.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/README.md +0 -85
- package/dist/index.js +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -5,89 +5,4 @@ ESLint React's utility module for building custom React rules with JavaScript fu
|
|
|
5
5
|
> [!WARNING]
|
|
6
6
|
> This module is currently in **beta**. APIs may change in future releases.
|
|
7
7
|
|
|
8
|
-
## Installation
|
|
9
|
-
|
|
10
|
-
```sh
|
|
11
|
-
npm install --save-dev @eslint-react/kit
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Quick Start
|
|
15
|
-
|
|
16
|
-
```ts title="eslint.config.ts"
|
|
17
|
-
import eslintReactKit, { merge } from "@eslint-react/kit";
|
|
18
|
-
import type { RuleFunction } from "@eslint-react/kit";
|
|
19
|
-
import { defineConfig } from "eslint/config";
|
|
20
|
-
|
|
21
|
-
/** Enforce function declarations for function components. */
|
|
22
|
-
function functionComponentDefinition(): RuleFunction {
|
|
23
|
-
return (context, { collect }) => {
|
|
24
|
-
const { query, visitor } = collect.components(context);
|
|
25
|
-
return merge(
|
|
26
|
-
visitor,
|
|
27
|
-
{
|
|
28
|
-
"Program:exit"(program) {
|
|
29
|
-
for (const { node } of query.all(program)) {
|
|
30
|
-
if (node.type === "FunctionDeclaration") continue;
|
|
31
|
-
context.report({
|
|
32
|
-
node,
|
|
33
|
-
message: "Function components must be defined with function declarations.",
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default defineConfig({
|
|
43
|
-
files: ["**/*.{ts,tsx}"],
|
|
44
|
-
extends: [
|
|
45
|
-
eslintReactKit()
|
|
46
|
-
.use(functionComponentDefinition)
|
|
47
|
-
.getConfig(),
|
|
48
|
-
],
|
|
49
|
-
});
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Rules are defined as **named functions** returning a `RuleFunction`. The function name is converted to kebab-case and registered under the `@eslint-react/kit` namespace (`functionComponentDefinition` → `@eslint-react/kit/function-component-definition`, enabled at `"error"` severity). Anonymous factories get a random hex name, which makes them impractical to disable via config or disable comments — useful for checks that must never be bypassed.
|
|
53
|
-
|
|
54
|
-
## API Overview
|
|
55
|
-
|
|
56
|
-
### `eslintReactKit()` (default export)
|
|
57
|
-
|
|
58
|
-
Creates a chainable `Builder` for registering custom rules:
|
|
59
|
-
|
|
60
|
-
| Method | Description |
|
|
61
|
-
| ----------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
62
|
-
| `use` | Registers a rule factory. The rule name is `kebabCase(factory.name)`; options are inferred from the factory signature. |
|
|
63
|
-
| `getConfig` | Returns a flat `Linter.Config` with the plugin and all registered rules enabled at `"error"`. |
|
|
64
|
-
| `getPlugin` | Returns the raw `ESLint.Plugin` for full control over namespace and severities. |
|
|
65
|
-
|
|
66
|
-
### `RuleFunction`
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
type RuleFunction = (context: RuleContext, toolkit: RuleToolkit) => RuleListener;
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### `RuleToolkit`
|
|
73
|
-
|
|
74
|
-
The second argument passed to every rule function:
|
|
75
|
-
|
|
76
|
-
- `collect` — Semantic collectors (`components(context, options?)`, `hooks(context)`). Each returns a `{ query, visitor }` pair; merge the `visitor` into your listener and call `query.all(program)` after traversal (e.g. in `Program:exit`) to get the detected semantic nodes.
|
|
77
|
-
- `is` — All predicates, with rule context pre-bound: component checks (`componentDecl`, `componentName`, `componentWrapperCall`, …), hook checks (`hookCall`, `hookDecl`, `useEffectLikeCall`, …), and React API checks (`memoCall`, `createElementCall`, every built-in hook call, plus the `API(name)` / `APICall(name)` factories for arbitrary APIs).
|
|
78
|
-
- `ast` — Low-level AST utilities: `findParent(node, test)` walks up ancestors; `unwrap(node)` strips TS type-expression wrappers (`as`, `satisfies`, `!`, …) and `ChainExpression`.
|
|
79
|
-
- `hint` — Bit-flags controlling what the component collector treats as a component (`hint.component.Default`, …).
|
|
80
|
-
- `flag` — Bit-flags describing component characteristics (`flag.component.Memo`, `flag.component.ForwardRef`, …).
|
|
81
|
-
- `settings` — The normalized `react-x` shared settings (`version`, `importSource`, `additionalEffectHooks`, …), so custom rules react to the same project settings as the built-in rules.
|
|
82
|
-
|
|
83
|
-
### `merge`
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
merge(...listeners: RuleListener[]): RuleListener
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
Merges multiple visitor objects into one; handlers for the same visitor key are chained in order. Essential for combining collector `visitor`s with your own logic.
|
|
90
|
-
|
|
91
|
-
## Documentation
|
|
92
|
-
|
|
93
8
|
For full documentation, see [https://beta.eslint-react.xyz/docs/packages/kit](https://beta.eslint-react.xyz/docs/packages/kit).
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/kit",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.22.1",
|
|
4
4
|
"description": "ESLint React's utility module for building custom React rules with JavaScript functions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@eslint-react/ast": "5.
|
|
39
|
-
"@eslint-react/core": "5.
|
|
40
|
-
"@eslint-react/shared": "5.
|
|
38
|
+
"@eslint-react/ast": "5.22.1",
|
|
39
|
+
"@eslint-react/core": "5.22.1",
|
|
40
|
+
"@eslint-react/shared": "5.22.1",
|
|
41
41
|
"@typescript-eslint/types": "^8.70.1",
|
|
42
42
|
"@typescript-eslint/utils": "^8.70.1",
|
|
43
43
|
"string-ts": "^2.3.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@eslint-react/eslint": "5.
|
|
46
|
+
"@eslint-react/eslint": "5.22.1",
|
|
47
47
|
"@local/configs": "0.0.0",
|
|
48
48
|
"eslint": "^10.11.0",
|
|
49
49
|
"tsdown": "^0.23.0",
|