Skip to content

Commit

Permalink
Router: add NL split in select chain for src=keep
Browse files Browse the repository at this point in the history
With binpack.callSite=oneline, we are assuming that we can always break
before a select dot; for source=keep, it wasn't true so let's fix it.

However, penalize this newline split so that it's only used sparingly.
  • Loading branch information
kitbellew committed May 20, 2024
1 parent a0d3e54 commit 5ee5a72
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,12 @@ class Router(formatOps: FormatOps) {

case _ if left.is[T.Comment] => Seq(Split(Space.orNL(t.noBreak), 0))

case Newlines.keep => Seq(Split(NoSplit.orNL(t.noBreak), 0))
case Newlines.keep =>
if (t.noBreak) Seq(
Split(NoSplit, 0),
Split(Newline, Constants.ExceedColumnPenalty * 3),
)
else Seq(Split(Newline, 0))

case Newlines.unfold =>
val nlCost = if (nlOnly) 0 else 1
Expand Down
20 changes: 10 additions & 10 deletions scalafmt-tests/src/test/resources/newlines/source_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -945,9 +945,8 @@ object a {
}
>>>
object a {
(intercept[java.lang.IllegalStateException] {
in.readObject
}).getMessage should ===(
(intercept[java.lang.IllegalStateException] { in.readObject })
.getMessage should ===(
"Trying to deserialize a serialized ActorRef without an ActorSystem in scope." +
" Use 'akka.serialization.Serialization.currentSystem.withValue(system) { ... }'")
}
Expand Down Expand Up @@ -2073,9 +2072,8 @@ object a {
}
>>>
object a {
plugins(
service.pluginType
) += service.pluginName -> service
plugins(service.pluginType) += service
.pluginName -> service
}
<<< 8.7
maxColumn = 80
Expand Down Expand Up @@ -2803,7 +2801,10 @@ object a {
test("foo") {
a.b(c, d) shouldBe
E(Seq(F(1, "v1"), F(2, "v2")),
G(Some(Seq(h, i)), Some(Seq(j, k)), a.b, c.d, e.f.g, h.i.j)).foo
G(Some(Seq(h, i)),
Some(Seq(j, k)), a.b, c.d,
e.f.g, h.i.j))
.foo
}
}
<<< binpack call, oneline, with syntaxNL, single arg
Expand Down Expand Up @@ -3551,9 +3552,8 @@ pubSubMessage match {
case message: UploadMessage => {
val services = makeUploadServices()

UploadSubscriber(
services
).processEff(message)
UploadSubscriber(services)
.processEff(message)
}
case message: IngestionMessage => (
IngestionSubscriber.defaultServices
Expand Down
18 changes: 10 additions & 8 deletions scalafmt-tests/src/test/resources/scalajs/Apply.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1062,11 +1062,13 @@ object a {
}
}
>>>
BestFirstSearch:289 Failed to format
UNABLE TO FORMAT,
tok=)∙.: RightParen [139..140) [] Dot [140..141)
toks.length=43
deepestYet.length=30
policies=List(REL?:[Router:1449](NB:[Router:1449]@141d,???,NoPolicy), REL?:[Router:1449](NB:[Router:1449]@141d,???,NoPolicy), REL?:[Router:1449](NB:[Router:1449]@141d,???,NoPolicy), NB:[Router:221]@165d, NB:[Router:221]@167d)
nextSplits=List(NoSplit:[Router:1703](cost=0, indents=[], NoPolicy))
splitsAfterPolicy=Decision()∙.: RightParen [139..140) [] Dot [140..141),List())
object a {
def createResetButton(): JQuery = {
jQuery("<input>",
js.Dynamic.literal(
`type` = "button",
value = "Reset"
))
.click(() => reset())
}
}

0 comments on commit 5ee5a72

Please sign in to comment.