Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter upgraded to 2.3.0-RC1 #1566

Merged
merged 3 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.0.0-RC5
version=2.3.0-RC1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The native image binaries had a wrong version number that got fixed in e35c827

The RC2 release has completed

Suggested change
version=2.3.0-RC1
version=2.3.0-RC2

project.git = true
project.excludeFilters = [
scalafmt-benchmarks/src/resources,
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolvers ++= Seq(
)

addSbtPlugin("org.scalameta" % "sbt-mdoc" % "1.3.6")
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.6.0-RC4")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.2.1")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.4.31")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
addSbtPlugin(
Expand Down
11 changes: 5 additions & 6 deletions scalafmt-cli/src/main/scala/org/scalafmt/cli/CliArgParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ object CliArgParser {
"test for mis-formatted code, exits with status 1 on first failure."
)
opt[File]("migrate2hocon")
.action(
(file, c) =>
c.copy(
migrate =
Some(AbsoluteFile.fromFile(file, c.common.workingDirectory))
)
.action((file, c) =>
c.copy(
migrate =
Some(AbsoluteFile.fromFile(file, c.common.workingDirectory))
)
)
.text(
"""migrate .scalafmt CLI style configuration to hocon style configuration in .scalafmt.conf"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ object TermDisplay {
s"Last update: ${formatTimestamp(remote)}"
case (None, None) =>
"" // ???
} else
}
else
currentTimeOpt match {
case Some(current) =>
s"Checking for updates since ${formatTimestamp(current)}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Edition {
}

implicit val encoder: ConfEncoder[Edition] =
ConfEncoder.instance(
edition => Conf.Str(f"${edition.year}%d-${edition.month}%02d")
ConfEncoder.instance(edition =>
Conf.Str(f"${edition.year}%d-${edition.month}%02d")
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -888,12 +888,11 @@ class Router(formatOps: FormatOps) {
}, comma.right.end)
case _ => NoPolicy
}
val optToken = nextComma.map(
_ =>
OptimalToken(
rhsOptimalToken(leftTok2tok(nextArg.tokens.last)),
killOnFail = true
)
val optToken = nextComma.map(_ =>
OptimalToken(
rhsOptimalToken(leftTok2tok(nextArg.tokens.last)),
killOnFail = true
)
)
Seq(
Split(Space, 0, optimalAt = optToken).withPolicy(singleLine),
Expand Down Expand Up @@ -1581,10 +1580,9 @@ class Router(formatOps: FormatOps) {
else newlineSplits
case FormatToken(_, c: T.Comment, between)
if newlinesBetween(between) == 0 && c.syntax.startsWith("//") =>
splits.map(
x =>
if (x.modification.isNewline) x.copy(modification = Space)
else x
splits.map(x =>
if (x.modification.isNewline) x.copy(modification = Space)
else x
)
case _ => splits
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ case object AvoidInfix extends Rewrite {
val selectorParens = for {
fstToken <- fstArgsToken
lastToken <- lastArgsToken
} yield
Seq(
TokenPatch.AddLeft(fstToken, "(", keepTok = true),
TokenPatch.AddRight(lastToken, ")", keepTok = true)
)
} yield Seq(
TokenPatch.AddLeft(fstToken, "(", keepTok = true),
TokenPatch.AddRight(lastToken, ")", keepTok = true)
)
selectorParens.getOrElse(Seq.empty)
} else
Nil
Expand All @@ -67,18 +66,16 @@ case object AvoidInfix extends Rewrite {
case _ => Nil
}

val toBeRemoved = fstArgsToken.fold(Seq.empty[TokenPatch])(
token =>
ctx.tokenTraverser
.filter(fstOpToken, token)(_.is[LF])
.map(TokenPatch.Remove)
val toBeRemoved = fstArgsToken.fold(Seq.empty[TokenPatch])(token =>
ctx.tokenTraverser
.filter(fstOpToken, token)(_.is[LF])
.map(TokenPatch.Remove)
)

val hasSingleLineComment = fstArgsToken.exists(
token =>
ctx.tokenTraverser
.filter(fstOpToken, token)(TokenOps.isSingleLineComment)
.nonEmpty
val hasSingleLineComment = fstArgsToken.exists(token =>
ctx.tokenTraverser
.filter(fstOpToken, token)(TokenOps.isSingleLineComment)
.nonEmpty
)

val infixTokens = infix.tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ case object ExpandImportSelectors extends Rewrite {
.map { `import` =>
val expandedImport = `import`.collect {
case importer @ Importer(path, importees) =>
val hasRenamesOrUnimports = importees.exists(
importee =>
importee.is[Importee.Rename] || importee
.is[Importee.Unimport]
val hasRenamesOrUnimports = importees.exists(importee =>
importee.is[Importee.Rename] || importee
.is[Importee.Unimport]
)

val hasWildcards = importees.exists(_.is[Importee.Wildcard])
Expand Down Expand Up @@ -45,9 +44,8 @@ case object ExpandImportSelectors extends Rewrite {
.groupBy(_.tok)

val mergedPatches: Seq[Patch] = groupedPatches.values.map { patches =>
patches.reduce(
(p1: TokenPatch, p2: TokenPatch) =>
TokenPatch.AddRight(p1.tok, p1.newTok + "\n" + p2.newTok)
patches.reduce((p1: TokenPatch, p2: TokenPatch) =>
TokenPatch.AddRight(p1.tok, p1.newTok + "\n" + p2.newTok)
)
}.toSeq

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,20 @@ case class ScalafmtReflect(
}

def parseConfigFromString(configText: String): ScalafmtReflectConfig = {
val configured: Object = try { // scalafmt >= 1.6.0
scalafmtCls.invokeStatic("parseHoconConfig", configText.asParam)
} catch {
case _: NoSuchMethodException =>
// scalafmt >= v0.7.0-RC1 && scalafmt < 1.6.0
val fromHoconEmptyPath =
configCls.invokeStatic("fromHoconString$default$2")
configCls.invokeStatic(
"fromHoconString",
configText.asParam,
fromHoconEmptyPath.asParam(optionCls)
)
}
val configured: Object =
try { // scalafmt >= 1.6.0
scalafmtCls.invokeStatic("parseHoconConfig", configText.asParam)
} catch {
case _: NoSuchMethodException =>
// scalafmt >= v0.7.0-RC1 && scalafmt < 1.6.0
val fromHoconEmptyPath =
configCls.invokeStatic("fromHoconString$default$2")
configCls.invokeStatic(
"fromHoconString",
configText.asParam,
fromHoconEmptyPath.asParam(optionCls)
)
}

try {
new ScalafmtReflectConfig(this, configured.invoke("get"), classLoader)
Expand Down