Skip to content

Commit

Permalink
FormatOps: consider scalajs tucking in getSlbEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 25, 2024
1 parent 00453f9 commit 68bd11b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,20 @@ class FormatOps(
case _: T.LeftBracket => null
case _: T.Dot if start.rightOwner.is[Type.Select] => null
case _: T.Ident if start.leftOwner.is[Type.Select] => null
case _: T.RightParen => start.left match {
case _: T.LeftParen => null
case _: T.RightParen
if style.newlines.fold ||
!style.danglingParentheses.atSite(start.rightOwner, true) =>
null
case _ => start
case t: T.RightParen =>
if (start.left.is[T.LeftParen]) null
else {
val owner = start.rightOwner
val isDefnSite = isParamClauseSite(owner)
implicit val clauseSiteFlags: ClauseSiteFlags =
ClauseSiteFlags(owner, isDefnSite)
val bpFlags = getBinpackSiteFlags(tokens(matching(t)), start, false)
if (bpFlags.scalaJsStyle) scalaJsOptCloseOnRight(start, bpFlags)
else if (
!start.left.is[T.RightParen] ||
!style.newlines.fold && clauseSiteFlags.dangleCloseDelim
) start
else null
}
case _: T.Comment =>
if (start.noBreak) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1264,9 +1264,8 @@ class Router(formatOps: FormatOps) {
}.toOption
else if (isSingleArg) None
else afterFirstArgOneline.map(_.right)
val opt = nextComma.getOrElse(endOfSingleLineBlock(
next(scalaJsOptCloseOnRight(beforeClose, flags)),
))
val opt = nextComma
.getOrElse(endOfSingleLineBlock(next(beforeClose)))

val slbArg = oneline && !noSplitIndents.exists(_.hasStateColumn)
val slbPolicy: Policy = (if (slbArg) nextComma else None).map {
Expand Down
16 changes: 7 additions & 9 deletions scalafmt-tests/shared/src/test/resources/default/Apply.stat
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,7 @@ SSLConfig(SSLLooseConfig(allowLegacyHelloMessages = None)/*comment 123 comment 2
val config = WSClientConfig(ssl =
SSLConfig(
SSLLooseConfig(allowLegacyHelloMessages =
None) /*comment 123 comment 234*/
)
None) /*comment 123 comment 234*/ )
) // comment 345 comment 456
}
<<< #1604 1: apply with then without assign, and attached comments, with breaks before paren/comment
Expand Down Expand Up @@ -678,10 +677,8 @@ SSLConfig(loose = SSLLooseConfig(allowLegacyHelloMessages = None)/*comment 123 c
>>>
{
val config = WSClientConfig(
SSLConfig(loose =
SSLLooseConfig(allowLegacyHelloMessages =
None) /*comment 123 comment 234*/
)
SSLConfig(loose = SSLLooseConfig(allowLegacyHelloMessages =
None) /*comment 123 comment 234*/ )
) // comment 345 comment 456
}
<<< #1604 2: apply without then with assign, and attached comments, with breaks before paren/comment
Expand Down Expand Up @@ -709,9 +706,10 @@ SSLConfig(loose = SSLLooseConfig(allowLegacyHelloMessages = None)/*comment 123 c
}
>>>
{
val config = WSClientConfig(ssl = SSLConfig(loose =
SSLLooseConfig(allowLegacyHelloMessages = None) /*comment 123 comment 234*/
)) // comment 345 comment 456
val config = WSClientConfig(ssl =
SSLConfig(loose = SSLLooseConfig(allowLegacyHelloMessages =
None) /*comment 123 comment 234*/ )
) // comment 345 comment 456
}
<<< #1604 3: apply with assign and attached comments, with breaks before paren/comment
{
Expand Down
10 changes: 3 additions & 7 deletions scalafmt-tests/shared/src/test/resources/scalajs/DefDef.stat
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,7 @@ trait EntityPage extends HtmlPage {
I(`class` = "clear material-icons",
elems = Txt("\uE14C")) ::
I(id = "search-icon", `class` = "material-icons",
elems = Txt(
"\uE8B6"))
elems = Txt("\uE8B6"))
)
) :: NoElems
)
Expand Down Expand Up @@ -807,9 +806,7 @@ val memberSel: Elems =
placeholder = "Filter all members",
`type` = "text", accesskey = "/")
) ::
I(`class` = "clear material-icons",
elems = Txt(
"\uE14C"))
I(`class` = "clear material-icons", elems = Txt("\uE14C"))
) ::
Div(
id = "filterby",
Expand Down Expand Up @@ -929,8 +926,7 @@ val memberSel: Elems =
elems = Txt("Public"))),
Li(`class` = "protected out",
elems = Span(
elems = Txt(
"Protected")))
elems = Txt("Protected")))
) ++ List(Li(`class` = "private out",
elems = Span(
elems = Txt("Private"))))
Expand Down
3 changes: 1 addition & 2 deletions scalafmt-tests/shared/src/test/resources/unit/Lambda.stat
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ Thing(implicit ctx =>
aaaaaaaaaaaaa(
bbbbbbbbbbbbbbbbbbb,
cccccccccc,
ddddddddddddddddddddj
)) // coooooooooooooooomment
ddddddddddddddddddddj)) // coooooooooooooooomment
<<< long curried with (), with breaks before paren/comment
Thing(implicit ctx =>
j =>
Expand Down

0 comments on commit 68bd11b

Please sign in to comment.