Skip to content

Commit

Permalink
Merge pull request #1380 from olafurpg/upgrade-fmt
Browse files Browse the repository at this point in the history
Upgrade to latest scalafmt.
  • Loading branch information
tanishiking authored Mar 6, 2019
2 parents cc6e086 + 094a971 commit 4aba063
Show file tree
Hide file tree
Showing 73 changed files with 627 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=1.6.0-RC4
version=2.0.0-RC5
project.git = true
project.excludeFilters = [
scalafmt-benchmarks/src/resources,
Expand Down
3 changes: 2 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.6.0-RC4")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.2.2")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
addSbtPlugin(
"io.get-coursier" % "sbt-coursier" % coursier.util.Properties.version)
"io.get-coursier" % "sbt-coursier" % coursier.util.Properties.version
)
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.7")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.4")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.5.0")
Expand Down
38 changes: 26 additions & 12 deletions readme/src/main/scala/org/scalafmt/readme/Adopters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import scalatags.Text.TypedTag
case class Adopter(
name: String,
url: String,
description: Option[String] = None) {
description: Option[String] = None
) {
import scalatags.Text.all._
def bullet: TypedTag[String] = li(
a(href := url, name),
Expand All @@ -18,56 +19,69 @@ object Adopters {
Adopter(
"scalafmt",
"http://scalafmt.org",
Some("Code formatter for Scala")),
Some("Code formatter for Scala")
),
Adopter(
"sbt",
"https://github.com/sbt/sbt",
Some("The interactive build tool for Scala")),
Some("The interactive build tool for Scala")
),
Adopter(
"scala-native",
"https://github.com/scala-native/scala-native",
Some("Your favourite language gets closer to bare metal.")),
Some("Your favourite language gets closer to bare metal.")
),
Adopter("HERE", "http://here.com", None),
Adopter("Letgo", "http://letgo.com", None),
Adopter(
"Seventh Sense",
"http://7thsense.io",
Some("Predictive analytics for sales and marketing")),
Some("Predictive analytics for sales and marketing")
),
Adopter(
"Teralytics",
"http://teralytics.net",
Some("We transform raw, human activity data into valuable insights.")),
Some("We transform raw, human activity data into valuable insights.")
),
Adopter(
"Venatus Media",
"https://venatusmedia.com",
Some(
"We represent some of the largest entertainment publishers and monetize billions of ads.")),
"We represent some of the largest entertainment publishers and monetize billions of ads."
)
),
Adopter(
"http4s",
"http://http4s.org",
Some("A minimal, idiomatic Scala interface for HTTP")),
Some("A minimal, idiomatic Scala interface for HTTP")
),
Adopter(
"Mendix",
"https://mendix.com",
Some(
"The fastest and easiest platform to create and continuously improve mobile and web apps at scale.")),
"The fastest and easiest platform to create and continuously improve mobile and web apps at scale."
)
),
Adopter(
"Foursquare",
"https://enterprise.foursquare.com",
Some(
"We use location intelligence to build meaningful consumer experiences and business solutions.")
"We use location intelligence to build meaningful consumer experiences and business solutions."
)
),
Adopter(
"Codacy",
"https://codacy.com",
Some(
"Codacy is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.")
"Codacy is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews."
)
),
Adopter(
"ZyseMe",
"https://www.zyse.me/",
Some(
"We use ML to predict body measurements and automate pattern creation to integrate with production, allowing companies to produce and/or sell made-to-measure garments at scale.")
"We use ML to predict body measurements and automate pattern creation to integrate with production, allowing companies to produce and/or sell made-to-measure garments at scale."
)
)
)
}
50 changes: 33 additions & 17 deletions readme/src/main/scala/org/scalafmt/readme/Readme.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ object Readme {

def configurationBlock(
style: ScalafmtConfig,
collapsed: Boolean = false): TypedTag[String] = {
collapsed: Boolean = false
): TypedTag[String] = {
div(
span(
"Show/hide configuration used for this example",
`class` := "scalafmt-configuration-toggle"),
`class` := "scalafmt-configuration-toggle"
),
pre(changedConfig(style)),
`class` := {
"scalafmt-configuration" + (
Expand All @@ -143,8 +145,10 @@ object Readme {
List(
div(hl.scala(code), `class` := "before"),
div(hl.scala(formatted), `class` := "after")
)),
configurationBlock(style))
)
),
configurationBlock(style)
)
}

def demoStyle(style: ScalafmtConfig)(code: String): TypedTag[String] = {
Expand All @@ -166,7 +170,9 @@ object Readme {
code,
ScalafmtConfig.default40.copy(
align =
ScalafmtConfig.default40.align.copy(tokens = AlignToken.default)))
ScalafmtConfig.default40.align.copy(tokens = AlignToken.default)
)
)
.get
hl.scala(formatted)
}
Expand All @@ -178,13 +184,15 @@ object Readme {
ScalafmtConfig.default.copy(
rewrite = ScalafmtConfig.default.rewrite.copy(
rules = Seq(AvoidInfix)
))
)
)

val rewriteImportSelectors =
ScalafmtConfig.default.copy(
rewrite = ScalafmtConfig.default.rewrite.copy(
rules = Seq(ExpandImportSelectors)
))
)
)

val rewriteBraces =
ScalafmtConfig.default.copy(
Expand All @@ -193,31 +201,36 @@ object Readme {
stringInterpolation = true
),
rules = Seq(RedundantBraces)
))
)
)

val rewriteParens =
ScalafmtConfig.default.copy(
rewrite = ScalafmtConfig.default.rewrite.copy(
rules = Seq(RedundantParens)
))
)
)

val rewriteImports =
ScalafmtConfig.default.copy(
rewrite = ScalafmtConfig.default.rewrite.copy(
rules = Seq(SortImports)
))
)
)

val rewriteAsciiImports =
ScalafmtConfig.default.copy(
rewrite = ScalafmtConfig.default.rewrite.copy(
rules = Seq(AsciiSortImports)
))
)
)

val rewriteSortModifiers =
ScalafmtConfig.default120.copy(
rewrite = ScalafmtConfig.default.rewrite.copy(
rules = Seq(SortModifiers)
))
)
)

/**
* This looks way too hacky. But can't seem to find a typeclass
Expand All @@ -241,7 +254,8 @@ object Readme {
ScalafmtConfig.default.copy(
rewrite = ScalafmtConfig.default.rewrite.copy(
rules = Seq(PreferCurlyFors)
))
)
)

val verticalAlign = ScalafmtConfig.default.copy(
maxColumn = 60,
Expand All @@ -250,9 +264,10 @@ object Readme {

val VerticalMultilineDefultConfigStr = Conf.printHocon(
Conf.Obj(
"verticalMultiline" -> ConfEncoder[VerticalMultiline].write(
ScalafmtConfig.default.verticalMultiline)
))
"verticalMultiline" -> ConfEncoder[VerticalMultiline]
.write(ScalafmtConfig.default.verticalMultiline)
)
)

val verticalAlignImplicitBefore = ScalafmtConfig.default.copy(
maxColumn = 60,
Expand Down Expand Up @@ -317,7 +332,8 @@ object Readme {
val alignMost = ScalafmtConfig.default.copy(align = Align.most)
val alignCaseArrow = ScalafmtConfig.default
val alignArrowEnum = ScalafmtConfig.defaultWithAlign.copy(
align = Align.default.copy(arrowEnumeratorGenerator = true))
align = Align.default.copy(arrowEnumeratorGenerator = true)
)
val alignModuleId = ScalafmtConfig.defaultWithAlign

def format(style: ScalafmtConfig)(code: String): TypedTag[String] = {
Expand Down
Binary file modified scalafmt
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ trait FormatBenchmark {
rewrite = RewriteSettings(
rules = Seq(SortImports, RedundantBraces)
)
))
)
)
.get
}
}
Expand Down Expand Up @@ -61,7 +62,9 @@ abstract class MacroBenchmark(parallel: Boolean, maxFiles: Int)
.files(
Corpus.fastparse.copy(
// TODO(olafur) remove once testkit 1.7 is out
url = Corpus.fastparse.url.replace("olafurpg", "scalameta")))
url = Corpus.fastparse.url.replace("olafurpg", "scalameta")
)
)
.filter { f =>
f.projectUrl.contains("scala-js")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ abstract class MicroBenchmark(path: String*) extends FormatBenchmark {
if (filename.isFile) filename
else
FileOps.getFile(
Seq("scalafmt-benchmarks", "src", "resources") ++ path: _*)
Seq("scalafmt-benchmarks", "src", "resources") ++ path: _*
)
}

def scalametaParser(): Unit = {
Expand Down
9 changes: 6 additions & 3 deletions scalafmt-cli/src/main/scala/org/scalafmt/cli/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ object Cli {
def nailMain(nGContext: NGContext): Unit = {
val workingDirectory =
AbsoluteFile.fromPath(nGContext.getWorkingDirectory).getOrElse {
throw new IllegalStateException(s"Expected absolute path, " +
s"obtained nGContext.getWorkingDirectory = ${nGContext.getWorkingDirectory}")
throw new IllegalStateException(
s"Expected absolute path, " +
s"obtained nGContext.getWorkingDirectory = ${nGContext.getWorkingDirectory}"
)
}
val exit = mainWithOptions(
nGContext.getArgs,
Expand All @@ -33,7 +35,8 @@ object Cli {
in: InputStream,
out: PrintStream,
err: PrintStream,
workingDirectory: String): Unit = {
workingDirectory: String
): Unit = {
val options = CliOptions.default.copy(
common = CommonOptions(
in = in,
Expand Down
43 changes: 30 additions & 13 deletions scalafmt-cli/src/main/scala/org/scalafmt/cli/CliArgParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ object CliArgParser {
override def showUsageOnError = false

private def printAndExit(
inludeUsage: Boolean)(ignore: Unit, c: CliOptions): CliOptions = {
inludeUsage: Boolean
)(ignore: Unit, c: CliOptions): CliOptions = {
if (inludeUsage) showUsage
else showHeader
sys.exit
Expand All @@ -43,7 +44,8 @@ object CliArgParser {

private def readConfigFromFile(
file: String,
c: CliOptions): CliOptions = {
c: CliOptions
): CliOptions = {
val configFile =
AbsoluteFile.fromFile(new File(file), c.common.workingDirectory)
c.copy(config = Some(configFile.jfile.toPath))
Expand All @@ -67,16 +69,21 @@ object CliArgParser {
.unbounded()
.action((file, c) => addFile(file, c))
.text(
"file or directory, in which case all *.scala files are formatted.")
"file or directory, in which case all *.scala files are formatted."
)

opt[Seq[File]]('f', "files")
.action { (files, c) =>
c.copy(customFiles =
AbsoluteFile.fromFiles(files, c.common.workingDirectory))
c.copy(
customFiles =
AbsoluteFile.fromFiles(files, c.common.workingDirectory)
)
}
.hidden() // this option isn't needed anymore. Simply pass the files as
// arguments. Keeping for backwards compatibility
.text("file or directory, in which case all *.scala files are formatted. Deprecated: pass files as arguments")
.text(
"file or directory, in which case all *.scala files are formatted. Deprecated: pass files as arguments"
)

opt[Unit]('i', "in-place")
.action((opt, c) => c.copy(writeMode = Override))
Expand All @@ -94,7 +101,8 @@ object CliArgParser {
opt[Seq[String]]("exclude")
.action((excludes, c) => c.copy(customExcludes = excludes))
.text(
"file or directory, in which case all *.scala files are formatted.")
"file or directory, in which case all *.scala files are formatted."
)
opt[String]('c', "config")
.action(readConfigFromFile)
.text("a file path to .scalafmt.conf.")
Expand All @@ -110,21 +118,30 @@ object CliArgParser {
opt[String]("assume-filename")
.action((filename, c) => c.copy(assumeFilename = filename))
.text(
"when using --stdin, use --assume-filename to hint to scalafmt that the input is an .sbt file.")
"when using --stdin, use --assume-filename to hint to scalafmt that the input is an .sbt file."
)
opt[Unit]("test")
.action((_, c) => c.copy(testing = true))
.text("test for mis-formatted code, exits with status 1 on failure.")
opt[File]("migrate2hocon")
.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""")
.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"""
)
opt[Unit]("diff")
.action((_, c) => c.copy(diff = Some("master")))
.text("If set, only format edited files in git diff against master.")
opt[String]("diff-branch")
.action((branch, c) => c.copy(diff = Some(branch)))
.text("If set, only format edited files in git diff against provided branch.")
.text(
"If set, only format edited files in git diff against provided branch."
)
opt[Unit]("build-info")
.action({
case (_, c) =>
Expand Down
Loading

0 comments on commit 4aba063

Please sign in to comment.