fix(linter): preserve comments in arrow-body-style auto-fix#22853
Closed
aartisonigra wants to merge 4 commits into
Closed
fix(linter): preserve comments in arrow-body-style auto-fix#22853aartisonigra wants to merge 4 commits into
aartisonigra wants to merge 4 commits into
Conversation
kapobajza
reviewed
May 30, 2026
Comment on lines
+349
to
+357
| // Check if there are comments between the opening brace and the return statement. | ||
| // If so, we cannot safely fix because the comment would be lost. | ||
| // ESLint also skips the fix in this case. | ||
| let block_start = body.span.start + 1; // Skip the opening '{' | ||
| let return_start = return_arg.span().start; | ||
| if ctx.has_comments_between(Span::new(block_start, return_start)) { | ||
| // Cannot fix when there are comments before the return statement | ||
| return fixer.noop(); | ||
| } |
Contributor
There was a problem hiding this comment.
ESLint doesn't actually skip the fix in this case. Here's a link to the playground where you can see that:
Signed-off-by: Aarti Sonigra <23amtics292@gmail.com>
Signed-off-by: Aarti Sonigra <23amtics292@gmail.com>
Sysix
reviewed
May 30, 2026
Sysix
left a comment
Member
There was a problem hiding this comment.
Thank you for working on this issue and welcome to the project 🫶
Like @kapobajza said, we should not skip the fix, instead trying to preserve the comments.
We should also make sure, that comments after the return are also preserved.
The fix behavior is difficult to get right, I got with #22854 a good try 🤞 Thank you for the work
Author
|
Thanks for the warm welcome! I'll look into #22854 and update the PR accordingly. |
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.
Description
This PR fixes an issue where the auto-fix for
eslint/arrow-body-styleremoves comments located inside the block body before the return statement.Now, the fixer checks if there are any comments between the opening brace and the return statement using
ctx.has_comments_between. If comments are detected, it safely aborts the auto-fix by returningfixer.noop(), thereby preserving the comments and preventing code loss.Closes #22833
Key Changes
fix_block_to_conciseincrates/oxc_linter/src/rules/eslint/arrow_body_style.rsto detect inner comments.failsuite covering both line comments (//) and block comments (/* ... */) to ensure they are not dropped during auto-fix.Checklist