Skip to content

Commit

Permalink
RemoveScala3OptionalBraces: not with no-NL select
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 27, 2024
1 parent 71c2b36 commit 9e60294
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.scalafmt.rewrite

import org.scalafmt.config.ScalafmtConfig
import org.scalafmt.internal.FormatToken
import org.scalafmt.internal.FormatTokens
import org.scalafmt.config._
import org.scalafmt.internal._
import org.scalafmt.util.TreeOps._

import scala.meta._
Expand Down Expand Up @@ -78,7 +77,7 @@ private class RemoveScala3OptionalBraces(implicit val ftoks: FormatTokens)
session: Session,
style: ScalafmtConfig,
): Option[(Replacement, Replacement)] = {
val nextFt = ftoks.nextNonComment(ftoks.next(ft))
val nextFt = ftoks.nextNonCommentAfter(ft)
val notOkToRewrite = hasFormatOff || // can't force significant indentation
(nextFt.meta.rightOwner match {
case t: Term.Name => t.parent.exists {
Expand All @@ -88,6 +87,8 @@ private class RemoveScala3OptionalBraces(implicit val ftoks: FormatTokens)
!t.tokens.head.isSymbolicInfixOperator
case _ => false
}
case _: Term.Select => nextFt.noBreak &&
(style.newlines.getSelectChains eq Newlines.keep)
case _ => false
}) ||
(left.ft.right match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5871,9 +5871,9 @@ object A:
}.bar()
>>>
object A:
new Foo("xyz"):
print("msg")
.bar()
new Foo("xyz") {
print("msg")
}.bar()
<<< #3537 2
object A:
new Foo("xyz"):
Expand Down Expand Up @@ -5937,10 +5937,10 @@ def foo(url: String) = {
}
>>>
def foo(url: String) =
url.match
case "foo" => Some("")
case _ => None
.map { img =>
url.match {
case "foo" => Some("")
case _ => None
}.map { img =>
Html(s"""<img class="embed" src="$img" alt="$url"/>""")
}
<<< new anon as infix lhs, with rewrite
Expand Down Expand Up @@ -5991,12 +5991,12 @@ object a {
}
>>>
object a:
new AdapterLike[Study]:
def query = Query(text take 100, me.map(_.id))
def nbResults = api count query
def slice(offset: Int, length: Int) =
api.search(query, From(offset), Size(length))
.mapFutureList
new AdapterLike[Study] {
def query = Query(text take 100, me.map(_.id))
def nbResults = api count query
def slice(offset: Int, length: Int) =
api.search(query, From(offset), Size(length))
}.mapFutureList
<<< #3623 beforeCurlyLambdaParams
newlines.beforeCurlyLambdaParams = true
===
Expand Down Expand Up @@ -7289,9 +7289,7 @@ object Streamable {
>>>
object Streamable:
def slurp(is: => InputStream)(implicit codec: Codec): String =
new Chars:
def inputStream() = is
.slurp(codec)
new Chars { def inputStream() = is }.slurp(codec)
<<< #4133 remove opt-braces to get fewer braces, without AvoidInfix
rewrite {
scala3.removeOptionalBraces = yes
Expand All @@ -7304,9 +7302,7 @@ object Streamable {
>>>
object Streamable:
def slurp(is: => InputStream)(implicit codec: Codec): String =
new Chars:
def inputStream() = is
.slurp(codec)
new Chars { def inputStream() = is }.slurp(codec)
<<< #4133 no need to remove opt-braces to get fewer braces
object Streamable {
def slurp(is: => InputStream)(implicit codec: Codec): String =
Expand Down

0 comments on commit 9e60294

Please sign in to comment.