From eae19b990b326eef69bc6ac536c02575d783b642 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Fri, 14 Jan 2022 21:01:33 -0800 Subject: [PATCH] Router: handle comma in repeated enum cases --- .../scala/org/scalafmt/internal/Router.scala | 5 +++++ .../test/resources/scala3/OptionalBraces.stat | 9 ++++++--- .../resources/scala3/OptionalBraces_keep.stat | 9 ++++++--- .../resources/scala3/OptionalBraces_unfold.stat | 16 ++++++++++++---- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala index 262b855c72..a00df806f7 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala @@ -1497,6 +1497,11 @@ class Router(formatOps: FormatOps) { Split(Space, 0), Split(Newline, 1).withIndent(indent, right, After) ) + case _: Defn.RepeatedEnumCase if { + if (!style.newlines.sourceIgnored) newlines != 0 + else style.newlines.source eq Newlines.unfold + } => + Seq(Split(Newline, 0)) case _ => Seq( Split(Space, 0), diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat index 0a52ea28b1..6cc0f81129 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat @@ -3330,9 +3330,12 @@ enum SerializedField extends jl.Enum[SerializedField] { case UNKNOWN, // represents a field code we didn't recognize END_MARKER, // end of a list of fields ROOT_VALUE, // Fields at the root - ROOT_WAS_CONFIG, VALUE_DATA, // Fields that make up a value - VALUE_ORIGIN, ORIGIN_DESCRIPTION, // Fields that make up an origin - ORIGIN_LINE_NUMBER, ORIGIN_END_LINE_NUMBER, ORIGIN_TYPE, ORIGIN_URL, + ROOT_WAS_CONFIG, + VALUE_DATA, // Fields that make up a value + VALUE_ORIGIN, + ORIGIN_DESCRIPTION, // Fields that make up an origin + ORIGIN_LINE_NUMBER, + ORIGIN_END_LINE_NUMBER, ORIGIN_TYPE, ORIGIN_URL, ORIGIN_COMMENTS, ORIGIN_NULL_URL, ORIGIN_NULL_COMMENTS, ORIGIN_RESOURCE, ORIGIN_NULL_RESOURCE } diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat index 9f2cfa0191..83e98437c1 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat @@ -3319,9 +3319,12 @@ enum SerializedField extends jl.Enum[SerializedField] { case UNKNOWN, // represents a field code we didn't recognize END_MARKER, // end of a list of fields ROOT_VALUE, // Fields at the root - ROOT_WAS_CONFIG, VALUE_DATA, // Fields that make up a value - VALUE_ORIGIN, ORIGIN_DESCRIPTION, // Fields that make up an origin - ORIGIN_LINE_NUMBER, ORIGIN_END_LINE_NUMBER, ORIGIN_TYPE, ORIGIN_URL, + ROOT_WAS_CONFIG, + VALUE_DATA, // Fields that make up a value + VALUE_ORIGIN, + ORIGIN_DESCRIPTION, // Fields that make up an origin + ORIGIN_LINE_NUMBER, + ORIGIN_END_LINE_NUMBER, ORIGIN_TYPE, ORIGIN_URL, ORIGIN_COMMENTS, ORIGIN_NULL_URL, ORIGIN_NULL_COMMENTS, ORIGIN_RESOURCE, ORIGIN_NULL_RESOURCE } diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat index ce83db092c..5cc2c06cc3 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat @@ -3421,9 +3421,17 @@ enum SerializedField extends jl.Enum[SerializedField] { case UNKNOWN, // represents a field code we didn't recognize END_MARKER, // end of a list of fields ROOT_VALUE, // Fields at the root - ROOT_WAS_CONFIG, VALUE_DATA, // Fields that make up a value - VALUE_ORIGIN, ORIGIN_DESCRIPTION, // Fields that make up an origin - ORIGIN_LINE_NUMBER, ORIGIN_END_LINE_NUMBER, ORIGIN_TYPE, ORIGIN_URL, - ORIGIN_COMMENTS, ORIGIN_NULL_URL, ORIGIN_NULL_COMMENTS, ORIGIN_RESOURCE, + ROOT_WAS_CONFIG, + VALUE_DATA, // Fields that make up a value + VALUE_ORIGIN, + ORIGIN_DESCRIPTION, // Fields that make up an origin + ORIGIN_LINE_NUMBER, + ORIGIN_END_LINE_NUMBER, + ORIGIN_TYPE, + ORIGIN_URL, + ORIGIN_COMMENTS, + ORIGIN_NULL_URL, + ORIGIN_NULL_COMMENTS, + ORIGIN_RESOURCE, ORIGIN_NULL_RESOURCE }