Skip to content

Commit

Permalink
FormatOps: set indent correctly for enclosed body
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jan 8, 2024
1 parent 85c44dd commit e3360af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,13 @@ class FormatOps(
style: ScalafmtConfig
): Split =
asInfixApp(body).fold {
val expire = tokens.nextNonCommentSameLine(tokens.getLast(body)).left
val lastFt = tokens.getLast(body)
val right = nextNonComment(ft).right
val rpOpt = if (right.is[T.LeftParen]) matchingOpt(right) else None
val expireFt = rpOpt.fold(lastFt) { rp =>
if (rp.end >= lastFt.left.end) tokens.before(rp) else lastFt
}
val expire = tokens.nextNonCommentSameLine(expireFt).left
nlSplit.withIndent(Num(style.indent.main), expire, ExpiresOn.After)
}(app => InfixSplits.withNLIndent(nlSplit)(app, ft))

Expand Down
12 changes: 6 additions & 6 deletions scalafmt-tests/src/test/resources/rewrite/RedundantParens.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1342,11 +1342,11 @@ object A {
def test =
(
foo,
)
)
def test =
(
foo,
)
)
def test =
(
Option(""),
Expand All @@ -1373,11 +1373,11 @@ object A {
def test =
(
foo,
)
)
def test =
(
foo,
)
)
def test =
(
Option(""),
Expand All @@ -1404,11 +1404,11 @@ object A {
def test =
(
foo,
)
)
def test =
(
foo,
)
)
def test =
(
Option(""),
Expand Down

0 comments on commit e3360af

Please sign in to comment.