feat(architecture): add no-prop-drilling rule#700
Open
NisargIO wants to merge 1 commit into
Open
Conversation
Flags a prop forwarded untouched through 3+ same-file components — each a
pure pass-through that never reads it — before it's finally consumed, and
recommends lifting the value into a Context/Provider (or composing with
`children`). Sourced from the vercel-labs composition-patterns
(compound-components) skill; this drilling angle had no prior coverage.
The detector is scope-aware (uses context.scopes): it resolves each JSX
tag to a same-file component and each forwarded attribute value to a prop
parameter binding, so shadowed names, transformed values (user.name,
fn(user)), conditionals, {...spread}, and hand-offs to DOM or imported
components do not count as untouched forwarding. The chain is only
counted when it terminates in a real consumer, so pure-forwarding cycles
never produce a phantom diagnostic.
Conservative v1 (threshold 3, same-file only); 16 adversarial unit tests.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
commit: |
Contributor
|
No React Doctor issues found. 🎉 Reviewed by React Doctor for commit |
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.
Why
Catches a prop forwarded untouched through 3+ same-file components — each one a pure pass-through that never reads the prop — before it's finally used. That's prop drilling: the intermediate components exist only to relay a value, which couples them to a shape they don't care about and makes refactors noisy. The fix is to lift the value into a Context/Provider (or compose with
children), per the vercel-labscomposition-patterns(compound-components) skill.This angle had no prior coverage in the plugin — the only existing
passthroughlogic is zod's.passthrough()and a single-component wrapper check inno-multi-comp; there was no cross-component drilling analysis.Before (flagged):
After (quiet):
What changed
no-prop-drilling(architecture/, category Maintainability, severitywarn, tagstest-noise+react-jsx-only).PROP_DRILL_CHAIN_THRESHOLD(= 3) and terminates in a real consumer.context.scopes): resolves each JSX tag to a same-file component symbol and each forwarded value to its prop parameter binding, so it's robust to shadowing and renamed destructures rather than name-matching.user.name,fn(user), ternaries),{...spread}forwarding, non-destructuredprops.x,memo()/forwardRef()-wrapped components, member/namespaced JSX tags, and hand-offs to DOM elements or imported components (treated as consuming the prop — the chain ends there).PROP_DRILL_CHAIN_THRESHOLDtoconstants/thresholds.ts; regeneratesrule-registry.tsviapnpm gen.v1 non-goals (intentional)
Cross-file drilling,
{...spread}chains, non-destructured props, and HOC/wrapper indirection are out of scope — documented in-code. The rule errs conservative: false positives are treated as correctness bugs.Adversarial review
This rule was stress-tested with a 4-lens multi-agent review that empirically ran 173 candidate fixtures through the real harness (false-positives: 32, false-negatives: 61, AST edge-cases: 55, robustness: 25). Result: 0 false negatives, no crashes/hangs/parse errors, and one genuine false positive — a pure-forwarding cycle with no consumer (
A→B→C→B) manufacturing a phantom chain. That's fixed (chains now only count when they terminate in a consumer) and locked in with 2 regression tests.Test plan
pnpm exec vp test run src/plugin/rules/architecture/no-prop-drilling.test.ts— 16 pass (12 valid + 4 invalid adversarial cases incl. renamed pass-through, TS-cast hop, shadowing, imported terminus, cycles).pnpm --filter oxlint-plugin-react-doctor typecheck— clean.pnpm exec vp lint+vp fmt --checkon changed files — clean.src/plugin/rules/architecture/suite — 109 pass.🤖 Generated with Claude Code