Skip to content

[🐞] eslint rule qwik/use-method-usage does not account for renderHook testing utilities #8381

@ianlet

Description

@ianlet

Which component is affected?

Qwik Runtime

Describe the bug

The qwik/use-method-usage rule currently allows use* calls only inside component$() or use*-named functions. This is too strict for testing utilities like renderHook, which wraps callbacks in component$() internally but isn't recognized by the linter.

// ✅ Works — but only when no arguments are needed
const { result } = await renderHook(useCounter);

// ❌ ESLint error — even though renderHook wraps this in component$() internally
const { result } = await renderHook(() => useCounter(10));

The workaround is to extract a use*-named wrapper function, which is unnecessary boilerplate:

function useCounterFrom10() {
  return useCounter(10);
}
const { result } = await renderHook(useCounterFrom10);

This affects at least two testing libraries:

Suggested fix: In useMethodUsage.ts, when the parent is an ArrowFunctionExpression or FunctionExpression inside a CallExpression, also allow callee names matching renderHook:

 if (parent.parent.type === 'CallExpression') {
   if (
     parent.parent.callee.type === 'Identifier' &&
-    parent.parent.callee.name === 'component$'
+    (parent.parent.callee.name === 'component$' ||
+     parent.parent.callee.name === 'renderHook')
   ) {
     return;
   }
 }

A more flexible approach would be making the list of allowed caller names configurable via rule options. Though that might allow qwik users to completely bypass this rule in situations where it should not.

Reproduction

ianlet/qwik-testing-library#92

Steps to reproduce

  1. Install eslint-plugin-qwik
  2. Write a test using renderHook(() => useSomeHook(args))
  3. ESLint reports: Calling use* methods in wrong function.

System Info

N/A — this is about the ESLint rule logic, not runtime behavior

Additional Information

Related prior issue: #3787 (custom hooks were also incorrectly flagged)

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDeveloper Experience related issuebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions