From 2a3a06ae816879afb7c9e77656d0daa155454035 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sun, 26 Dec 2021 14:13:12 -0800 Subject: [PATCH 1/2] Add tests with comma after multi-line comment --- .../src/test/resources/unit/Comment.stat | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/scalafmt-tests/src/test/resources/unit/Comment.stat b/scalafmt-tests/src/test/resources/unit/Comment.stat index 1f41d71caf..39dc9d9605 100644 --- a/scalafmt-tests/src/test/resources/unit/Comment.stat +++ b/scalafmt-tests/src/test/resources/unit/Comment.stat @@ -782,3 +782,29 @@ foo(barBarBarBar, /* c1 */ baz, /* c2 */ qux) >>> foo(barBarBarBar, /* c1 */ baz, /* c2 */ qux) +<<< comma after mlc +foo( + bar /* c1 */ + , + baz /* c2 */ + , +) +>>> +foo( + bar /* c1 */, + baz /* c2 */ +) +<<< comma after mlc, binpack +binPack.preset = true +=== +foo( + bar /* c1 */ + , + baz /* c2 */ + , +) +>>> +foo( + bar /* c1 */, + baz /* c2 */ +) From 1c20f0a7ce0d0a55cdf3059a1398b0f4731f1c1c Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sun, 26 Dec 2021 14:20:20 -0800 Subject: [PATCH 2/2] Router: do not attach comma after a comment Since we can potentially reformat a long single-line comment into a multi-line comment, we can't attach anything that followed the MLC after a break. --- .../src/main/scala/org/scalafmt/internal/Router.scala | 3 ++- scalafmt-tests/src/test/resources/unit/Comment.stat | 6 ++++-- 2 files changed, 6 insertions(+), 3 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 e391699847..0593c71c00 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 @@ -1380,7 +1380,8 @@ class Router(formatOps: FormatOps) { Seq(Split(Space, 0)) // Delim - case FormatToken(_, T.Comma(), _) => + case ft @ FormatToken(left, _: T.Comma, _) + if !left.is[T.Comment] || newlines == 0 => Seq( Split(NoSplit, 0) ) diff --git a/scalafmt-tests/src/test/resources/unit/Comment.stat b/scalafmt-tests/src/test/resources/unit/Comment.stat index 39dc9d9605..e6e428ea0d 100644 --- a/scalafmt-tests/src/test/resources/unit/Comment.stat +++ b/scalafmt-tests/src/test/resources/unit/Comment.stat @@ -791,7 +791,8 @@ foo( ) >>> foo( - bar /* c1 */, + bar /* c1 */ + , baz /* c2 */ ) <<< comma after mlc, binpack @@ -805,6 +806,7 @@ foo( ) >>> foo( - bar /* c1 */, + bar /* c1 */ + , baz /* c2 */ )