diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala index 99731c8218..7245a0033e 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala @@ -1085,45 +1085,6 @@ class FormatOps( } else Seq(Split(Space, 0), Split(Newline, 1)) } - def decideNewlinesOnlyBeforeClose( - close: Token - )(implicit fileLine: FileLine): Policy = - decideNewlinesOnlyBeforeClose(Split(Newline, 0))(close) - - def decideNewlinesOnlyBeforeCloseOnBreak( - close: Token - )(implicit fileLine: FileLine): Policy = - delayedBreakPolicyFor(close)(decideNewlinesOnlyBeforeClose) - - def decideNewlinesOnlyBeforeClose( - split: Split - )(close: Token)(implicit fileLine: FileLine): Policy = - Policy.on(close) { - case d: Decision if d.formatToken.right eq close => - d.onlyNewlinesWithFallback(split) - } - - def decideNewlinesOnlyAfterClose( - close: Token - )(implicit fileLine: FileLine): Policy = - decideNewlinesOnlyAfterClose(Split(Newline, 0))(close) - - def decideNewlinesOnlyAfterClose( - split: Split - )(close: Token)(implicit fileLine: FileLine): Policy = - Policy.after(close) { - case d: Decision if d.formatToken.left eq close => - d.onlyNewlinesWithFallback(split) - } - - def decideNewlinesOnlyAfterToken( - token: Token - )(implicit fileLine: FileLine): Policy = - Policy.after(token) { - case d: Decision if d.formatToken.left eq token => - d.onlyNewlinesWithoutFallback - } - def getForceConfigStyle: (Set[Tree], Set[TokenHash]) = { val maxDistance = runner.optimizer.forceConfigStyleOnOffset if (maxDistance < 0) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/util/PolicyOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/util/PolicyOps.scala index 26b5baa10b..cdc84ed527 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/util/PolicyOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/util/PolicyOps.scala @@ -3,6 +3,7 @@ package org.scalafmt.util import scala.meta.tokens.{Token => T} import org.scalafmt.internal.Decision +import org.scalafmt.internal.Newline import org.scalafmt.internal.Policy import org.scalafmt.internal.Policy.End import org.scalafmt.internal.Split @@ -133,4 +134,43 @@ object PolicyOps { )(f: T => Policy)(implicit fileLine: FileLine): Policy = delayedBreakPolicyBefore(token)(f(token)) + def decideNewlinesOnlyBeforeClose(close: T)(implicit + fileLine: FileLine + ): Policy = + decideNewlinesOnlyBeforeClose(Split(Newline, 0))(close) + + def decideNewlinesOnlyBeforeCloseOnBreak(close: T)(implicit + fileLine: FileLine + ): Policy = + delayedBreakPolicyFor(close)(decideNewlinesOnlyBeforeClose) + + def decideNewlinesOnlyBeforeClose( + split: Split + )(close: T)(implicit fileLine: FileLine): Policy = + Policy.on(close) { + case d: Decision if d.formatToken.right eq close => + d.onlyNewlinesWithFallback(split) + } + + def decideNewlinesOnlyAfterClose(close: T)(implicit + fileLine: FileLine + ): Policy = + decideNewlinesOnlyAfterClose(Split(Newline, 0))(close) + + def decideNewlinesOnlyAfterClose( + split: Split + )(close: T)(implicit fileLine: FileLine): Policy = + Policy.after(close) { + case d: Decision if d.formatToken.left eq close => + d.onlyNewlinesWithFallback(split) + } + + def decideNewlinesOnlyAfterToken( + token: T + )(implicit fileLine: FileLine): Policy = + Policy.after(token) { + case d: Decision if d.formatToken.left eq token => + d.onlyNewlinesWithoutFallback + } + }