Skip to content

Commit

Permalink
Router: use spaces.afterColonInMatchPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jun 20, 2024
1 parent 4dab474 commit 2654a0e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ case class Spaces(
) {
def isSpaceAfterKeyword(tokenAfter: Token): Boolean =
afterKeywordBeforeParen || !tokenAfter.is[Token.LeftParen]

def notAfterColon(owner: meta.Tree): Boolean = owner match {
case x: meta.Pat.Typed => afterColonInMatchPattern match {
case Spaces.AfterColonInMatchPattern.Never => true
case Spaces.AfterColonInMatchPattern.Always => false
case Spaces.AfterColonInMatchPattern.NoAlternatives => x.parent
.exists(_.is[meta.Pat.Alternative])
}
case _ => false
}

}

object Spaces {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,8 @@ class Router(formatOps: FormatOps) {
case FormatToken(T.RightArrow(), _, _) if leftOwner.is[Type.ByName] =>
val mod = Space(style.spaces.inByNameTypes)
Seq(Split(mod, 0))
case FormatToken(_: T.Colon, _, _)
if style.spaces.notAfterColon(leftOwner) => Seq(Split(NoSplit, 0))
case FormatToken(_: T.Symbolic, _, _) => Seq(Split(Space, 0))
case tok =>
logger.debug(s"MISSING CASE: $tok")
Expand Down
6 changes: 3 additions & 3 deletions scalafmt-tests/src/test/resources/unit/Case.stat
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ foo match {
}
>>>
foo match {
case e: Etype | f: Ftype =>
case g: Gtype =>
case e:Etype | f:Ftype =>
case g:Gtype =>
}
<<< pattern alternatives, afterColonInMatchPattern = noAlternatives
spaces.afterColonInMatchPattern = noAlternatives
Expand All @@ -141,6 +141,6 @@ foo match {
}
>>>
foo match {
case e: Etype | f: Ftype =>
case e:Etype | f:Ftype =>
case g: Gtype =>
}

0 comments on commit 2654a0e

Please sign in to comment.