From 84adca5d7ca70f658bb5f213f1994ecdee419bf9 Mon Sep 17 00:00:00 2001 From: Maks Pikov Date: Thu, 26 Mar 2026 22:10:01 +0000 Subject: [PATCH] fix(eslint-plugin): normalize whitespace in allowList variable matching When a member expression spans multiple lines (e.g. `ignored\n .run()`), `sourceCode.getText()` preserves the newline. The root segment extracted by splitting on `.'` then becomes `'ignored\n '`, which never matches the allowlisted variable name `'ignored'`. Fix: extend `normalizeChain` to also collapse all whitespace, so multi-line chains produce the same identifier path as single-line ones. Fixes #10334 --- .../src/__tests__/exhaustive-deps.test.ts | 14 ++++++++++++++ .../rules/exhaustive-deps/exhaustive-deps.utils.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts b/packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts index 6ee61ca8d7..7e67ae8540 100644 --- a/packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts +++ b/packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts @@ -2160,6 +2160,20 @@ ruleTester.run('exhaustive-deps allowlist.variables', rule, { } `, }, + { + name: 'should ignore allowlisted variable when member access spans multiple lines', + options: [{ allowlist: { variables: ['ignored'] } }], + code: normalizeIndent` + function useThing() { + const ignored = { run: () => Promise.resolve() } + return useQuery({ + queryKey: ['thing'], + queryFn: () => ignored + .run() + }) + } + `, + }, ], invalid: [ { diff --git a/packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.utils.ts b/packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.utils.ts index 8e67fd6a8d..135a5b620d 100644 --- a/packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.utils.ts +++ b/packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.utils.ts @@ -282,7 +282,7 @@ export const ExhaustiveDepsUtils = { * Example: `a?.b.c!` -> `a.b.c` */ normalizeChain(text: string): string { - return text.replace(/(?:\?(\.)|!)/g, '$1') + return text.replace(/(?:\?(\.)|!)/g, '$1').replace(/\s+/g, '') }, /**