Skip to content

Commit

Permalink
Router: fold single-line case arrow body if unfold
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Oct 28, 2021
1 parent 08d7897 commit db5ec56
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ class Router(formatOps: FormatOps) {
else if (ft.right.is[T.KwCase]) Seq(nlSplit(ft)(0))
else if (beforeMultiline eq Newlines.unfold) {
if (ft.right.is[T.Semicolon]) Seq(baseSplit, nlSplit(ft)(1))
else if (style.newlines.source ne Newlines.unfold) withSlbSplit
else Seq(nlSplit(ft)(0))
} else if (ft.hasBreak && !beforeMultiline.ignoreSourceSplit)
Seq(nlSplit(ft)(0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4659,8 +4659,6 @@ assembly / assemblyMergeStrategy := {
}
>>>
assembly / assemblyMergeStrategy := {
case A("B", c @ _*) =>
D.e
case _ =>
E.f
case A("B", c @ _*) => D.e
case _ => E.f
}
6 changes: 2 additions & 4 deletions scalafmt-tests/src/test/resources/newlines/source_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -4456,8 +4456,6 @@ assembly / assemblyMergeStrategy := {
}
>>>
assembly / assemblyMergeStrategy := {
case A("B", c @ _*) =>
D.e
case _ =>
E.f
case A("B", c @ _*) => D.e
case _ => E.f
}
6 changes: 2 additions & 4 deletions scalafmt-tests/src/test/resources/newlines/source_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -4685,8 +4685,6 @@ assembly / assemblyMergeStrategy := {
}
>>>
assembly / assemblyMergeStrategy := {
case A("B", c @ _*) =>
D.e
case _ =>
E.f
case A("B", c @ _*) => D.e
case _ => E.f
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ transparent inline def g(x: Any): Any = inline x match {
>>>
transparent inline def g(x: Any): Any =
inline x match {
case x: String =>
(x, x) // Tuple2[String, String](x, x)
case x: Double =>
x
case x: String => (x, x) // Tuple2[String, String](x, x)
case x: Double => x
}
<<< complex
inline def repro[T <: Int with Singleton , U <: Int with Singleton]: Int =
Expand Down
3 changes: 1 addition & 2 deletions scalafmt-tests/src/test/resources/scala3/Macro.stat
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ body match {
sum(${ Varargs(subArgs) }: _*)
} if aVeryLongCondition(parameter) =>
subArgs.flatMap(flatSumArgs)
case body =>
body
case body => body
}
<<< macro pattern fold
newlines.beforeMultiline = fold
Expand Down
6 changes: 2 additions & 4 deletions scalafmt-tests/src/test/resources/scala3/MatchType.stat
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ newlines.beforeMultiline = unfold
>>>
type Elem[X] =
X match {
case String =>
Array[AVeryLongTraitNameToTestOutSomeThings]
case Array[t] =>
t
case String => Array[AVeryLongTraitNameToTestOutSomeThings]
case Array[t] => t
}
<<< match type fold
newlines.beforeMultiline = fold
Expand Down

0 comments on commit db5ec56

Please sign in to comment.