Skip to content

[bug] false positive for @eslint-react/no-unnecessary-use-prefix rule #1181

@mcmxcdev

Description

@mcmxcdev

Describe the bug

We have code like below in a file called hooks.test.tsx:

const mockUseSession = vi.fn().mockReturnValue(sessionUser);

vi.mock("src/components/session/session", () => ({
  useSession: () => mockUseSession(),
}));

The content of src/components/session/session is as following:

export const useSession = (): Session | undefined => {
  const { session } = React.useContext(SessionContext);

  return session;
};

useSession in vi.mock is getting flagged with If your function doesn't call any Hooks, avoid the 'use' prefix. Instead, write it as a regular function without the 'use' prefix. but I would argue that useSession is a hook.

If the rule is unable to determine with certainty if it's actually a hook or not, it should rather not report on it.

Reproduction

No response

Expected behavior

Possibly eslint-react opting out of checking vi.mock blocks completely.

Platform and versions

Node.js v22.15.0

"@eslint-react/eslint-plugin": "2.0.0-beta.34"

Stack trace


Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions