fix(eslint-plugin): normalize whitespace in allowList variable matching for multiline expressions#10337
Conversation
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 TanStack#10334
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdded a test case validating that allowlisted variables are not flagged as missing dependencies regardless of formatting. Modified the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes #10334
Root Cause
When a member expression spans multiple lines in source code, returns the text verbatim including the newline and indentation:
computeRefPathsplits on'.'to extract the root identifier, so the root becomes'ignored\n '(with trailing whitespace) instead of'ignored'. This never matches the allowlisted variable name.Fix
Extend
normalizeChainto collapse whitespace in addition to stripping optional-chaining operators and non-null assertions. This makesignored\n .run→ignored.runbefore the path/root extraction.Changes
exhaustive-deps.utils.ts: add.replace(/\s+/g, '')tonormalizeChainexhaustive-deps.test.ts: add regression test for the multiline caseAll 1531 existing tests pass.
Summary by CodeRabbit
Tests
Bug Fixes