Skip to content
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

Router: space between if-while-for cond and body #3356

Merged
merged 2 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,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
18 changes: 18 additions & 0 deletions scalafmt-tests/src/test/resources/default/For.stat
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,21 @@ object a {
} a +
b
}
<<< body starts with lparen
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
}
>>>
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
}
18 changes: 18 additions & 0 deletions scalafmt-tests/src/test/resources/default/If.stat
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,21 @@ if (host.indexOf(':') != -1 && host.indexOf(']') == -1 &&
host.indexOf('[') == -1) {
hostVar = "[" + host + "]"
}
<<< body starts with lparen
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
}
>>>
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
}