Skip to content

Commit 0df80b1

Browse files
committed
refactor: replace 'uid' with 'getId'
1 parent 34fc195 commit 0df80b1

File tree

10 files changed

+25
-41
lines changed

10 files changed

+25
-41
lines changed

packages/core/docs/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
# @eslint-react/core
66

7-
## Namespaces
8-
9-
- [uid](namespaces/uid/README.md)
10-
117
## Interfaces
128

139
- [ERClassComponent](interfaces/ERClassComponent.md)
@@ -47,6 +43,7 @@
4743
- [getComponentNameFromIdentifier](functions/getComponentNameFromIdentifier.md)
4844
- [getElementRepresentName](functions/getElementRepresentName.md)
4945
- [getFunctionComponentIdentifier](functions/getFunctionComponentIdentifier.md)
46+
- [getId](functions/getId.md)
5047
- [hasNoneOrValidComponentName](functions/hasNoneOrValidComponentName.md)
5148
- [isCallFromReact](functions/isCallFromReact.md)
5249
- [isCallFromReactMember](functions/isCallFromReactMember.md)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / getId
6+
7+
# Function: getId()
8+
9+
> **getId**(): `string`
10+
11+
## Returns
12+
13+
`string`

packages/core/docs/namespaces/uid/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/core/docs/namespaces/uid/functions/next.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AST_NODE_TYPES } from "@typescript-eslint/types";
44
import type { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
55
import { match, P } from "ts-pattern";
66

7-
import { uid } from "../utils";
7+
import { getId } from "../utils";
88
import type { ERClassComponent } from "./component";
99
import { ERClassComponentFlag } from "./component-flag";
1010

@@ -89,7 +89,7 @@ export function useComponentCollectorLegacy() {
8989
const collect = (node: AST.TSESTreeClass) => {
9090
if (!isClassComponent(node)) return;
9191
const id = AST.getClassIdentifier(node);
92-
const key = uid.next().toString();
92+
const key = getId();
9393
const flag = isPureComponent(node)
9494
? ERClassComponentFlag.PureComponent
9595
: ERClassComponentFlag.None;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { match } from "ts-pattern";
99

1010
import { isChildrenOfCreateElement } from "../element";
1111
import { isReactHookCall } from "../hook";
12-
import { uid } from "../utils";
12+
import { getId } from "../utils";
1313
import type { ERFunctionComponent } from "./component";
1414
import { DEFAULT_COMPONENT_HINT, ERComponentHint } from "./component-collector-hint";
1515
import { ERFunctionComponentFlag } from "./component-flag";
@@ -74,7 +74,7 @@ export function useComponentCollector(
7474
][] = [];
7575
const getCurrentFunction = () => O.fromNullable(functionStack.at(-1));
7676
const onFunctionEnter = (node: AST.TSESTreeFunction) => {
77-
const key = uid.next().toString();
77+
const key = getId();
7878
functionStack.push([key, node, false, []]);
7979
};
8080
const onFunctionExit = () => {
@@ -117,7 +117,7 @@ export function useComponentCollector(
117117
const initPath = AST.getFunctionInitPath(currentFn);
118118
const id = getFunctionComponentIdentifier(currentFn, context);
119119
const name = O.flatMapNullable(id, getComponentNameFromIdentifier);
120-
const key = uid.next().toString();
120+
const key = getId();
121121
components.set(key, {
122122
_: key,
123123
id,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as AST from "@eslint-react/ast";
22
import { F, O } from "@eslint-react/eff";
33
import type { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
44

5-
import { uid } from "../utils";
5+
import { getId } from "../utils";
66
import type { ERHook } from "./hook";
77
import { isReactHookName } from "./hook-name";
88
import { isReactHookCall } from "./is";
@@ -14,7 +14,7 @@ export function useHookCollector() {
1414
const id = AST.getFunctionIdentifier(node);
1515
const name = O.flatMapNullable(id, (id) => id.name);
1616
if (O.isSome(id) && O.isSome(name) && isReactHookName(name.value)) {
17-
const key = uid.next().toString();
17+
const key = getId();
1818
fStack.push([node, O.some(key)]);
1919
hooks.set(key, {
2020
_: key,

packages/core/src/utils/get-id.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let id = 0n;
2+
3+
export const getId = () => (id++).toString();

packages/core/src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1+
export * from "./get-id";
12
export * from "./is-from-react";
23
export * from "./is-initialized-from-react";
34
export * from "./is-react-api";
4-
export * as uid from "./uid";

packages/core/src/utils/uid.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)