From dd36f97a82746cec0b25b94651581fe799e24579 Mon Sep 17 00:00:00 2001 From: Jiuyang Liu Date: Mon, 10 Jan 2022 10:37:17 -0800 Subject: Add scalafmt config, SBT plugin, and mill support Can be run in two ways: * sbt scalaFmtAll * mill mill.scalalib.scalafmt.ScalafmtModule/reformatAll __.sources --- .scalafmt.conf | 26 ++++++++++++++++++++++++++ build.sc | 3 ++- project/plugins.sbt | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .scalafmt.conf diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 00000000..f74e5504 --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,26 @@ +version = 2.6.4 + +maxColumn = 120 +align = most +continuationIndent.defnSite = 2 +assumeStandardLibraryStripMargin = true +docstrings = ScalaDoc +lineEndings = preserve +includeCurlyBraceInSelectChains = false +danglingParentheses = true + +align.tokens.add = [ + { + code = ":" + } +] + +newlines.alwaysBeforeCurlyBraceLambdaParams = false +newlines.alwaysBeforeMultilineDef = false +newlines.implicitParamListModifierForce = [before] + +verticalMultiline.atDefnSite = true + +optIn.annotationNewlines = true + +rewrite.rules = [SortImports, PreferCurlyFors, AvoidInfix] diff --git a/build.sc b/build.sc index 1bf17ae3..1e665a9f 100644 --- a/build.sc +++ b/build.sc @@ -1,6 +1,7 @@ import mill._ import mill.scalalib._ import mill.scalalib.publish._ +import mill.scalalib.scalafmt._ import coursier.maven.MavenRepository import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION` import mill.contrib.buildinfo.BuildInfo @@ -29,7 +30,7 @@ def getTestVersion(dep: String, org: String = "edu.berkeley.cs") = { } // Since chisel contains submodule core and macros, a CommonModule is needed -trait CommonModule extends CrossSbtModule with PublishModule { +trait CommonModule extends CrossSbtModule with PublishModule with ScalafmtModule { def firrtlModule: Option[PublishModule] = None def firrtlIvyDeps = if (firrtlModule.isEmpty) Agg( diff --git a/project/plugins.sbt b/project/plugins.sbt index 8c19290c..f09e1a1b 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -24,5 +24,7 @@ addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.0.1") addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") + // From FIRRTL for building from source addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.33") -- cgit v1.2.3