prop-flow: resolve JSX spreads instead of reporting them as manual - #935
Merged
Merged
Conversation
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
prop-flowreported every JSX element carrying a{...spread}asmanual, and because the pass-through climb stopped there, one spread suppressed the verdict for that call site and for every leaf below it. Spreads are now resolved wherever the type system can answer the question, somanualis reserved for cases that genuinely cannot be decided statically. Two correctness bugs surfaced on the way — attribute precedence and pass-throughs inside render callbacks — are fixed here too.Changes
{...props}and{...rest}are followed one level up into the enclosing component, and a spread of an object literal (or of aconstbound to one) is read key by key.any, index signatures, and unions carrying the prop in only some constituents still reportmanual, as does an optional prop in a spread contesting an earlier value.<C title="x" {...props} />reported"x", but JSX is last-wins, so the spread overrides the attribute.AttrLookupdrops the'spread'sentinel for an explicit{ attr, spreadsAfter }shape that makes the ordering decidable.items.map(() => <C x={props.x} />)was classified as a local value, which could turn into a wrongjustifiedorunnecessary-optional.React.ComponentProps<'button'>inherits some 250 optional DOM and ARIA props; a verdict on those is true but not actionable, and it buried the props the author owns. A prop redeclared in the component's own type is still reported.renderX({ … })test helper) now reportsmanualinstead of counting its invisible callers as zero — which would report a live prop ascaller-dead.SiteKindloses itsspreadmember; former spread sites are reported aspassthrough/real/omit/manualwith a note. This changes--jsonoutput.analyzer.tsintoclassify.tsandcomponent.ts;Componentis now declared incomponent.tsand re-exported unchanged from the package index.spread.tsx,sources.tsx,vendored.tsx) plus a checked-infixtures/basic/node_modules/vendorstand-in — with a matching.gitignorenegation — so the dependency-prop rule can be exercised against a real external-library boundary.Related issues
Closes #933