diff --git a/packages/core/package.json b/packages/core/package.json index a65382858..d6583fbf7 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -50,8 +50,8 @@ "@typescript-eslint/type-utils": "^8.19.0", "@typescript-eslint/types": "^8.19.0", "@typescript-eslint/utils": "^8.19.0", - "short-unique-id": "^5.2.0", - "ts-pattern": "^5.6.0" + "ts-pattern": "^5.6.0", + "uid": "^2.0.2" }, "devDependencies": { "@workspace/configs": "workspace:*", diff --git a/packages/core/src/component/component-collector-legacy.ts b/packages/core/src/component/component-collector-legacy.ts index a1e8d958d..9366412aa 100644 --- a/packages/core/src/component/component-collector-legacy.ts +++ b/packages/core/src/component/component-collector-legacy.ts @@ -2,14 +2,12 @@ import * as AST from "@eslint-react/ast"; import { O } from "@eslint-react/eff"; import { AST_NODE_TYPES } from "@typescript-eslint/types"; import type { ESLintUtils, TSESTree } from "@typescript-eslint/utils"; -import ShortUniqueId from "short-unique-id"; import { match, P } from "ts-pattern"; +import { uid } from "uid"; import type { ERClassComponent } from "./component"; import { ERClassComponentFlag } from "./component-flag"; -const uid = new ShortUniqueId({ length: 10 }); - /** * Check if a node is a React class component * @param node The AST node to check @@ -94,7 +92,7 @@ export function useComponentCollectorLegacy() { const collect = (node: AST.TSESTreeClass) => { if (!isClassComponent(node)) return; const id = AST.getClassIdentifier(node); - const key = uid.rnd(); + const key = uid(10); const flag = isPureComponent(node) ? ERClassComponentFlag.PureComponent : ERClassComponentFlag.None; diff --git a/packages/core/src/component/component-collector.ts b/packages/core/src/component/component-collector.ts index 2e054964c..1c76df7b6 100644 --- a/packages/core/src/component/component-collector.ts +++ b/packages/core/src/component/component-collector.ts @@ -5,8 +5,8 @@ import type { RuleContext } from "@eslint-react/types"; import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES } from "@typescript-eslint/types"; import type { ESLintUtils } from "@typescript-eslint/utils"; -import ShortUniqueId from "short-unique-id"; import { match } from "ts-pattern"; +import { uid } from "uid"; import { isChildrenOfCreateElement } from "../element"; import { isReactHookCall } from "../hook"; @@ -18,8 +18,6 @@ import { getComponentNameFromIdentifier } from "./component-name"; import { isFunctionOfRenderMethod } from "./component-render-method"; import { hasNoneOrValidComponentName } from "./misc"; -const uid = new ShortUniqueId({ length: 10 }); - function hasValidHierarchy(node: AST.TSESTreeFunction, context: RuleContext, hint: bigint) { if (isChildrenOfCreateElement(node, context) || isFunctionOfRenderMethod(node)) { return false; @@ -75,7 +73,7 @@ export function useComponentCollector( hookCalls: TSESTree.CallExpression[], ][] = []; const getCurrentFunction = () => O.fromNullable(functionStack.at(-1)); - const onFunctionEnter = (node: AST.TSESTreeFunction) => functionStack.push([uid.rnd(), node, false, []]); + const onFunctionEnter = (node: AST.TSESTreeFunction) => functionStack.push([uid(10), node, false, []]); const onFunctionExit = () => { const [key, fn, isComponent] = functionStack.at(-1) ?? []; if (!key || !fn || !isComponent) return functionStack.pop(); @@ -119,7 +117,7 @@ export function useComponentCollector( const initPath = AST.getFunctionInitPath(currentFn); const id = getFunctionComponentIdentifier(currentFn, context); const name = O.flatMapNullable(id, getComponentNameFromIdentifier); - const key = uid.rnd(); + const key = uid(10); components.set(key, { _: key, id, diff --git a/packages/core/src/hook/hook-collector.ts b/packages/core/src/hook/hook-collector.ts index 4230618c4..682649501 100644 --- a/packages/core/src/hook/hook-collector.ts +++ b/packages/core/src/hook/hook-collector.ts @@ -1,14 +1,12 @@ import * as AST from "@eslint-react/ast"; import { F, O } from "@eslint-react/eff"; import type { ESLintUtils, TSESTree } from "@typescript-eslint/utils"; -import ShortUniqueId from "short-unique-id"; +import { uid } from "uid"; import type { ERHook } from "./hook"; import { isReactHookName } from "./hook-name"; import { isReactHookCall } from "./is"; -const uid = new ShortUniqueId({ length: 10 }); - export function useHookCollector() { const hooks = new Map(); const fStack: [node: AST.TSESTreeFunction, id: O.Option][] = []; @@ -16,7 +14,7 @@ export function useHookCollector() { const id = AST.getFunctionIdentifier(node); const name = O.flatMapNullable(id, (id) => id.name); if (O.isSome(id) && O.isSome(name) && isReactHookName(name.value)) { - const key = uid.rnd(); + const key = uid(10); fStack.push([node, O.some(key)]); hooks.set(key, { _: key, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b7e2b6573..641b7d3c0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -470,12 +470,12 @@ importers: '@typescript-eslint/utils': specifier: ^8.19.0 version: 8.19.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.7.2) - short-unique-id: - specifier: ^5.2.0 - version: 5.2.0 ts-pattern: specifier: ^5.6.0 version: 5.6.0 + uid: + specifier: ^2.0.2 + version: 2.0.2 devDependencies: '@workspace/configs': specifier: workspace:* @@ -2929,6 +2929,10 @@ packages: '@jridgewell/trace-mapping@0.3.25': resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==} + '@lukeed/csprng@1.1.0': + resolution: {integrity: sha512-Z7C/xXCiGWsg0KuKsHTKJxbWhpI3Vs5GwLfOean7MGyVFGqdRgBbAjOCh6u4bbjPc/8MJ2pZmK/0DLdCbivLDA==} + engines: {node: '>=8'} + '@manypkg/find-root@1.1.0': resolution: {integrity: sha512-mki5uBvhHzO8kYYix/WRy2WX8S3B5wdVSc9D6KcU5lQNglP2yt58/VfLuAK49glRXChosY8ap2oJ1qgma3GUVA==} @@ -7882,6 +7886,10 @@ packages: ufo@1.5.4: resolution: {integrity: sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ==} + uid@2.0.2: + resolution: {integrity: sha512-u3xV3X7uzvi5b1MncmZo3i2Aw222Zk1keqLA1YkHldREkAhAqi65wuPfe7lHx8H/Wzy+8CE7S7uS3jekIM5s8g==} + engines: {node: '>=8'} + uncrypto@0.1.3: resolution: {integrity: sha512-Ql87qFHB3s/De2ClA9e0gsnS6zXG27SkTiSJwjCc9MebbfapQfuPzumMIUMi38ezPZVNFcHI9sUIepeQfw8J8Q==} @@ -10094,6 +10102,8 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.0 + '@lukeed/csprng@1.1.0': {} + '@manypkg/find-root@1.1.0': dependencies: '@babel/runtime': 7.26.0 @@ -15887,6 +15897,10 @@ snapshots: ufo@1.5.4: {} + uid@2.0.2: + dependencies: + '@lukeed/csprng': 1.1.0 + uncrypto@0.1.3: {} undici-types@6.20.0: {}