Skip to content

Commit 80e673f

Browse files
committed
refactor(core): rename and consolidate component flag types
1 parent ba94d90 commit 80e673f

14 files changed

+70
-101
lines changed

packages/core/docs/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515

1616
## Type Aliases
1717

18-
- [ERClassComponentFlag](type-aliases/ERClassComponentFlag.md)
1918
- [ERComponent](type-aliases/ERComponent.md)
19+
- [ERComponentFlag](type-aliases/ERComponentFlag.md)
2020
- [ERComponentHint](type-aliases/ERComponentHint.md)
2121
- [ERComponentKind](type-aliases/ERComponentKind.md)
2222
- [EREffectKind](type-aliases/EREffectKind.md)
2323
- [EREffectPhaseKind](type-aliases/EREffectPhaseKind.md)
24-
- [ERFunctionComponentFlag](type-aliases/ERFunctionComponentFlag.md)
2524
- [ERHookKind](type-aliases/ERHookKind.md)
2625
- [ERLifecyclePhaseKind](type-aliases/ERLifecyclePhaseKind.md)
2726
- [ERPhaseKind](type-aliases/ERPhaseKind.md)
@@ -31,9 +30,8 @@
3130

3231
- [COMPONENT\_DISPLAY\_NAME\_ASSIGNMENT\_SELECTOR](variables/COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR.md)
3332
- [DEFAULT\_COMPONENT\_HINT](variables/DEFAULT_COMPONENT_HINT.md)
34-
- [ERClassComponentFlag](variables/ERClassComponentFlag.md)
33+
- [ERComponentFlag](variables/ERComponentFlag.md)
3534
- [ERComponentHint](variables/ERComponentHint.md)
36-
- [ERFunctionComponentFlag](variables/ERFunctionComponentFlag.md)
3735
- [ERPhaseRelevance](variables/ERPhaseRelevance.md)
3836
- [RE\_COMPONENT\_NAME](variables/RE_COMPONENT_NAME.md)
3937
- [RE\_HOOK\_NAME](variables/RE_HOOK_NAME.md)

packages/core/docs/type-aliases/ERClassComponentFlag.md

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / ERComponentFlag
6+
7+
# Type Alias: ERComponentFlag
8+
9+
> **ERComponentFlag**: `bigint`

packages/core/docs/type-aliases/ERFunctionComponentFlag.md

-9
This file was deleted.

packages/core/docs/variables/ERClassComponentFlag.md

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / ERComponentFlag
6+
7+
# Variable: ERComponentFlag
8+
9+
> **ERComponentFlag**: `object`
10+
11+
## Type declaration
12+
13+
### Async
14+
15+
> **Async**: `bigint`
16+
17+
### CreateElement
18+
19+
> **CreateElement**: `bigint`
20+
21+
### ForwardRef
22+
23+
> **ForwardRef**: `bigint`
24+
25+
### Memo
26+
27+
> **Memo**: `bigint`
28+
29+
### None
30+
31+
> **None**: `bigint` = `0n`
32+
33+
### PureComponent
34+
35+
> **PureComponent**: `bigint`

packages/core/docs/variables/ERFunctionComponentFlag.md

-23
This file was deleted.

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { _ } from "@eslint-react/eff";
33
import { getId } from "@eslint-react/shared";
44
import type { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
55

6-
import { ERClassComponentFlag } from "./component-flag";
6+
import { ERComponentFlag } from "./component-flag";
77
import type { ERClassComponent } from "./component-semantic-node";
88
import { isClassComponent, isPureComponent } from "./is";
99

@@ -28,8 +28,8 @@ export function useComponentCollectorLegacy() {
2828
const id = AST.getClassIdentifier(node);
2929
const key = getId();
3030
const flag = isPureComponent(node)
31-
? ERClassComponentFlag.PureComponent
32-
: ERClassComponentFlag.None;
31+
? ERComponentFlag.PureComponent
32+
: ERComponentFlag.None;
3333
components.set(
3434
key,
3535
{

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { isChildrenOfCreateElement } from "../element";
1111
import { isReactHookCall } from "../hook";
1212
import { DEFAULT_COMPONENT_HINT, ERComponentHint } from "./component-collector-hint";
1313
import { COMPONENT_DISPLAY_NAME_ASSIGNMENT_SELECTOR } from "./component-display-name";
14-
import { ERFunctionComponentFlag } from "./component-flag";
14+
import { ERComponentFlag } from "./component-flag";
1515
import { getFunctionComponentIdentifier } from "./component-id";
1616
import { isFunctionOfRenderMethod } from "./component-lifecycle";
1717
import { getComponentNameFromIdentifier, hasNoneOrValidComponentName } from "./component-name";
@@ -47,12 +47,12 @@ function hasValidHierarchy(node: AST.TSESTreeFunction, context: RuleContext, hin
4747
}
4848

4949
function getComponentFlag(initPath: ERFunctionComponent["initPath"]) {
50-
let flag = ERFunctionComponentFlag.None;
50+
let flag = ERComponentFlag.None;
5151
if (initPath != null && AST.hasCallInFunctionInitPath("memo", initPath)) {
52-
flag |= ERFunctionComponentFlag.Memo;
52+
flag |= ERComponentFlag.Memo;
5353
}
5454
if (initPath != null && AST.hasCallInFunctionInitPath("forwardRef", initPath)) {
55-
flag |= ERFunctionComponentFlag.ForwardRef;
55+
flag |= ERComponentFlag.ForwardRef;
5656
}
5757
return flag;
5858
}
+7-20
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1-
export type ERClassComponentFlag = bigint;
1+
/* eslint-disable perfectionist/sort-objects */
2+
export type ERComponentFlag = bigint;
23

3-
export const ERClassComponentFlag = {
4+
export const ERComponentFlag = {
45
None: 0n,
56
PureComponent: 1n << 0n,
6-
// Reserved for future use
7-
// CreateElement: 1n << 1n,
8-
};
9-
10-
export type ERFunctionComponentFlag = bigint;
11-
12-
/* eslint-disable perfectionist/sort-objects */
13-
export const ERFunctionComponentFlag = {
14-
None: 0n,
15-
Memo: 1n << 0n,
16-
ForwardRef: 1n << 1n,
17-
// Reserved for future use
18-
// CreateElement: 1n << 2n,
19-
// Reserved for future use
20-
// hasHooks: 1n << 3n,
21-
// Reserved for future use
22-
// Async: 1n << 4n,
7+
CreateElement: 1n << 1n,
8+
Memo: 1n << 2n,
9+
Async: 1n << 3n,
10+
ForwardRef: 1n << 4n,
2311
};
24-
/* eslint-enable perfectionist/sort-objects */

packages/core/src/component/component-semantic-node.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { TSESTree } from "@typescript-eslint/types";
44

55
import type { ERSemanticNode } from "../semantic-node";
66
import type { ERComponentHint } from "./component-collector-hint";
7-
import type { ERClassComponentFlag, ERFunctionComponentFlag } from "./component-flag";
7+
import type { ERComponentFlag } from "./component-flag";
88

99
/* eslint-disable perfectionist/sort-interfaces */
1010
export interface ERFunctionComponent extends ERSemanticNode {
@@ -14,7 +14,7 @@ export interface ERFunctionComponent extends ERSemanticNode {
1414
| TSESTree.Identifier[];
1515
kind: "function";
1616
node: AST.TSESTreeFunction;
17-
flag: ERFunctionComponentFlag;
17+
flag: ERComponentFlag;
1818
hint: ERComponentHint;
1919
initPath:
2020
| _
@@ -31,7 +31,7 @@ export interface ERClassComponent extends ERSemanticNode {
3131
| TSESTree.Identifier;
3232
kind: "class";
3333
node: AST.TSESTreeClass;
34-
flag: ERClassComponentFlag;
34+
flag: ERComponentFlag;
3535
hint: ERComponentHint;
3636
methods: AST.TSESTreeMethodOrProperty[];
3737
displayName:

packages/plugins/eslint-plugin-react-debug/src/rules/function-component.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DEFAULT_COMPONENT_HINT, ERFunctionComponentFlag, useComponentCollector } from "@eslint-react/core";
1+
import { DEFAULT_COMPONENT_HINT, ERComponentFlag, useComponentCollector } from "@eslint-react/core";
22
import type { RuleFeature } from "@eslint-react/shared";
33
import type { CamelCase } from "string-ts";
44

@@ -46,9 +46,9 @@ export default createRule<[], MessageID>({
4646
data: {
4747
name,
4848
displayName: displayName != null ? context.sourceCode.getText(displayName) : "none",
49-
forwardRef: (flag & ERFunctionComponentFlag.ForwardRef) > 0n,
49+
forwardRef: (flag & ERComponentFlag.ForwardRef) > 0n,
5050
hookCalls: hookCalls.length,
51-
memo: (flag & ERFunctionComponentFlag.Memo) > 0n,
51+
memo: (flag & ERComponentFlag.Memo) > 0n,
5252
},
5353
});
5454
}

packages/plugins/eslint-plugin-react-x/src/rules/no-missing-component-display-name.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as AST from "@eslint-react/ast";
2-
import { DEFAULT_COMPONENT_HINT, ERFunctionComponentFlag, useComponentCollector } from "@eslint-react/core";
2+
import { DEFAULT_COMPONENT_HINT, ERComponentFlag, useComponentCollector } from "@eslint-react/core";
33
import type { RuleFeature } from "@eslint-react/shared";
44
import type { CamelCase } from "string-ts";
55

@@ -46,7 +46,7 @@ export default createRule<[], MessageID>({
4646
"Program:exit"(node) {
4747
const components = ctx.getAllComponents(node);
4848
for (const { node, displayName, flag } of components.values()) {
49-
const isMemoOrForwardRef = (flag & (ERFunctionComponentFlag.ForwardRef | ERFunctionComponentFlag.Memo)) > 0n;
49+
const isMemoOrForwardRef = (flag & (ERComponentFlag.ForwardRef | ERComponentFlag.Memo)) > 0n;
5050
if (AST.getFunctionIdentifier(node) != null) {
5151
continue;
5252
}

packages/plugins/eslint-plugin-react-x/src/rules/no-redundant-should-component-update.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as AST from "@eslint-react/ast";
2-
import { ERClassComponentFlag, useComponentCollectorLegacy } from "@eslint-react/core";
2+
import { ERComponentFlag, useComponentCollectorLegacy } from "@eslint-react/core";
33
import type { RuleFeature } from "@eslint-react/shared";
44
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
55
import type { TSESTree } from "@typescript-eslint/utils";
@@ -47,7 +47,7 @@ export default createRule<[], MessageID>({
4747
const components = ctx.getAllComponents(node);
4848

4949
for (const { name = "PureComponent", node: component, flag } of components.values()) {
50-
if ((flag & ERClassComponentFlag.PureComponent) === 0n) {
50+
if ((flag & ERComponentFlag.PureComponent) === 0n) {
5151
continue;
5252
}
5353
const { body } = component.body;

0 commit comments

Comments
 (0)