Skip to content

Commit

Permalink
Router: handle !annotationNewlines for source=keep
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Dec 14, 2021
1 parent 08e63e3 commit 7f10770
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ class Router(formatOps: FormatOps) {
case Newlines.fold =>
right.is[T.Comment] || annoRight ||
!style.optIn.annotationNewlines && right.is[Keyword]
case Newlines.keep =>
newlines == 0 && (annoRight || right.is[Keyword])
case _ =>
newlines == 0 && right.is[Keyword]
})
Expand Down
27 changes: 9 additions & 18 deletions scalafmt-tests/src/test/resources/newlines/source_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,7 @@ object WrapperToHaveStatTestCaseParserWorking {
}
>>>
object WrapperToHaveStatTestCaseParserWorking {
@annot
@deprecated
@annot @deprecated
class B(
@annot @deprecated private implicit val x: Int
) extends A {
Expand All @@ -1155,12 +1154,8 @@ object WrapperToHaveStatTestCaseParserWorking {
@annot
override def bar = { 1 }

@annot
@annot2
@annot3
@annot4 /*comment4*/
@annot5
@deprecated
@annot @annot2 @annot3 @annot4 /*comment4*/
@annot5 @deprecated
def foo2(@annot @deprecated x: Int) = 1

// in case of annotations with params located in many lines
Expand All @@ -1170,17 +1165,14 @@ object WrapperToHaveStatTestCaseParserWorking {
value =
"foo",
someInt = 5
)
@annot3
) @annot3
@deprecated(value =
"bar") def bar2 = 1
}

@annot
@annot2
@annot @annot2
@annot3
@annot4
@deprecated class C
@annot4 @deprecated class C

@annot
@deprecated
Expand All @@ -1200,12 +1192,11 @@ object a {
}
>>>
object a {
@Ignore
@Test def foo(): Unit = {
@Ignore @Test def foo(): Unit = {
val bar = baz
}
@Ignore
@Test def fooFooFoo(): Unit = {
@Ignore @Test
def fooFooFoo(): Unit = {
val bar = baz
}
}
Expand Down

0 comments on commit 7f10770

Please sign in to comment.