Skip to content

Fix jsx-sort-props autofix with trailing line comments#4011

Open
sjh9714 wants to merge 2 commits into
jsx-eslint:masterfrom
sjh9714:fix-jsx-sort-props-line-comment-autofix
Open

Fix jsx-sort-props autofix with trailing line comments#4011
sjh9714 wants to merge 2 commits into
jsx-eslint:masterfrom
sjh9714:fix-jsx-sort-props-line-comment-autofix

Conversation

@sjh9714

@sjh9714 sjh9714 commented May 17, 2026

Copy link
Copy Markdown

Summary

Fixes an unsafe autofix in jsx-sort-props when a JSX prop has a trailing line comment.

What changed

  • Added a regression test for a prop followed by an inline // comment.
  • Kept the lint report, but skipped autofix when sorting that prop would produce invalid JSX.

Why

Issue #3936 reports that sorting a prop with a trailing line comment can move JSX syntax after the comment, producing invalid output.

Testing

  • ./node_modules/.bin/mocha tests/lib/rules/jsx-sort-props.js --grep "Comment"
  • ./node_modules/.bin/mocha tests/lib/rules/jsx-sort-props.js
  • npm run lint
  • npm run unit-test
  • npm test

Fixes #3936

@codecov

codecov Bot commented May 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.71%. Comparing base (c9a2de7) to head (05b25ec).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4011   +/-   ##
=======================================
  Coverage   97.71%   97.71%           
=======================================
  Files         137      137           
  Lines       10188    10199   +11     
  Branches     3797     3800    +3     
=======================================
+ Hits         9955     9966   +11     
  Misses        233      233           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sjh9714 sjh9714 force-pushed the fix-jsx-sort-props-line-comment-autofix branch from 8b57742 to 05b25ec Compare May 17, 2026 01:33

@ljharb ljharb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check this locally, but it looks good at a quick glance

Comment thread tests/lib/rules/jsx-sort-props.js Outdated
code: `
<div
onClick={() => console.log()} // Comment
className="flex">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
className="flex">
className="flex"
>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied this formatting suggestion in the current diff; the output block now keeps className="flex" and the closing > on separate lines as suggested. All PR checks are passing.

@sjh9714 sjh9714 force-pushed the fix-jsx-sort-props-line-comment-autofix branch from e26ca9b to b278c53 Compare May 17, 2026 05:40
@sjh9714

sjh9714 commented May 21, 2026

Copy link
Copy Markdown
Author

The outstanding review thread is outdated now; the current fixture has the suggested formatting with className and > on separate lines. I rechecked locally:

  • npx mocha tests/lib/rules/jsx-sort-props.js
  • npm run lint -- tests/lib/rules/jsx-sort-props.js
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: react/jsx-sort-props causes errors when an inline comment follows a JSX prop

2 participants