Skip to content

Commit

Permalink
Router: space between if-while-for cond and body
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Oct 31, 2022
1 parent 2cad711 commit f7ab935
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,20 @@ class Router(formatOps: FormatOps) {
// infix applications have no space.
case _: Type.ApplyInfix | _: Term.ApplyInfix => false
case _ => true
} && (prevNonComment(formatToken).left match {
case RightParenOrBracket() | T.KwSuper() | T.KwThis() |
T.Ident(_) | T.RightBrace() | T.Underscore() |
T.Constant.Symbol(_) =>
true
case _ => false
}) =>
} && {
val prevFt = prevNonComment(formatToken)
prevFt.left match {
case _: T.RightParen | _: T.RightBrace =>
prevFt.meta.leftOwner match {
case _: Term.For | _: Term.If | _: Term.While => false
case _ => true
}
case _: T.RightBracket | _: T.KwSuper | _: T.KwThis |
_: T.Ident | _: T.Underscore | _: T.Constant.Symbol =>
true
case _ => false
}
} =>
def modification: Modification = leftOwner match {
case _: Mod => Space
// Add a space between constructor annotations and their parameter lists
Expand Down
4 changes: 2 additions & 2 deletions scalafmt-tests/src/test/resources/default/Apply.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1359,8 +1359,8 @@ object a {
val boss = system.actorOf(Props(new Actor {
def receive = {
case "run" ⇒
for (_ ← 1 to num)(context.watch(
context.actorOf(props))) ! cachedMessage
for (_ ← 1 to num)
(context.watch(context.actorOf(props))) ! cachedMessage
case Terminated(child) ⇒ stopLatch.countDown()
}
}).withDispatcher("boss"))
Expand Down
12 changes: 6 additions & 6 deletions scalafmt-tests/src/test/resources/default/For.stat
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ object a {
}
>>>
object a {
for (b <- c)(d(e))
for (b <- c)(d.e(f))
for (b <- c)(d(e)) + f
for { b <- c }(d(e))
for { b <- c }(d.e(f))
for { b <- c }(d(e)) + f
for (b <- c) (d(e))
for (b <- c) (d.e(f))
for (b <- c) (d(e)) + f
for { b <- c } (d(e))
for { b <- c } (d.e(f))
for { b <- c } (d(e)) + f
}
12 changes: 6 additions & 6 deletions scalafmt-tests/src/test/resources/default/If.stat
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,10 @@ object a {
}
>>>
object a {
if (true)(d(e))
if (true)(d.e(f))
if (true)(d(e)) + f
while (true)(d(e))
while (true)(d.e(f))
while (true)(d(e)) + f
if (true) (d(e))
if (true) (d.e(f))
if (true) (d(e)) + f
while (true) (d(e))
while (true) (d.e(f))
while (true) (d(e)) + f
}

0 comments on commit f7ab935

Please sign in to comment.