fix(eslint-plugin-query): use Object.hasOwn to avoid Object.prototype false positives in no-unstable-deps#11125
Conversation
📝 WalkthroughWalkthroughThe ChangesUnstable dependency tracking
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
✨ 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 |
… false positives in no-unstable-deps The trackedVariables record lookup used bracket access which matches inherited Object.prototype properties (toString, constructor, etc.), causing false positives when those names appear in dependency arrays. Use Object.hasOwn for a safe own-property check instead.
0480692 to
adf4299
Compare
|
Rebased on latest main ✅ — merge conflict resolved. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts (1)
79-84: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winMake
combinedetection match the actual property key.This misses
useQueries({ 'combine': fn })because non-computed quoted keys are ASTLiteralnodes, and false-positive it when a computed key namedcombineis present because{ [combine]: fn }hasprop.key.name === 'combine'. Add!prop.computedand include string-literal keys for"combine".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts` around lines 79 - 84, Update the combine-property detection in the firstArg.properties check to require !prop.computed, while matching both identifier keys and non-computed string-literal keys whose value is "combine"; preserve the existing Property filtering and avoid treating computed keys such as {[combine]: fn} as matches.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In
`@packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts`:
- Around line 79-84: Update the combine-property detection in the
firstArg.properties check to require !prop.computed, while matching both
identifier keys and non-computed string-literal keys whose value is "combine";
preserve the existing Property filtering and avoid treating computed keys such
as {[combine]: fn} as matches.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f9b8f54c-3a40-4735-9e90-c3fe50849dea
📒 Files selected for processing (2)
packages/eslint-plugin-query/src/__tests__/no-unstable-deps.test.tspackages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/eslint-plugin-query/src/tests/no-unstable-deps.test.ts
|
Thanks for working on this! I also opened a PR addressing this issue earlier: #11117 |
The trackedVariables record lookup in the no-unstable-deps rule used bracket access (
trackedVariables[name] !== undefined) which matches inherited Object.prototype properties like toString, constructor, and valueOf. This caused false positives when those names appeared in dependency arrays alongside TanStack Query hooks.Fixes #11118
Summary by CodeRabbit
toString), preventing incorrect instability reports.