JS-1180 Fix FP on S6767 for props used through dynamic access or helper methods#6414
Conversation
|
github-actions[bot] 2026-02-18T20:04:33Z addressed |
Tests cover scenarios where React props are reported as unused but are actually consumed through indirect patterns: helper function calls, super(props), exported interfaces, HOC wrappers, bracket notation, spread operators, forwardRef, and context providers. Also includes a true positive case to verify direct unused props are still flagged. Relates to JS-1180
Add a decorator to suppress false positives when React props are used indirectly through patterns the upstream eslint-plugin-react rule cannot track. The decorator scans the file AST for eight indirect prop usage patterns: HOC export wrappers, props passed to helper functions, spread operators and rest destructuring, super(props) calls, bracket notation access, exported props interfaces, React.forwardRef wrappers, and context provider value attributes. If any pattern is detected, the unused-prop report is suppressed. Implementation follows the approved proposal algorithm using interceptReportForReact with a WeakMap cache for per-file scan results. Test uses NoTypeCheckingRuleTester to support TypeScript syntax parsing. Relates to JS-1180
Add detection for props closure in nested functions to fix 2 remaining
FP mismatches in FairsRail.tsx (title, subtitle). The upstream rule
misses prop usage when props.X is accessed inside a nested arrow
function closure (e.g. const Header = () => <div>{props.title}</div>
inside the component body). The new hasPropsClosureInNestedFunction
check detects function components with a `props` parameter that contain
nested functions (without their own `props` param) accessing `props.X`.
Verified safe against all 73 true-positive entries: class components
(PermissionPopup, RelationPermissionPopup, Timer, etc.) are unaffected
since they don't match the function-component-with-props-param pattern.
Function components with `(props)` param (ZeroState, MapContainer,
image.tsx, media-manager-dialog.tsx) don't have nested functions
accessing props.X without their own props parameter.
Added tests: nested function closure suppression (valid), nested
function with own props parameter does not suppress (invalid).
Ticket: JS-1180 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Reduce cognitive complexity of hasPatternInChildren function from 16 to 15 (typescript:S3776) by extracting the array element iteration logic into a separate hasPatternInArray helper function. This removes one level of nesting in the original function while preserving identical behavior.
b50920e to
bcfd298
Compare
FP impact review — consider removing
|
Comment: ## FP impact review — consider removing `isExportedPropsInterface` I ran a full FP impact review on this PR (1 053 resolved issues across 456 files). The fix overall is sound, but the `isExportedPropsInterface` pattern stands out as worth reconsidering. After analysing the corpus, the legitimate FPs caught by this pattern are almost entirely also caught by one of the other nine checks (the file also has an HOC export, a props spread, a helper-function call, etc.). In the rare cases where it is the **sole** trigger, the suppression is over-broad: we found genuinely unused props being silenced — props commented out, shadowed by local state, or simply never accessed. So in practice `isExportedPropsInterface` neither adds unique value nor improves precision: it misses false positives that the other patterns would already suppress, while introducing false negatives on top. It also makes the decorator harder to reason about. **Recommendation:** remove it. If ruling regressions surface after removal, they would identify a genuinely missing pattern that deserves a more targeted fix. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
francois-mora-sonarsource 2026-02-23T13:10:44Z addressed |
🤖 Generated with GitHub Actions
|




Fix false positives in rule S6767 (no-unused-prop-types) where React props are reported as unused but are actually consumed through indirect patterns that the upstream eslint-plugin-react rule cannot track.
Changes
interceptReportForReactthat suppresses false positive reports when indirect prop usage is detected. The decorator scans the file AST (with per-file WeakMap caching) for eight patterns:super(props)callsprops[key])React.forwardRefwrappersconst Header = () => <div>{props.title}</div>)hasPatternInArrayhelper to reduce cognitive complexity (fixes typescript:S3776)Testing
propsparameterRelates to JS-1180