Skip to content

Commit 6c08ea2

Browse files
committed
refactor: code optimizations
1 parent 4581b8e commit 6c08ea2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+455
-382
lines changed

.github/CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ ESLint React does not accept contributions of a purely utilitarian nature.
6060
- `@eslint-react/types`: Type definitions.
6161
- `@eslint-react/shared`: Shared constants and functions.
6262
- `@eslint-react/ast`: TSESTree AST primitive utility module.
63+
- `@eslint-react/var`: TSESTree AST utility module for static analysis of variables.
6364
- `@eslint-react/jsx`: TSESTree AST utility module for static analysis of JSX.
64-
- `@eslint-react/core`: ESLint utility module for static analysis of React core API and Patterns.
65+
- `@eslint-react/core`: ESLint utility module for static analysis of React core APIs and Patterns.
6566
- `@eslint-react/eslint-plugin-jsx`: ESLint plugin for JSX related rules.
6667
- `@eslint-react/eslint-plugin-react`: ESLint plugin for React related rules.
6768
- `@eslint-react/eslint-plugin-react-hooks`: ESLint plugin for React Hooks related rules.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.10.5
1+
0.10.6-beta.0

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "@eslint-react/monorepo",
3-
"version": "0.10.5",
3+
"version": "0.10.6-beta.0",
44
"description": "ESLint React's monorepo. A full TypeScript rewrite of eslint-plugin-react, with well-designed rule behaviors and sensible defaults for modern React apps.",
55
"keywords": [
66
"eslint",
77
"eslint-plugin",
88
"eslint-react",
9+
"eslint-plugin-react",
910
"react",
1011
"ts",
1112
"tsx",

packages/core/docs/README.md

Lines changed: 10 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,22 @@
1515

1616
- [ERClassComponentFlag](README.md#erclasscomponentflag)
1717
- [ERComponent](README.md#ercomponent)
18-
- [ERComponentCollectorHint](README.md#ercomponentcollectorhint)
18+
- [ERComponentHint](README.md#ercomponenthint)
1919
- [ERComponentInitPath](README.md#ercomponentinitpath)
2020
- [ERComponentKind](README.md#ercomponentkind)
21-
- [ERConstruction](README.md#erconstruction)
2221
- [ERFunctionComponentFlag](README.md#erfunctioncomponentflag)
2322

2423
### Variables
2524

26-
- [DEFAULT\_COMPONENT\_COLLECTOR\_HINT](README.md#default_component_collector_hint)
25+
- [DEFAULT\_COMPONENT\_HINT](README.md#default_component_hint)
2726
- [ERClassComponentFlag](README.md#erclasscomponentflag-1)
28-
- [ERComponentCollectorHint](README.md#ercomponentcollectorhint-1)
29-
- [ERConstruction](README.md#erconstruction-1)
27+
- [ERComponentHint](README.md#ercomponenthint-1)
3028
- [ERFunctionComponentFlag](README.md#erfunctioncomponentflag-1)
3129
- [RE\_COMPONENT\_NAME](README.md#re_component_name)
3230
- [RE\_HOOK\_NAME](README.md#re_hook_name)
3331

3432
### Functions
3533

36-
- [constructionDetector](README.md#constructiondetector)
3734
- [getComponentInitPath](README.md#getcomponentinitpath)
3835
- [getComponentNameFromIdentifier](README.md#getcomponentnamefromidentifier)
3936
- [getFunctionComponentIdentifier](README.md#getfunctioncomponentidentifier)
@@ -76,7 +73,6 @@
7673
- [isReactHookCallWithName](README.md#isreacthookcallwithname)
7774
- [isReactHookCallWithNameLoose](README.md#isreacthookcallwithnameloose)
7875
- [isReactHookName](README.md#isreacthookname)
79-
- [isUnstableAssignmentPattern](README.md#isunstableassignmentpattern)
8076
- [isUseCallbackCall](README.md#isusecallbackcall)
8177
- [isUseContextCall](README.md#isusecontextcall)
8278
- [isUseDebugValueCall](README.md#isusedebugvaluecall)
@@ -113,9 +109,9 @@ ___
113109

114110
___
115111

116-
### ERComponentCollectorHint
112+
### ERComponentHint
117113

118-
Ƭ **ERComponentCollectorHint**: `bigint`
114+
Ƭ **ERComponentHint**: `bigint`
119115

120116
___
121117

@@ -131,21 +127,15 @@ ___
131127

132128
___
133129

134-
### ERConstruction
135-
136-
Ƭ **ERConstruction**: `Data.TaggedEnum`\<\{ `Array`: \{ `node`: `TSESTree.ArrayExpression` ; `usage`: `O.Option`\<`TSESTree.Node`\> } ; `AssignmentExpression`: \{ `node`: `TSESTree.Node` ; `usage`: `O.Option`\<`TSESTree.Node`\> } ; `ClassExpression`: \{ `node`: `TSESTree.ClassExpression` ; `usage`: `O.Option`\<`TSESTree.Node`\> } ; `FunctionDeclaration`: \{ `node`: `TSESTree.FunctionDeclaration` ; `usage`: `O.Option`\<`TSESTree.Expression` \| `TSESTree.Identifier`\> } ; `FunctionExpression`: \{ `node`: `TSESTree.ArrowFunctionExpression` \| `TSESTree.FunctionExpression` ; `usage`: `O.Option`\<`TSESTree.Node`\> } ; `JSXElement`: \{ `node`: `TSESTree.JSXElement` ; `usage`: `O.Option`\<`TSESTree.Node`\> } ; `JSXFragment`: \{ `node`: `TSESTree.JSXFragment` ; `usage`: `O.Option`\<`TSESTree.Node`\> } ; `NewExpression`: \{ `node`: `TSESTree.NewExpression` ; `usage`: `O.Option`\<`TSESTree.Node`\> } ; `None`: {} ; `ObjectExpression`: \{ `node`: `TSESTree.ObjectExpression` ; `usage`: `O.Option`\<`TSESTree.Node`\> } ; `RegExpLiteral`: \{ `node`: `TSESTree.Literal` ; `usage`: `O.Option`\<`TSESTree.Node`\> } }\>
137-
138-
___
139-
140130
### ERFunctionComponentFlag
141131

142132
Ƭ **ERFunctionComponentFlag**: `bigint`
143133

144134
## Variables
145135

146-
### DEFAULT\_COMPONENT\_COLLECTOR\_HINT
136+
### DEFAULT\_COMPONENT\_HINT
147137

148-
`Const` **DEFAULT\_COMPONENT\_COLLECTOR\_HINT**: `bigint`
138+
`Const` **DEFAULT\_COMPONENT\_HINT**: `bigint`
149139

150140
___
151141

@@ -162,9 +152,9 @@ ___
162152

163153
___
164154

165-
### ERComponentCollectorHint
155+
### ERComponentHint
166156

167-
**ERComponentCollectorHint**: `Object`
157+
**ERComponentHint**: `Object`
168158

169159
hints for component collector
170160

@@ -191,28 +181,6 @@ hints for component collector
191181

192182
___
193183

194-
### ERConstruction
195-
196-
**ERConstruction**: `Object`
197-
198-
#### Type declaration
199-
200-
| Name | Type |
201-
| :------ | :------ |
202-
| `Array` | `Constructor`\<`Data`\<\{ `_tag`: ``"Array"`` ; `node`: `ArrayExpression` ; `usage`: `Option`\<`Node`\> }\>, ``"_tag"``\> |
203-
| `AssignmentExpression` | `Constructor`\<`Data`\<\{ `_tag`: ``"AssignmentExpression"`` ; `node`: `Node` ; `usage`: `Option`\<`Node`\> }\>, ``"_tag"``\> |
204-
| `ClassExpression` | `Constructor`\<`Data`\<\{ `_tag`: ``"ClassExpression"`` ; `node`: `ClassExpression` ; `usage`: `Option`\<`Node`\> }\>, ``"_tag"``\> |
205-
| `FunctionDeclaration` | `Constructor`\<`Data`\<\{ `_tag`: ``"FunctionDeclaration"`` ; `node`: `FunctionDeclaration` ; `usage`: `Option`\<`Expression`\> }\>, ``"_tag"``\> |
206-
| `FunctionExpression` | `Constructor`\<`Data`\<\{ `_tag`: ``"FunctionExpression"`` ; `node`: `ArrowFunctionExpression` \| `FunctionExpression` ; `usage`: `Option`\<`Node`\> }\>, ``"_tag"``\> |
207-
| `JSXElement` | `Constructor`\<`Data`\<\{ `_tag`: ``"JSXElement"`` ; `node`: `JSXElement` ; `usage`: `Option`\<`Node`\> }\>, ``"_tag"``\> |
208-
| `JSXFragment` | `Constructor`\<`Data`\<\{ `_tag`: ``"JSXFragment"`` ; `node`: `JSXFragment` ; `usage`: `Option`\<`Node`\> }\>, ``"_tag"``\> |
209-
| `NewExpression` | `Constructor`\<`Data`\<\{ `_tag`: ``"NewExpression"`` ; `node`: `NewExpression` ; `usage`: `Option`\<`Node`\> }\>, ``"_tag"``\> |
210-
| `None` | `Constructor`\<`Data`\<\{ `_tag`: ``"None"`` }\>, ``"_tag"``\> |
211-
| `ObjectExpression` | `Constructor`\<`Data`\<\{ `_tag`: ``"ObjectExpression"`` ; `node`: `ObjectExpression` ; `usage`: `Option`\<`Node`\> }\>, ``"_tag"``\> |
212-
| `RegExpLiteral` | `Constructor`\<`Data`\<\{ `_tag`: ``"RegExpLiteral"`` ; `node`: `Literal` ; `usage`: `Option`\<`Node`\> }\>, ``"_tag"``\> |
213-
214-
___
215-
216184
### ERFunctionComponentFlag
217185

218186
**ERFunctionComponentFlag**: `Object`
@@ -239,44 +207,6 @@ ___
239207

240208
## Functions
241209

242-
### constructionDetector
243-
244-
**constructionDetector**\<`T`\>(`context`): (`node`: `TSESTree.Node`) => [`ERConstruction`](README.md#erconstruction)
245-
246-
Get a function that detects the construction of a given node.
247-
248-
#### Type parameters
249-
250-
| Name | Type |
251-
| :------ | :------ |
252-
| `T` | extends `Readonly`\<`RuleContext`\<`string`, readonly `unknown`[]\>\> |
253-
254-
#### Parameters
255-
256-
| Name | Type | Description |
257-
| :------ | :------ | :------ |
258-
| `context` | `T` | The rule context |
259-
260-
#### Returns
261-
262-
`fn`
263-
264-
A function that detects the construction of a given node
265-
266-
▸ (`node`): [`ERConstruction`](README.md#erconstruction)
267-
268-
##### Parameters
269-
270-
| Name | Type |
271-
| :------ | :------ |
272-
| `node` | `TSESTree.Node` |
273-
274-
##### Returns
275-
276-
[`ERConstruction`](README.md#erconstruction)
277-
278-
___
279-
280210
### getComponentInitPath
281211

282212
**getComponentInitPath**(`node`): `O.Option`\<[`ERComponentInitPath`](README.md#ercomponentinitpath)\>
@@ -1084,24 +1014,6 @@ ___
10841014

10851015
___
10861016

1087-
### isUnstableAssignmentPattern
1088-
1089-
**isUnstableAssignmentPattern**(`node`): node is AssignmentPattern & Object
1090-
1091-
Check if the given node is an unstable assignment pattern (will change between assignments)
1092-
1093-
#### Parameters
1094-
1095-
| Name | Type | Description |
1096-
| :------ | :------ | :------ |
1097-
| `node` | `AssignmentPattern` | The AST node to check |
1098-
1099-
#### Returns
1100-
1101-
node is AssignmentPattern & Object
1102-
1103-
___
1104-
11051017
### isUseCallbackCall
11061018

11071019
**isUseCallbackCall**(`node`, `context`, `pragma`): `boolean`
@@ -1459,7 +1371,7 @@ ___
14591371
| Name | Type | Default value |
14601372
| :------ | :------ | :------ |
14611373
| `context` | `Readonly`\<`RuleContext`\<`string`, readonly `unknown`[]\>\> | `undefined` |
1462-
| `hint` | `bigint` | `DEFAULT_COMPONENT_COLLECTOR_HINT` |
1374+
| `hint` | `bigint` | `DEFAULT_COMPONENT_HINT` |
14631375
| `pragma` | `string` | `undefined` |
14641376

14651377
#### Returns

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@eslint-react/core",
3-
"version": "0.10.5",
4-
"description": "ESLint React's ESLint utility module for static analysis of React core API and Patterns.",
3+
"version": "0.10.6-beta.0",
4+
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and Patterns.",
55
"homepage": "https://github.com/rel1cx/eslint-react",
66
"bugs": {
77
"url": "https://github.com/rel1cx/eslint-react/issues"
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { JSXValueCheckHint } from "@eslint-react/jsx";
1+
import { JSXValueHint } from "@eslint-react/jsx";
22

3-
export type ERComponentCollectorHint = bigint;
3+
export type ERComponentHint = bigint;
44

55
/* eslint-disable perfectionist/sort-objects */
66
/**
77
* hints for component collector
88
*/
9-
export const ERComponentCollectorHint = {
10-
...JSXValueCheckHint,
11-
// 1n << 0n - 1n << 63n are reserved for JSXValueCheckHint
9+
export const ERComponentHint = {
10+
...JSXValueHint,
11+
// 1n << 0n - 1n << 63n are reserved for JSXValueHint
1212
// Skip function component created by React.memo
1313
SkipMemo: 1n << 64n,
1414
// Skip function component created by React.forwardRef
@@ -24,8 +24,8 @@ export const ERComponentCollectorHint = {
2424
} as const;
2525
/* eslint-enable perfectionist/sort-objects */
2626

27-
export const DEFAULT_COMPONENT_COLLECTOR_HINT = 0n
28-
| ERComponentCollectorHint.SkipUndefinedLiteral
29-
| ERComponentCollectorHint.SkipBooleanLiteral
30-
| ERComponentCollectorHint.SkipStringLiteral
31-
| ERComponentCollectorHint.SkipNumberLiteral;
27+
export const DEFAULT_COMPONENT_HINT = 0n
28+
| ERComponentHint.SkipUndefinedLiteral
29+
| ERComponentHint.SkipBooleanLiteral
30+
| ERComponentHint.SkipStringLiteral
31+
| ERComponentHint.SkipNumberLiteral;

packages/core/src/component/component-collector.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { isMatching, match } from "ts-pattern";
1818

1919
import { isReactHookCall } from "../hook";
2020
import type { ERFunctionComponent } from "./component";
21-
import { DEFAULT_COMPONENT_COLLECTOR_HINT, ERComponentCollectorHint } from "./component-collector-hint";
21+
import { DEFAULT_COMPONENT_HINT, ERComponentHint } from "./component-collector-hint";
2222
import { ERFunctionComponentFlag } from "./component-flag";
2323
import { getFunctionComponentIdentifier } from "./component-identifier";
2424
import { getComponentInitPath, hasCallInInitPath } from "./component-init-path";
@@ -41,19 +41,19 @@ function hasValidHierarchy(node: TSESTreeFunction, context: RuleContext, hint: b
4141
return false;
4242
}
4343

44-
if (hint & ERComponentCollectorHint.SkipMapCallback && isMapCall(node.parent)) {
44+
if (hint & ERComponentHint.SkipMapCallback && isMapCall(node.parent)) {
4545
return false;
4646
}
4747

48-
if (hint & ERComponentCollectorHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
48+
if (hint & ERComponentHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
4949
return false;
5050
}
5151

52-
if (hint & ERComponentCollectorHint.SkipClassMethod && isFunctionOfClassMethod(node.parent)) {
52+
if (hint & ERComponentHint.SkipClassMethod && isFunctionOfClassMethod(node.parent)) {
5353
return false;
5454
}
5555

56-
if (hint & ERComponentCollectorHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
56+
if (hint & ERComponentHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
5757
return false;
5858
}
5959

@@ -88,7 +88,7 @@ function getComponentFlag(initPath: ERFunctionComponent["initPath"], pragma: str
8888

8989
export function useComponentCollector(
9090
context: RuleContext,
91-
hint: bigint = DEFAULT_COMPONENT_COLLECTOR_HINT,
91+
hint: bigint = DEFAULT_COMPONENT_HINT,
9292
pragma = getPragmaFromContext(context),
9393
) {
9494
const components = new Map<string, ERFunctionComponent>();

packages/core/src/component/component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { O } from "@eslint-react/tools";
33
import type { TSESTree } from "@typescript-eslint/types";
44

55
import type { ERAnalyzerNode } from "../internal";
6-
import type { ERComponentCollectorHint } from "./component-collector-hint";
6+
import type { ERComponentHint } from "./component-collector-hint";
77
import type { ERClassComponentFlag, ERFunctionComponentFlag } from "./component-flag";
88
import type { ERComponentInitPath } from "./component-init-path";
99

@@ -13,7 +13,7 @@ export interface ERFunctionComponent extends ERAnalyzerNode {
1313
kind: "function";
1414
node: TSESTreeFunction;
1515
flag: ERFunctionComponentFlag;
16-
hint: ERComponentCollectorHint;
16+
hint: ERComponentHint;
1717
initPath: O.Option<ERComponentInitPath>;
1818
hookCalls: TSESTree.CallExpression[];
1919
displayName: O.Option<TSESTree.Expression>;
@@ -24,7 +24,7 @@ export interface ERClassComponent extends ERAnalyzerNode {
2424
kind: "class";
2525
node: TSESTreeClass;
2626
flag: ERClassComponentFlag;
27-
hint: ERComponentCollectorHint;
27+
hint: ERComponentHint;
2828
methods: (TSESTree.MethodDefinition | TSESTree.PropertyDefinition)[];
2929
displayName: O.Option<TSESTree.Expression>;
3030
}

0 commit comments

Comments
 (0)