Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/component/component-collector-legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/component/component-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/hook/hook-collector.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
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<string, ERHook>();
const fStack: [node: AST.TSESTreeFunction, id: O.Option<string>][] = [];
const onFunctionEnter = (node: AST.TSESTreeFunction) => {
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,
Expand Down
20 changes: 17 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading