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: extend optimal token to include comment #4138

Merged
merged 3 commits into from
Aug 6, 2024
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 @@ -2524,9 +2524,7 @@ class Router(formatOps: FormatOps) {
case _: Term.ForYield => twoBranches
// we force newlines in try/catch/finally
case _: Term.Try | _: Term.TryWithHandler => Split.ignored
case t: Term.Apply if t.argClause.nonEmpty =>
baseSpaceSplit.withOptimalToken(optimalWithComment)
case _ => baseSpaceSplit.withOptimalToken(optimal)
case _ => baseSpaceSplit.withOptimalToken(optimalWithComment)
}
Seq(
spaceSplit,
Expand Down
4 changes: 2 additions & 2 deletions scalafmt-tests/src/test/resources/default/Apply.stat
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,8 @@ override final def next(): To =
override final def next(): To =
if (hasNext) {
val ret = _next
_next =
null.asInstanceOf[To] // Mark as consumed aaaaaaaaaaaaaaaaaa(nice to the GC, don't leak the last returned value)
_next = null
.asInstanceOf[To] // Mark as consumed aaaaaaaaaaaaaaaaaa(nice to the GC, don't leak the last returned value)
_hasNext = false // Mark as consumed (we need to look for the next value)
ret
} else throw new java.util.NoSuchElementException("next")
Expand Down
26 changes: 20 additions & 6 deletions scalafmt-tests/src/test/resources/default/String.stat
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,38 @@ object a {
object a {
system.log.warning("Replicator points to dead letters: Make sure the cluster node is not terminated and has the proper role!")
}
<<< #1505 2
<<< #1505 2.1 break, can fit within maxColumn
newlines.avoidForSimpleOverflow = [toolong]
===
object a {
intercept[TestException] {
val ct = Thread.currentThread() // Ensure that the thunk is executed in the tests thread
}
}
>>>
object a {
intercept[TestException] {
val ct = Thread
.currentThread() // Ensure that the thunk is executed in the tests thread
}
}
<<< #1505 2.2 don't break, overflows anyway
newlines.avoidForSimpleOverflow = [toolong]
===
object a {
intercept[TestException] {
val ct =
Thread.currentThread() // Ensure that the thunk is executed in the tests thread
}
}
>>>
object a {
intercept[TestException] {
val ct = Thread.currentThread() // Ensure that the thunk is executed in the tests thread
val ct =
Thread.currentThread() // Ensure that the thunk is executed in the tests thread
}
}
<<< #1505 2.1
<<< #1505 2.3 break, can fit within maxColumn
maxColumn = 90
newlines.avoidForSimpleOverflow = [toolong]
===
Expand All @@ -191,7 +204,7 @@ object a {
Thread.currentThread() // Ensure that the thunk is executed in the tests thread
}
}
<<< #1505 2.2 [#2633]
<<< #1505 2.4 [#2633] ok to overflow for single-line comment, despite no-overflow solution
maxColumn = 90
newlines.avoidForSimpleOverflow = [slc]
===
Expand All @@ -210,7 +223,7 @@ object a {
Thread.currentThread() // Ensure that the thunk is executed in the tests thread
}
}
<<< #1505 3
<<< #1505 3 break, can fit within maxColumn
newlines.avoidForSimpleOverflow = [toolong]
===
object a {
Expand All @@ -221,7 +234,8 @@ object a {
>>>
object a {
intercept[TestException] {
val ct = Thread.currentThread() // Ensure that the thunk is executed in the tests thread
val ct = Thread
.currentThread() // Ensure that the thunk is executed in the tests thread
}
}
<<< #1505 4
Expand Down
12 changes: 12 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,18 @@ end f

/** Some doc comment */
def g = f("Foo")
<<< oveflow infix assignment with trailing single-line comment
maxColumn = 26
===
object a:
def foo =
bar = baz + baz(qux) // c1
>>>
object a:
def foo =
bar = baz + baz(
qux
) // c1
<<< #2561 no forced dangle in tuples
maxColumn = 40
newlines {
Expand Down
10 changes: 10 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,16 @@ end f

/** Some doc comment */
def g = f("Foo")
<<< oveflow infix assignment with trailing single-line comment
maxColumn = 26
===
object a:
def foo =
bar = baz + baz(qux) // c1
>>>
object a:
def foo = bar = baz +
baz(qux) // c1
<<< #2561 no forced dangle in tuples
maxColumn = 40
newlines {
Expand Down
12 changes: 12 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,18 @@ end f

/** Some doc comment */
def g = f("Foo")
<<< oveflow infix assignment with trailing single-line comment
maxColumn = 26
===
object a:
def foo =
bar = baz + baz(qux) // c1
>>>
object a:
def foo =
bar = baz + baz(
qux
) // c1
<<< #2561 no forced dangle in tuples
newlines {
beforeOpenParenDefnSite = source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,18 @@ end f

/** Some doc comment */
def g = f("Foo")
<<< oveflow infix assignment with trailing single-line comment
maxColumn = 26
===
object a:
def foo =
bar = baz + baz(qux) // c1
>>>
object a:
def foo =
bar =
baz +
baz(qux) // c1
<<< #2561 no forced dangle in tuples
newlines {
beforeOpenParenDefnSite = source
Expand Down
Loading