Skip to content

Commit

Permalink
Add break after annotation preceding return statement
Browse files Browse the repository at this point in the history
Summary: Reported on [this issue](#497) which I thought was fair to "fix"

Reviewed By: cortinico

Differential Revision: D61208619

fbshipit-source-id: b244c84d00e340d244161bf594729d8c48e4e2a9
  • Loading branch information
Nivaldo Bondança authored and facebook-github-bot committed Aug 14, 2024
1 parent 30cfe0d commit a1ffe3d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
### Fixed
- IntelliJ plugin crash (https://github.com/facebook/ktfmt/pull/501)
- Ordering of `@property` and `@param` in KDoc (https://github.com/facebook/ktfmt/pull/498)
- Annotation in return expressions (https://github.com/facebook/ktfmt/issues/497)

### Changed
- KotlinLang style also managing trailing commas (https://github.com/facebook/ktfmt/issues/216, https://github.com/facebook/ktfmt/issues/442)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,7 @@ class KotlinInputAstVisitor(
(baseExpression is KtBinaryExpression || baseExpression is KtBinaryExpressionWithTypeRHS) &&
expression.parent is KtBlockExpression -> builder.forcedBreak()
baseExpression is KtLambdaExpression -> builder.space()
baseExpression is KtReturnExpression -> builder.forcedBreak()
else -> builder.breakOp(Doc.FillMode.UNIFIED, " ", ZERO)
}

Expand Down
11 changes: 11 additions & 0 deletions core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3500,6 +3500,17 @@ class FormatterTest {
|"""
.trimMargin())

@Test
fun `annotations on return statements`() =
assertFormatted(
"""
|fun foo(): Map<String, Any> {
| @Suppress("AsCollectionCall")
| return map.asMap()
|}
|"""
.trimMargin())

@Test
fun `Unary prefix expressions`() =
assertFormatted(
Expand Down

0 comments on commit a1ffe3d

Please sign in to comment.