feat(oxlint): add prefer-explicit-variants rule#705
Merged
aidenybai merged 2 commits intoJun 6, 2026
Merged
Conversation
Flags a component that selects which component to render from 2+ boolean props, each used as the test of a two-sided JSX ternary (isThread ? <A/> : <B/> plus isEditing ? <C/> : <D/>) — the "explicit variants" smell from the composition-patterns guidance. Conservative by design: requires 2 distinct props, both ternary arms must be JSX (parens stripped for the Prettier multi-line shape), cross-cutting state/ responsive/auth booleans are excluded, and nested-function branches are pruned. App-only, warn severity.
commit: |
Member
Author
|
/rde parity |
|
❌ Parity failed — trace |
Member
Author
|
/rde parity |
Replace the rule-local JSX-arm check with a reusable utils/is-jsx-element-or-fragment.ts type-guard — the `isNodeOfType(x, "JSXElement") || isNodeOfType(x, "JSXFragment")` pattern inlined across ~20 rules. The rule strips parens at the call site and delegates the node check to the shared guard. No behavior change.
d942131
into
refactor/boolean-prefixed-prop-util
4 checks passed
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
Adds
prefer-explicit-variants(architecture,warn, app-only) — the one net-new lintable pattern from the vercel-labs composition-patterns skill (the rest are already shipped or aren't statically lintable).Catches a component that picks which component to render from 2+ boolean-prefixed props, each the test of a two-sided JSX ternary:
Stays quiet on: single boolean switch (
isMobile ? <A/> : <B/>), visibility toggles (? <X/> : null), cross-cutting state/responsive/auth booleans (isLoading,isError,isMobile, …), non-prefixed props, localuseStatebooleans, and nested-function branches.Precision: requires 2 distinct props; both arms must be JSX with parens/TS-wrappers stripped (so Prettier's multi-line
cond ? (<A/>) : (<B/>)is caught — thanks to the thermo review); curated state-boolean denylist for false-positive control.Test plan
run-oxlint/architecture.test.ts+ rule meta-tests (registry/metadata/tags/docs-url)typecheck/lint/format:checkFollow-ups (rule-validate stage)
eslint-plugin-react-doctortest-noisetier; threshold may tune)Note
Low Risk
New optional maintainability lint at warn severity with deliberate false-positive guards; no runtime or security impact.
Overview
Adds
react-doctor/prefer-explicit-variants, an architecture warn that nudges apps away from one component whose render path is driven by two or more boolean-prefixed props, each used as the test of a two-sided JSX ternary (both arms must be element/fragment; parens stripped for Prettier-shaped arms).The rule is registered in the oxlint plugin, tagged
test-noise/react-jsx-only, and listed inAPP_ONLY_RULE_KEYSso it runs on app/unknown packages but stays off confidently classified libraries.BOOLEAN_PROP_VARIANT_BRANCH_THRESHOLD(2) gates firing; a curated denylist skips cross-cutting booleans (isLoading,isMobile, etc.), and nested inline functions are not walked.Supporting change: shared
isJsxElementOrFragmenthelper plus a focused unit test suite and a minor changeset foroxlint-plugin-react-doctor.Reviewed by Cursor Bugbot for commit 003de9c. Bugbot is set up for automated code reviews on this repo. Configure here.