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 e8b8053 commit 9f56f93
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 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 @@ -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 9f56f93

Please sign in to comment.