fix: align JSX expression line handling with upstream - #2071
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
Fix
react/jsx-one-expression-per-linesoliteralandsingle-childallowances work when JSX follows a line break or comment. For example, this remains valid withallow: "literal":Preserve complete trailing ASCII-space runs, distinguish LF from bare CR when fixing multiline text, and exclude disabled reports from adjacent-fix selection. Reuse tsgo's trivia scanner and rslint's ECMAScript whitespace helpers; avoid reversing entire text nodes, sorting children already in source order, and computing fix selection for diagnostics-only requests.
Validation:
eslint-plugin-react@7.37.5using ESLint 8.57.1 and 10.10.0: zero differences in diagnostic messages, positions, counts, or final multipass output. The ESLint 10 driver delegates its removedSourceCode.isSpaceBetweenTokensmethod to the unchanged ESLint 8 implementation; unused-disable reporting is disabled to isolate this rule.go test ./internal/plugins/react/rules/jsx_one_expression_per_line -count=3passed, including regression cases and edit-demand checks.pnpm run check-spell,pnpm run format:check, andpnpm exec golangci-lint run --new-from-merge-base=origin/main ./internal/plugins/react/rules/jsx_one_expression_per_line/...passed. Go lint was limited to this package and introduced code.Go benchmark medians from five 500 ms samples on Apple M5 Max, Go 1.26.5, with
-benchmem -cpu=1. Parsing and JSX-node collection were outside the timed loop; the benchmark exercised rule setup and listeners with different edit demands. The temporary benchmark source was removed.Diagnostics and autofix improved by 18.8% and 12.4% respectively. The long-text case avoids a full-text allocation and scan; lightweight control cases varied by less than 4%, so no end-to-end performance claim is made.
Related Links
Checklist