Skip to content

prop-flow: detect props that are always passed the same value - #936

Merged
fxOne merged 1 commit into
masterfrom
issue-934-prop-flow-detect-props-that-are-always
Aug 2, 2026
Merged

prop-flow: detect props that are always passed the same value#936
fxOne merged 1 commit into
masterfrom
issue-934-prop-flow-detect-props-that-are-always

Conversation

@fxOne

@fxOne fxOne commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

prop-flow now reports props that are passed the same value at every call site. Constancy is orthogonal to whether an optional prop's ? earns its keep — a prop can be justified and still be constant everywhere it is passed — so it lands as its own field on PropAnalysis rather than as a sixth verdict. Values are read off the type, not the syntax, so size="sm", a const, an enum member and a property of an as const object all resolve to one value, and a single unreadable site leaves the claim unmade.

Changes

  • New constant field ({ coverage, value }) on every PropAnalysis, null where there is no finding. coverage: 'passes' means the passing sites agree; 'all' means the omissions land on the value too via the component's own binding default — the case where the prop can go away entirely. Nothing is reported below two passing sites.
  • New values.ts resolves values through checker.getTypeAtLocation plus the literal-type checks, covering string/number/boolean literals, boolean shorthand (<C dense /> is true), enum members and as const properties. A manual site or any type the checker cannot pin to a single literal suppresses the finding.
  • --all-props widens discovery to required props, not the report: a required prop appears only when it carries a constant value, under a new required verdict. Without the flag the output is byte-identical to before.
  • Binding defaults are now carried as values rather than a boolean. A pass-through level that binds its own default absorbs the omissions at its own call sites and feeds the default down, instead of counting them as omissions at the leaf — which reported an always-set prop as caller-dead. Each absorbed omission is listed as a real site at the call site where the default fires, so the counts still line up with the sites below.
  • Usage indexing (indexProgram, JSX tag resolution, the symbol-id allocator) moved out of analyzer.ts into a createUsageIndex module, which is what lets it be tested directly.
  • README gains a "Constant values" section, the --all-props row and the absorbed-default example; CHANGELOG cut to 2.0.0 and the version bumped.

Breaking changes in the library API and the --json shape (the CLI arguments and the text output only gained things):

  • OptionalProp is now DeclaredProp, with an added optional field
  • Analyzer.listOptionalProps is now listProps(component, { includeRequired })
  • PropAnalysis.constant is required, so every --json row carries it

Related issues

Closes #934

@fxOne
fxOne merged commit 2748454 into master Aug 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prop-flow: detect props that are always passed the same value

1 participant