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
- Install
eslint-plugin-qwik
- Write a test using
renderHook(() => useSomeHook(args))
- 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)
Which component is affected?
Qwik Runtime
Describe the bug
The
qwik/use-method-usagerule currently allowsuse*calls only insidecomponent$()oruse*-named functions. This is too strict for testing utilities likerenderHook, which wraps callbacks incomponent$()internally but isn't recognized by the linter.The workaround is to extract a
use*-named wrapper function, which is unnecessary boilerplate:This affects at least two testing libraries:
@noma.to/qwik-testing-libraryvitest-browser-qwikSuggested fix: In
useMethodUsage.ts, when the parent is anArrowFunctionExpressionorFunctionExpressioninside aCallExpression, also allow callee names matchingrenderHook: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
eslint-plugin-qwikrenderHook(() => useSomeHook(args))Calling use* methods in wrong function.System Info
Additional Information
Related prior issue: #3787 (custom hooks were also incorrectly flagged)