Skip to content

Commit 64823ca

Browse files
committed
chore: cleanup
1 parent 8e8160c commit 64823ca

18 files changed

+153
-79
lines changed

packages/core/docs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
- [getFunctionComponentId](functions/getFunctionComponentId.md)
122122
- [getJsxConfigFromAnnotation](functions/getJsxConfigFromAnnotation.md)
123123
- [getJsxConfigFromContext](functions/getJsxConfigFromContext.md)
124+
- [getPhaseKindOfFunction](functions/getPhaseKindOfFunction.md)
124125
- [hasAnyAttribute](functions/hasAnyAttribute.md)
125126
- [hasAttribute](functions/hasAttribute.md)
126127
- [hasEveryAttribute](functions/hasEveryAttribute.md)
@@ -135,7 +136,11 @@
135136
- [isComponentWrapperCallLoose](functions/isComponentWrapperCallLoose.md)
136137
- [isDeclaredInRenderPropLoose](functions/isDeclaredInRenderPropLoose.md)
137138
- [isFragmentElement](functions/isFragmentElement.md)
139+
- [isFunctionOfComponentDidMount](functions/isFunctionOfComponentDidMount.md)
140+
- [isFunctionOfComponentWillUnmount](functions/isFunctionOfComponentWillUnmount.md)
138141
- [isFunctionOfRenderMethod](functions/isFunctionOfRenderMethod.md)
142+
- [isFunctionOfUseEffectCleanup](functions/isFunctionOfUseEffectCleanup.md)
143+
- [isFunctionOfUseEffectSetup](functions/isFunctionOfUseEffectSetup.md)
139144
- [isHostElement](functions/isHostElement.md)
140145
- [isJsxLike](functions/isJsxLike.md)
141146
- [isJsxText](functions/isJsxText.md)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / getPhaseKindOfFunction
6+
7+
# Function: getPhaseKindOfFunction()
8+
9+
> **getPhaseKindOfFunction**(`node`): `null` \| [`ComponentPhaseKind`](../type-aliases/ComponentPhaseKind.md)
10+
11+
## Parameters
12+
13+
### node
14+
15+
`TSESTreeFunction`
16+
17+
## Returns
18+
19+
`null` \| [`ComponentPhaseKind`](../type-aliases/ComponentPhaseKind.md)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / isFunctionOfComponentDidMount
6+
7+
# Function: isFunctionOfComponentDidMount()
8+
9+
> **isFunctionOfComponentDidMount**(`node`): `boolean`
10+
11+
## Parameters
12+
13+
### node
14+
15+
`Node`
16+
17+
## Returns
18+
19+
`boolean`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / isFunctionOfComponentWillUnmount
6+
7+
# Function: isFunctionOfComponentWillUnmount()
8+
9+
> **isFunctionOfComponentWillUnmount**(`node`): `boolean`
10+
11+
## Parameters
12+
13+
### node
14+
15+
`Node`
16+
17+
## Returns
18+
19+
`boolean`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / isFunctionOfUseEffectCleanup
6+
7+
# Function: isFunctionOfUseEffectCleanup()
8+
9+
> **isFunctionOfUseEffectCleanup**(`node`): `boolean`
10+
11+
## Parameters
12+
13+
### node
14+
15+
`undefined` | `Node`
16+
17+
## Returns
18+
19+
`boolean`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / isFunctionOfUseEffectSetup
6+
7+
# Function: isFunctionOfUseEffectSetup()
8+
9+
> **isFunctionOfUseEffectSetup**(`node`): `boolean`
10+
11+
## Parameters
12+
13+
### node
14+
15+
`undefined` | `Node`
16+
17+
## Returns
18+
19+
`boolean`
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as AST from "@eslint-react/ast";
2+
import type { TSESTree } from "@typescript-eslint/types";
3+
4+
import { isComponentDidMount, isComponentWillUnmount } from "./component-method";
5+
6+
export function isFunctionOfComponentDidMount(node: TSESTree.Node) {
7+
return AST.isFunction(node)
8+
&& isComponentDidMount(node.parent)
9+
&& node.parent.value === node;
10+
}
11+
12+
export function isFunctionOfComponentWillUnmount(node: TSESTree.Node) {
13+
return AST.isFunction(node)
14+
&& isComponentWillUnmount(node.parent)
15+
&& node.parent.value === node;
16+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type * as AST from "@eslint-react/ast";
2+
import { dual } from "@eslint-react/eff";
3+
import { match } from "ts-pattern";
4+
5+
import { isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup } from "../hook/hook-parts";
6+
import { isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount } from "./component-method-parts";
7+
import { type ComponentPhaseKind, ComponentPhaseRelevance } from "./component-phase";
8+
9+
export const isInversePhase: {
10+
(a: ComponentPhaseKind): (b: ComponentPhaseKind) => boolean;
11+
(a: ComponentPhaseKind, b: ComponentPhaseKind): boolean;
12+
} = dual(2, (a: ComponentPhaseKind, b: ComponentPhaseKind) => ComponentPhaseRelevance.get(a) === b);
13+
14+
export function getPhaseKindOfFunction(node: AST.TSESTreeFunction) {
15+
return match<AST.TSESTreeFunction, ComponentPhaseKind | null>(node)
16+
.when(isFunctionOfUseEffectSetup, () => "setup")
17+
.when(isFunctionOfUseEffectCleanup, () => "cleanup")
18+
.when(isFunctionOfComponentDidMount, () => "mount")
19+
.when(isFunctionOfComponentWillUnmount, () => "unmount")
20+
.otherwise(() => null);
21+
}
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { dual } from "@eslint-react/eff";
21
import birecord from "birecord";
32

43
export type ComponentEffectPhaseKind = "cleanup" | "setup";
@@ -9,8 +8,3 @@ export const ComponentPhaseRelevance = birecord({
98
mount: "unmount",
109
setup: "cleanup",
1110
});
12-
13-
export const isInversePhase: {
14-
(a: ComponentPhaseKind): (b: ComponentPhaseKind) => boolean;
15-
(a: ComponentPhaseKind, b: ComponentPhaseKind): boolean;
16-
} = dual(2, (a: ComponentPhaseKind, b: ComponentPhaseKind) => ComponentPhaseRelevance.get(a) === b);

packages/core/src/component/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ export * from "./component-init-path";
99
export * from "./component-is";
1010
export type * from "./component-kind";
1111
export * from "./component-method";
12+
export * from "./component-method-parts";
1213
export * from "./component-name";
1314
export * from "./component-phase";
15+
export * from "./component-phase-helpers";
1416
export * from "./component-render-method";
1517
export * from "./component-render-prop";
1618
export type * from "./component-semantic-node";

0 commit comments

Comments
 (0)