Skip to content

Commit deb62e0

Browse files
mixelburgTkDodo
andauthored
fix(eslint-plugin): normalize whitespace in allowList variable matching for multiline expressions (#10337)
* 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 * changeset --------- Co-authored-by: Maks Pikov <mixelburg@users.noreply.github.com> Co-authored-by: Dominik Dorfmeister 🔮 <office@dorfmeister.cc>
1 parent 67b12ae commit deb62e0

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

.changeset/violet-dogs-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/eslint-plugin-query': patch
3+
---
4+
5+
fix(eslint-plugin): normalize whitespace in allowList variable matching for multiline expressions

packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,20 @@ ruleTester.run('exhaustive-deps allowlist.variables', rule, {
21602160
}
21612161
`,
21622162
},
2163+
{
2164+
name: 'should ignore allowlisted variable when member access spans multiple lines',
2165+
options: [{ allowlist: { variables: ['ignored'] } }],
2166+
code: normalizeIndent`
2167+
function useThing() {
2168+
const ignored = { run: () => Promise.resolve() }
2169+
return useQuery({
2170+
queryKey: ['thing'],
2171+
queryFn: () => ignored
2172+
.run()
2173+
})
2174+
}
2175+
`,
2176+
},
21632177
],
21642178
invalid: [
21652179
{

packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export const ExhaustiveDepsUtils = {
282282
* Example: `a?.b.c!` -> `a.b.c`
283283
*/
284284
normalizeChain(text: string): string {
285-
return text.replace(/(?:\?(\.)|!)/g, '$1')
285+
return text.replace(/(?:\?(\.)|!)/g, '$1').replace(/\s+/g, '')
286286
},
287287

288288
/**

0 commit comments

Comments
 (0)