-
-
Notifications
You must be signed in to change notification settings - Fork 791
fix(lint): correct multiline autofix in useConsistentArrowReturn #8183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: bd77c58 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughTrims leading trivia from the expression when converting a concise arrow body into a block with Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
crates/biome_js_analyze/tests/specs/nursery/useConsistentArrowReturn/multiline.invalid.options.json (1)
1-15: Configuration looks good; minor formatting inconsistency.The rule configuration correctly enables
useConsistentArrowReturnwithstyle: alwaysfor testing.Minor nit: line 3 uses a tab whilst the remaining lines use spaces.
crates/biome_js_analyze/tests/specs/nursery/useConsistentArrowReturn/multiline.invalid.js (1)
1-27: Good test coverage for multiline patterns.The test cases effectively cover common multiline arrow function scenarios: method chaining, object literals, arrays, and nested calls. These will properly exercise the
trim_leading_trivia()fix.If you're feeling thorough, you could also add cases for multiline template literals or ternary expressions, but the current set is solid.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
crates/biome_js_analyze/tests/specs/nursery/useConsistentArrowReturn/multiline.invalid.js.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (3)
crates/biome_js_analyze/src/lint/nursery/use_consistent_arrow_return.rs(1 hunks)crates/biome_js_analyze/tests/specs/nursery/useConsistentArrowReturn/multiline.invalid.js(1 hunks)crates/biome_js_analyze/tests/specs/nursery/useConsistentArrowReturn/multiline.invalid.options.json(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-05T14:43:29.581Z
Learnt from: dyc3
Repo: biomejs/biome PR: 7081
File: packages/@biomejs/biome/configuration_schema.json:7765-7781
Timestamp: 2025-08-05T14:43:29.581Z
Learning: The file `packages/biomejs/biome/configuration_schema.json` is auto-generated and should not be manually edited or reviewed for schema issues; any changes should be made at the code generation source.
Applied to files:
crates/biome_js_analyze/tests/specs/nursery/useConsistentArrowReturn/multiline.invalid.options.json
📚 Learning: 2025-09-25T12:32:59.003Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7593
File: crates/biome_service/src/workspace/server.rs:1306-1306
Timestamp: 2025-09-25T12:32:59.003Z
Learning: In the biomejs/biome project, do not flag compilation errors during code review as they are handled by the existing test infrastructure and CI. Focus on other code quality aspects instead.
Applied to files:
crates/biome_js_analyze/tests/specs/nursery/useConsistentArrowReturn/multiline.invalid.options.json
🔇 Additional comments (1)
crates/biome_js_analyze/src/lint/nursery/use_consistent_arrow_return.rs (1)
187-187: Properly handles multiline expressions.Trimming leading trivia before constructing the return statement correctly addresses the multiline case. This prevents malformed formatting when converting concise arrows with leading whitespace/newlines to block-body returns.
.changeset/wild-ghosts-design.md
Outdated
| ```js | ||
| const foo = (l) => { | ||
| return l.split('\n'); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this code block is not closed...
.changeset/wild-ghosts-design.md
Outdated
| For example, this code: | ||
|
|
||
| ```js | ||
| const foo = (l) => | ||
| l | ||
| .split('\n') | ||
| ``` | ||
|
|
||
| Was incorrectly fixed to: | ||
|
|
||
| ```js | ||
| const foo = (l) => { | ||
| return | ||
| l.split('\n'); | ||
| } | ||
| ``` | ||
|
|
||
| Biome now correctly produces: | ||
|
|
||
| ```js | ||
| const foo = (l) => { | ||
| return l.split('\n'); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...but actually you could probably make this a little bit more concise using a diff block to show the change.
.changeset/wild-ghosts-design.md
Outdated
|
|
||
| Fixed [#8179](https://github.com/biomejs/biome/issues/8179): The [`useConsistentArrowReturn`](https://biomejs.dev/linter/rules/use-consistent-arrow-return/) rule now correctly handles multiline expressions in its autofix when the `style` option is set to `"always"`. | ||
|
|
||
| Previously, when converting arrow functions with multiline expressions to block statements, the autofix would place a newline after the `return` keyword. This triggered JavaScript's Automatic Semicolon Insertion (ASI), causing the function to return `undefined` instead of the intended value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This statement (line 7) isn't entirely accurate and IMO its a bit too "in the weeds" for end users to care about. I would rather we just omit this paragraph.
| " ", | ||
| )])) | ||
| .with_argument(expr_to_return) | ||
| .with_argument(expr_to_return.trim_leading_trivia()?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would get rid of comments. Let's make sure the comments get preserved and moved to the correct nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include comments in these tests so we can verify we don't accidentally delete comments.
CodSpeed Performance ReportMerging #8183 will not alter performanceComparing Summary
Footnotes
|
|
I think I've addressed all comments. I've added a few code snippets that has comments and noticed they didn't generate something in the snapshots which I think means they wont be like autofixable and that the user has to address them manually? |
dyc3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done!
Summary
Fixes #8179.
The
useConsistentArrowReturnrule had a bug in its autofix when thestyleoption was set to"always". When converting arrow functions with multiline expressions to block statements, the autofix would incorrectly place a newline after thereturnkeyword. This triggered JavaScript's Automatic Semicolon Insertion (ASI), causing the function to returnundefinedinstead of the intended value.For example, this code:
Was incorrectly fixed to:
The fix ensures that multiline expressions are kept on the same line as the
returnkeyword:Test Plan
Added comprehensive test cases in
multiline.invalid.jscovering various multiline expression scenarios including:All tests verify that the autofix produces correct code without triggering ASI.
Docs
This is a bugfix for an existing rule, so no documentation changes are needed beyond the changeset.