Skip to content

fix: align JSX expression line handling with upstream - #2071

Merged
fansenze merged 1 commit into
mainfrom
codex/fix-jsx-one-expression-per-line-20260905
Sep 5, 2026
Merged

fix: align JSX expression line handling with upstream#2071
fansenze merged 1 commit into
mainfrom
codex/fix-jsx-one-expression-per-line-20260905

Conversation

@fansenze

@fansenze fansenze commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix react/jsx-one-expression-per-line so literal and single-child allowances work when JSX follows a line break or comment. For example, this remains valid with allow: "literal":

const view = () => (
  <A>text</A>
);

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:

  • Compared 10,097 upstream and generated cases against the latest published eslint-plugin-react@7.37.5 using 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 removed SourceCode.isSpaceBetweenTokens method 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=3 passed, including regression cases and edit-demand checks.
  • The corresponding JavaScript rule suite and eight real CLI autofix cases passed, including BOM preservation, CR, and disable directives.
  • pnpm run check-spell, pnpm run format:check, and pnpm 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.

Case ns/op before → after B/op before → after allocs/op before → after
NoJSX 175.8 → 174.3 512 → 512 5 → 5
Formatted 10,586 → 10,176 11,104 → 11,080 112 → 111
Diagnostics 37,782 → 30,686 75,232 → 70,272 574 → 569
Autofix 46,124 → 40,422 82,400 → 82,392 958 → 957
LongText 73,795 → 292.4 156,192 → 520 8 → 6
NonJSXAllowed 338.9 → 345.9 512 → 512 5 → 5
SingleChildAllowed 191.4 → 198 512 → 512 5 → 5

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

  • Tests updated (or not required).
  • Documentation updated (or not required).

@fansenze
fansenze merged commit 3ccaa0a into main Sep 5, 2026
14 checks passed
@fansenze
fansenze deleted the codex/fix-jsx-one-expression-per-line-20260905 branch September 5, 2026 07:44
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.

1 participant