Skip to content

Commit

Permalink
Formatting: update version to v3.8.4-RC3
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 27, 2024
1 parent 4aeb6de commit 5e76cc2
Show file tree
Hide file tree
Showing 54 changed files with 765 additions and 777 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=3.8.2
version=3.8.4-RC3
runner.dialect = scala213
project {
git = true
Expand Down
15 changes: 7 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,18 @@ lazy val communityTestsScala3 = project
.in(file("scalafmt-tests-community/scala3")).settings(communityTestsSettings)
.enablePlugins(BuildInfoPlugin).dependsOn(communityTestsCommon)

lazy val communityTestsSpark = project
.in(file("scalafmt-tests-community/spark")).settings(communityTestsSettings)
.enablePlugins(BuildInfoPlugin).dependsOn(communityTestsCommon)

lazy val communityTestsIntellij = project
.in(file("scalafmt-tests-community/intellij"))
lazy val communityTestsSpark = project.in(file("scalafmt-tests-community/spark"))
.settings(communityTestsSettings).enablePlugins(BuildInfoPlugin)
.dependsOn(communityTestsCommon)

lazy val communityTestsOther = project
.in(file("scalafmt-tests-community/other")).settings(communityTestsSettings)
lazy val communityTestsIntellij = project
.in(file("scalafmt-tests-community/intellij")).settings(communityTestsSettings)
.enablePlugins(BuildInfoPlugin).dependsOn(communityTestsCommon)

lazy val communityTestsOther = project.in(file("scalafmt-tests-community/other"))
.settings(communityTestsSettings).enablePlugins(BuildInfoPlugin)
.dependsOn(communityTestsCommon)

lazy val benchmarks = project.in(file("scalafmt-benchmarks")).settings(
publish / skip := true,
moduleName := "scalafmt-benchmarks",
Expand Down
9 changes: 5 additions & 4 deletions readme/src/main/scala/org/scalafmt/readme/Readme.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ object Readme {
val expressions = s"{$code}".parse[Stat].get.asInstanceOf[Term.Block].stats
val evaluated = eval[Any](code)
val output = evaluated match {
case s: String => s"""|
|"$s"""".stripMargin
case s: String =>
s"""|
|"$s"""".stripMargin
case x => x.toString
}
val result = s"""|${expressions.map(x => s"scala> ${x.toString().trim}")
Expand Down Expand Up @@ -142,8 +143,8 @@ object Readme {
}

def demoStyle(style: ScalafmtConfig)(code: String): TypedTag[String] = {
val formatted = Scalafmt
.format(code, style.copy(runner = ScalafmtRunner.sbt)).get
val formatted = Scalafmt.format(code, style.copy(runner = ScalafmtRunner.sbt))
.get
div(sideBySide(code, formatted), configurationBlock(style))
}

Expand Down
16 changes: 8 additions & 8 deletions scalafmt-cli/jvm/src/main/scala/org/scalafmt/cli/CliUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ private[scalafmt] trait CliUtils {
protected val isScalaNative: Boolean = false

def nailMain(nGContext: NGContext): Unit = {
val workingDirectory = AbsoluteFile.fromPathIfAbsolute(
nGContext.getWorkingDirectory,
).getOrElse {
throw new IllegalStateException(
s"Expected absolute path, " +
s"obtained nGContext.getWorkingDirectory = ${nGContext.getWorkingDirectory}",
)
}
val workingDirectory = AbsoluteFile
.fromPathIfAbsolute(nGContext.getWorkingDirectory).getOrElse {
throw new IllegalStateException(
s"Expected absolute path, " +
s"obtained nGContext.getWorkingDirectory = ${nGContext
.getWorkingDirectory}",
)
}
val exit = Cli.mainWithOptions(
nGContext.getArgs,
CliOptions.default.copy(common =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ object CliArgParser {
|${FileFetchMode.help}
|""".stripMargin,
)
opt[Unit]("diff")
.action((_, c) => c.copy(mode = Option(DiffFiles("master")))).text(
opt[Unit]("diff").action((_, c) => c.copy(mode = Option(DiffFiles("master"))))
.text(
s"""|Format files listed in `git diff` against master.
|Deprecated: use --mode diff instead""".stripMargin,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ case class CliOptions(

private[cli] lazy val hoconOpt: Option[ConfParsed] = configStr
.map(ConfParsed.fromString(_)).orElse {
canonicalConfigFile.map(
_.fold(x => new ConfParsed(Configured.exception(x)), ConfParsed.fromPath(_)),
)
canonicalConfigFile.map(_.fold(
x => new ConfParsed(Configured.exception(x)),
ConfParsed.fromPath(_),
))
}

lazy val fileFetchMode: FileFetchMode = mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ object TermDisplay extends TermUtils {
def display(): String =
if (isDone) (currentTimeOpt, remoteTimeOpt) match {
case (Some(current), Some(remote)) =>
if (current < remote)
s"Updated since ${formatTimestamp(current)} (${formatTimestamp(remote)})"
if (current < remote) s"Updated since ${formatTimestamp(
current,
)} (${formatTimestamp(remote)})"
else if (current == remote)
s"No new update since ${formatTimestamp(current)}"
else
s"Warning: local copy newer than remote one (${formatTimestamp(current)} > ${formatTimestamp(remote)})"
else s"Warning: local copy newer than remote one (${formatTimestamp(
current,
)} > ${formatTimestamp(remote)})"
case (Some(_), None) =>
// FIXME Likely a 404 Not found, that should be taken into account by the cache
"No modified time in response"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ class ConfParsed(val conf: Configured[Conf]) extends AnyVal {
getHoconValueOpt[String]("onTestFailure")

def encoding: Option[Either[String, Codec]] =
getHoconValueOpt[String]("encoding").map {
_.flatMap(x => Try(Codec(x)).toEither.left.map(_.getMessage))
}
getHoconValueOpt[String]("encoding")
.map(_.flatMap(x => Try(Codec(x)).toEither.left.map(_.getMessage)))

def version: Option[Either[String, String]] =
getHoconValueOpt[String]("version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package scala.collection
package object mutable {

implicit class ImplicitMap[K, V](private val obj: Map[K, V]) extends AnyVal {
def updateWith(key: K)(
remappingFunction: Option[V] => Option[V],
): Option[V] = obj.get(key) match {
def updateWith(
key: K,
)(remappingFunction: Option[V] => Option[V]): Option[V] = obj.get(key) match {
case vOldOpt @ Some(vOld) =>
val vOpt = remappingFunction(vOldOpt)
vOpt match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ object Docstrings {

implicit val surface: generic.Surface[Docstrings] = generic
.deriveSurface[Docstrings]
implicit val codec: ConfCodecEx[Docstrings] = generic
.deriveCodecEx(Docstrings()).noTypos
implicit val codec: ConfCodecEx[Docstrings] = generic.deriveCodecEx(Docstrings())
.noTypos

sealed abstract class Style {
def skipFirstLine(v: Option[BlankFirstLine]): Option[BlankFirstLine]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ case class Indents(

object Indents {
implicit lazy val surface: generic.Surface[Indents] = generic.deriveSurface
implicit lazy val codec: ConfCodecEx[Indents] = generic
.deriveCodecEx(Indents()).noTypos
implicit lazy val codec: ConfCodecEx[Indents] = generic.deriveCodecEx(Indents())
.noTypos

sealed abstract class RelativeToLhs
object RelativeToLhs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ case class ScalafmtConfig(
import ScalafmtConfig._

private[scalafmt] lazy val alignMap: Map[String, Seq[AlignToken.Matcher]] =
align.tokens.map(x => x.code -> x).toMap.map { case (k, v) =>
k -> v.getMatcher
}
align.tokens.map(x => x.code -> x).toMap
.map { case (k, v) => k -> v.getMatcher }

private[scalafmt] def withDialect(dialect: NamedDialect): ScalafmtConfig =
copy(runner = runner.withDialect(dialect))
Expand Down Expand Up @@ -218,9 +217,8 @@ case class ScalafmtConfig(
val cfg = conf match {
case x: Conf.Str => withDialect(NamedDialect.codec.read(None, x).get)
case x =>
val styleOpt = eitherPat.left.toOption.flatMap { lang =>
project.layout.map(_.withLang(lang, this))
}
val styleOpt = eitherPat.left.toOption
.flatMap(lang => project.layout.map(_.withLang(lang, this)))
decoder.read(styleOpt.orElse(Some(this)), x).get
}
eitherPat -> cfg
Expand Down Expand Up @@ -378,9 +376,8 @@ object ScalafmtConfig {

private def readActiveStylePresets(conf: Conf): Configured[ScalafmtConfig] =
(conf match {
case Conf.Str(x) => availableStyles.get(x.toLowerCase).map { style =>
Configured.ok(style)
}
case Conf.Str(x) => availableStyles.get(x.toLowerCase)
.map(style => Configured.ok(style))
case _ => None
}).getOrElse {
val alternatives = activeStyles.keys.mkString(", ")
Expand Down Expand Up @@ -466,9 +463,8 @@ object ScalafmtConfig {
(stateOpt, conf) => {
val stylePreset = conf match {
case x: Conf.Obj =>
val section = Seq(Presets.presetKey, "style").flatMap { y =>
x.field(y).map(y -> _)
}
val section = Seq(Presets.presetKey, "style")
.flatMap(y => x.field(y).map(y -> _))
section.headOption.map { case (field, obj) =>
obj -> Conf.Obj((x.map - field).toList)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ case class ScalafmtOptimizer(
pruneSlowStates: ScalafmtOptimizer.PruneSlowStates =
ScalafmtOptimizer.PruneSlowStates.Yes,
recurseOnBlocks: Boolean = true,
@annotation.ExtraName("forceConfigStyleOnOffset")
@annotation.DeprecatedName(
@annotation.ExtraName("forceConfigStyleOnOffset") @annotation.DeprecatedName(
"forceConfigStyleMinSpan",
"Use `callSite.minSpan` instead",
"3.8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,8 @@ private class BestFirstSearch private (range: Set[Range])(implicit
stats.trackState(state)
val idx = state.depth
val ft = tokens(idx)
val active = state.policy.execute(Decision(ft, routes(idx))).filter { s =>
s.isActive && pred(s)
}
val active = state.policy.execute(Decision(ft, routes(idx)))
.filter(s => s.isActive && pred(s))
val splits =
if (active.isEmpty || !ft.meta.formatOff && ft.inside(range)) active
else {
Expand All @@ -259,9 +258,9 @@ private class BestFirstSearch private (range: Set[Range])(implicit
}

private def stateAsOptimal(state: State, splits: Seq[Split]) = {
val isOptimal = splits.exists { s =>
s.isNL && s.penalty < Constants.ShouldBeNewline
} || tokens.isRightCommentWithBreak(tokens(state.depth))
val isOptimal = splits
.exists(s => s.isNL && s.penalty < Constants.ShouldBeNewline) ||
tokens.isRightCommentWithBreak(tokens(state.depth))
if (isOptimal) Some(state) else None
}

Expand Down Expand Up @@ -301,15 +300,15 @@ private class BestFirstSearch private (range: Set[Range])(implicit
val deepestYet = stats.deepestYet
val nextSplits = routes(deepestYet.depth)
val tok = tokens(deepestYet.depth)
val splitsAfterPolicy = deepestYet.policy
.execute(Decision(tok, nextSplits))
val splitsAfterPolicy = deepestYet.policy.execute(Decision(tok, nextSplits))
def printSeq(vals: Seq[_]): String = vals.mkString("\n ", "\n ", "")
val msg = s"""|UNABLE TO FORMAT,
|tok #${deepestYet.depth}/${tokens.length}: $tok
|policies:${printSeq(deepestYet.policy.policies)}
|splits (before policy):${printSeq(nextSplits)}
|splits (after policy):${printSeq(splitsAfterPolicy)}
|""".stripMargin
val msg =
s"""|UNABLE TO FORMAT,
|tok #${deepestYet.depth}/${tokens.length}: $tok
|policies:${printSeq(deepestYet.policy.policies)}
|splits (before policy):${printSeq(nextSplits)}
|splits (after policy):${printSeq(splitsAfterPolicy)}
|""".stripMargin
if (initStyle.runner.debug) logger.debug(
s"""|Failed to format
|$msg""".stripMargin,
Expand Down Expand Up @@ -416,8 +415,7 @@ object BestFirstSearch {
}

private def updateBestImpl(state: State): Boolean = state.split.isNL &&
!state.hasSlb() &&
(best.getOrElseUpdate(state.prev.depth, state) eq state)
!state.hasSlb() && (best.getOrElseUpdate(state.prev.depth, state) eq state)

def updateBest(state: State, furtherState: State)(implicit
Q: StateQueue,
Expand Down Expand Up @@ -446,9 +444,8 @@ object BestFirstSearch {
def retry: Option[StateStats] = {
val ok = best.nonEmpty &&
(pruneSlowStates eq ScalafmtOptimizer.PruneSlowStates.Yes)
if (ok) Some(
new StateStats(tokens, runner, ScalafmtOptimizer.PruneSlowStates.No),
)
if (ok)
Some(new StateStats(tokens, runner, ScalafmtOptimizer.PruneSlowStates.No))
else None
}
}
Expand Down
Loading

0 comments on commit 5e76cc2

Please sign in to comment.