From d3b160450efb45145f33ab19c4731f578a3a9c5e Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Tue, 31 Dec 2024 10:18:16 -0800 Subject: [PATCH] Newlines: add a shortcut to check for `classic` --- .../shared/src/main/scala/org/scalafmt/config/Newlines.scala | 4 +++- .../shared/src/main/scala/org/scalafmt/internal/State.scala | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/Newlines.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/Newlines.scala index f3242a962..0c06cccf1 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/Newlines.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/Newlines.scala @@ -255,6 +255,8 @@ case class Newlines( @inline def keep: Boolean = source eq Newlines.keep @inline + def classic: Boolean = source eq Newlines.classic + @inline def keepBreak(hasBreak: => Boolean): Boolean = keep && hasBreak @inline def keepBreak(newlines: Int): Boolean = keepBreak(!FT.noBreak(newlines)) @@ -349,7 +351,7 @@ case class Newlines( def isBeforeOpenParenDefnSite: Boolean = beforeOpenParenDefnSite.isDefined private[scalafmt] lazy val encloseSelectChains = selectChains.enclose - .getOrElse(source.ne(Newlines.classic)) + .getOrElse(!classic) } diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/State.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/State.scala index d1caaf4a0..b2d96cdab 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/State.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/State.scala @@ -362,8 +362,7 @@ object State { new WithComparisons(compareCost, compareDepth, compareLineId) def get(style: ScalafmtConfig): Ordering[State] = - if (style.newlines.source eq Newlines.classic) classicOrdering - else compactOrdering + if (style.newlines.classic) classicOrdering else compactOrdering class WithComparisons(comparisons: (State, State) => Int*) extends Ordering[State] {