JS-2192 Fix S4782 false positive for external indexed access - #7694
Open
francois-mora-sonarsource wants to merge 2 commits into
Open
JS-2192 Fix S4782 false positive for external indexed access#7694francois-mora-sonarsource wants to merge 2 commits into
francois-mora-sonarsource wants to merge 2 commits into
Conversation
Contributor
Ruling ReportNo changes to ruling expected issues in this PR |
francois-mora-sonarsource
marked this pull request as ready for review
July 30, 2026 15:46
francois-mora-sonarsource
requested review from
a team
and removed request for
a team
July 30, 2026 16:19
Follow-up on the indexed-access fix: an access that resolves through an index signature rather than a named property (`ExternalRecord['anyKey']`) was still classified as project-local, so S4782 kept reporting it and its suggestion still made the property required. Resolve those accesses through the index signature's own declaration, and fall back to the declaration of the indexed type for signatures the checker synthesizes (mapped types such as `Record<K, V>`, which have no declaration node). Cover both shapes, plus the non-literal-index path that stays reportable, at the helper and rule levels, and restate the shared all-declarations-external rule and the known limitations in the docblock. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Code Review ✅ ApprovedClassifies index-signature access by origin in S4782 to prevent false positives on external indexed access. No issues found. OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Summary
Fix S4782 reporting an optional property whose type is indexed from an imported
optional property.
Root cause
The semantic classifier treated every indexed-access type as project-local,
even when the accessed property declaration came entirely from an external
library. Removing the reported
?then made the consumer property required.Change
Resolve literal indexed-access property symbols through the TypeScript checker.
Classify the access as external only when every property declaration is from an
external or TypeScript default-library source; unresolved and local accesses
remain reportable.
Validation
npx tsx --test packages/analysis/tests/jsts/rules/helpers/type-origin.test.ts packages/analysis/src/jsts/rules/S4782/unit.test.tsnpm run bbf