Skip to content

Conversation

TTOzzi
Copy link
Member

@TTOzzi TTOzzi commented Feb 15, 2025

Resolve #812 and fix an additional minor bug that was discovered.
I will leave the explanation in the comments.

@@ -60,7 +60,7 @@ public final class OmitExplicitReturns: SyntaxFormatRule {
guard let accessorBlock = binding.accessorBlock,
let transformed = transformAccessorBlock(accessorBlock)
else {
return node
return super.visit(node)
Copy link
Member Author

Choose a reason for hiding this comment

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

If the condition was not met, the node was returned immediately, preventing the additional visit logic from executing.
By calling super.visit, the visit process continues, allowing the formatting logic in visit(_ node: ClosureExprSyntax) to be applied.

@@ -145,7 +145,7 @@ public final class OmitExplicitReturns: SyntaxFormatRule {
CodeBlockItemListSyntax([
CodeBlockItemSyntax(
leadingTrivia: returnStmt.leadingTrivia,
item: .expr(returnStmt.expression!),
item: .expr(returnStmt.expression!.detached.with(\.trailingTrivia, [])),
Copy link
Member Author

Choose a reason for hiding this comment

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

Since returnStmt.expression and returnStmt had the same trailingTrivia, formatting caused trailingTrivia to appear twice when present.
To fix this, I detached the trailingTrivia of returnStmt.expression when rewrapping with CodeBlockItemSyntax, ensuring it does not get duplicated.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Thank you, change looks good to me.

@ahoppen ahoppen enabled auto-merge February 17, 2025 21:55
@ahoppen ahoppen merged commit fb63404 into swiftlang:main Feb 17, 2025
19 checks passed
@TTOzzi TTOzzi deleted the fix-OmitExplicitReturns branch March 7, 2025 00:33
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.

_lint_ flags things for _OmitExplicitReturns_ but _format_ doesn't fix them
2 participants