Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router: handle !annotationNewlines for source=keep #2961

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 23 additions & 0 deletions scalafmt-tests/src/test/resources/newlines/source_classic.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,29 @@ object WrapperToHaveStatTestCaseParserWorking {
@deprecated
class D
}
<<< 4.2.1 annotation !annotationNewlines
align.preset = none
optIn.annotationNewlines = false
===
object a {
@Ignore @Test def foo(): Unit = {
val bar = baz
}
@Ignore @Test def fooFooFoo(): Unit = {
val bar = baz
}
}
>>>
object a {
@Ignore
@Test def foo(): Unit = {
val bar = baz
}
@Ignore
@Test def fooFooFoo(): Unit = {
val bar = baz
}
}
<<< 4.3: #938 flag false, newline no
optIn.selfAnnotationNewline = false
maxColumn = 20
Expand Down
22 changes: 22 additions & 0 deletions scalafmt-tests/src/test/resources/newlines/source_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,28 @@ object WrapperToHaveStatTestCaseParserWorking {

@annot @deprecated class D
}
<<< 4.2.1 annotation !annotationNewlines
align.preset = none
optIn.annotationNewlines = false
===
object a {
@Ignore @Test def foo(): Unit = {
val bar = baz
}
@Ignore @Test def fooFooFoo(): Unit = {
val bar = baz
}
}
>>>
object a {
@Ignore @Test def foo(): Unit = {
val bar = baz
}
@Ignore @Test
def fooFooFoo(): Unit = {
val bar = baz
}
}
<<< 4.3: #938 flag false, newline no
optIn.selfAnnotationNewline = false
maxColumn = 20
Expand Down
42 changes: 28 additions & 14 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,22 +1165,41 @@ 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
class D
}
<<< 4.2.1 annotation !annotationNewlines
align.preset = none
optIn.annotationNewlines = false
===
object a {
@Ignore @Test def foo(): Unit = {
val bar = baz
}
@Ignore @Test def fooFooFoo(): Unit = {
val bar = baz
}
}
>>>
object a {
@Ignore @Test def foo(): Unit = {
val bar = baz
}
@Ignore @Test
def fooFooFoo(): Unit = {
val bar = baz
}
}
<<< 4.3: #938 flag false, newline no
optIn.selfAnnotationNewline = false
maxColumn = 20
Expand Down
23 changes: 23 additions & 0 deletions scalafmt-tests/src/test/resources/newlines/source_unfold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,29 @@ object WrapperToHaveStatTestCaseParserWorking {
@annot @deprecated
class D
}
<<< 4.2.1 annotation !annotationNewlines
align.preset = none
optIn.annotationNewlines = false
===
object a {
@Ignore @Test def foo(): Unit = {
val bar = baz
}
@Ignore @Test def fooFooFoo(): Unit = {
val bar = baz
}
}
>>>
object a {
@Ignore @Test
def foo(): Unit = {
val bar = baz
}
@Ignore @Test
def fooFooFoo(): Unit = {
val bar = baz
}
}
<<< 4.3: #938 flag false, newline no
optIn.selfAnnotationNewline = false
maxColumn = 20
Expand Down