fix(linter/react): return-position JSX detection (stacked on #22755)#1
Draft
pbomb wants to merge 1 commit into
Draft
Conversation
…narrowing shared helper Replaces the change to the shared `JsxFinder` (which affected every `*_contains_jsx` consumer) with dedicated return-position helpers used only where component detection is intended. - revert `JsxFinder` to "JSX anywhere"; `expression_contains_jsx` / `function_body_contains_jsx` / `function_contains_jsx` are unchanged for all other rules. - add `expression_returns_jsx` / `function_returns_jsx` / `function_body_returns_jsx` / `arrow_returns_jsx` (plus private `expression_is_jsx_value`): JSX in return position, recognizing conditionals, logical/sequence expressions, `React.createElement`, and JSX-valued identifiers; ignoring JSX passed only as a call argument. - use the returns helpers in display-name (variable declarator + `find_innermost_function_with_jsx`) and no-unstable-nested-components (arrow candidate + parent-component lookup). - regression guards in no-multi-comp / prefer-function-component pin the shared helpers' "JSX anywhere" behavior (these fail if `JsxFinder` is re-narrowed). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.
Note
Stacked on top of oxc-project#22755. The base branch here is a snapshot of that PR's head, so this PR's diff is only the delta — it can be cherry-picked / squashed straight into oxc-project#22755 if accepted. It is intentionally kept separate so oxc-project#22755's author can decide whether to incorporate it.
AI usage disclosure
Implemented with Claude Code, then reviewed and tested by me.
Summary
Addresses the change-request review on oxc-project#22755 (review). That PR narrowed the shared
JsxFinderso JSX in call-argument position is ignored everywhere — which (1) changes behavior for every*_contains_jsxconsumer (no-multi-comp,prefer-function-component, …) and (2) is narrower than upstreameslint-plugin-react, which still reports HOFs that return JSX via conditionals / logical exprs / sequences / JSX-valued identifiers.This delta swaps that approach for dedicated return-position helpers, used only where component detection is intended, and restores the shared helpers to their original "JSX anywhere" semantics.
Details
JsxFinderchange —expression_contains_jsx/function_body_contains_jsx/function_contains_jsxare unchanged for all other rules.utils/react.rs:expression_returns_jsx,function_returns_jsx,function_body_returns_jsx,arrow_returns_jsx, plus privateexpression_is_jsx_value. They detect JSX in return position — recognizing?:,&&/||, sequence expressions,React.createElement, and JSX-valued identifiers (const x = <div/>; return x;) — while ignoring JSX passed only as a call argument.display-name(variable declarator +find_innermost_function_with_jsx) andno-unstable-nested-components(arrow candidate + parent-component lookup). Named-function and HOC-argument paths are left on the shared helpers to avoid behavior drift.Tests
react/display-nameno longer flags arrows that only pass JSX as an argument oxc-project/oxc#22755's added pass/fail cases still pass;react_display_name.snapis unchanged (the PR's expected output is preserved).no-multi-compandprefer-function-componentthat pin the shared helpers' "JSX anywhere" behavior. These fail on fix(linter/react):react/display-nameno longer flags arrows that only pass JSX as an argument oxc-project/oxc#22755 as-is (the shared narrowing caused false negatives) and pass here — guarding against re-narrowing the shared helper.cargo test -p oxc_linter: 1170 passed, 0 failed. Clippy clean on changed code;just fmtapplied.Generated with Claude Code