Skip to content

Commit 12db9a5

Browse files
committed
[ETCM-522][ETCM-523] Add scalafix and add scalafmt rules
1 parent cf30683 commit 12db9a5

File tree

4 files changed

+78
-5
lines changed

4 files changed

+78
-5
lines changed

.scalafix.conf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
rules = [
2+
ExplicitResultTypes
3+
NoAutoTupling
4+
NoValInForComprehension
5+
OrganizeImports
6+
ProcedureSyntax
7+
RemoveUnused
8+
]
9+
10+
OrganizeImports {
11+
groupedImports = Explode
12+
groups = [
13+
"re:javax?\\."
14+
"akka."
15+
"cats."
16+
"monix."
17+
"scala."
18+
"scala.meta."
19+
"*"
20+
"io.iohk.ethereum."
21+
]
22+
removeUnused = true
23+
}
24+
25+
RemoveUnused {
26+
imports = false // handled by OrganizeImports
27+
}

.scalafmt.conf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
version = "2.7.1"
2-
align = none
1+
version = "2.7.5"
2+
align.preset = some
33
maxColumn = 120
4+
5+
rewrite.rules = [AvoidInfix, RedundantBraces, RedundantParens, SortModifiers]

build.sbt

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
4545
name := projectName,
4646
organization := "io.iohk",
4747
scalaVersion := `scala-2.13`,
48+
semanticdbEnabled := true, // enable SemanticDB
49+
semanticdbVersion := scalafixSemanticdb.revision, // use Scalafix compatible version
50+
ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value),
51+
ThisBuild / scalafixDependencies ++= List(
52+
"com.github.liancheng" %% "organize-imports" % "0.5.0",
53+
"com.github.vovapolu" %% "scaluzzi" % "0.1.16"
54+
),
4855
// Scalanet snapshots are published to Sonatype after each build.
4956
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
5057
testOptions in Test += Tests
@@ -53,7 +60,9 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
5360
"-unchecked",
5461
"-deprecation",
5562
"-feature",
56-
"-Xfatal-warnings",
63+
// "-Xfatal-warnings", // disabled until unused are removed
64+
"-Ywarn-unused",
65+
"-Xlint",
5766
"-encoding",
5867
"utf-8"
5968
),
@@ -86,6 +95,7 @@ lazy val bytes = {
8695
.in(file("bytes"))
8796
.configs(Integration)
8897
.settings(commonSettings("mantis-bytes"))
98+
.settings(inConfig(Integration)(scalafixConfigSettings(Integration)))
8999
.settings(publishSettings)
90100
.settings(
91101
libraryDependencies ++=
@@ -102,6 +112,7 @@ lazy val crypto = {
102112
.configs(Integration)
103113
.dependsOn(bytes)
104114
.settings(commonSettings("mantis-crypto"))
115+
.settings(inConfig(Integration)(scalafixConfigSettings(Integration)))
105116
.settings(publishSettings)
106117
.settings(
107118
libraryDependencies ++=
@@ -119,6 +130,7 @@ lazy val rlp = {
119130
.configs(Integration)
120131
.dependsOn(bytes)
121132
.settings(commonSettings("mantis-rlp"))
133+
.settings(inConfig(Integration)(scalafixConfigSettings(Integration)))
122134
.settings(publishSettings)
123135
.settings(
124136
libraryDependencies ++=
@@ -176,8 +188,6 @@ lazy val node = {
176188
(test in Evm) := (test in Evm).dependsOn(solidityCompile).value
177189
(sourceDirectory in Evm) := baseDirectory.value / "src" / "evmTest"
178190

179-
val sep = java.io.File.separator
180-
181191
val node = project
182192
.in(file("."))
183193
.configs(Integration, Benchmark, Evm, Rpc)
@@ -201,6 +211,9 @@ lazy val node = {
201211
buildInfoOptions in Compile += BuildInfoOption.ToMap
202212
)
203213
.settings(commonSettings("mantis"): _*)
214+
.settings(inConfig(Integration)(scalafixConfigSettings(Integration)))
215+
.settings(inConfig(Evm)(scalafixConfigSettings(Evm)))
216+
.settings(inConfig(Rpc)(scalafixConfigSettings(Rpc)))
204217
.settings(
205218
libraryDependencies ++= dep
206219
)
@@ -290,6 +303,36 @@ addCommandAlias(
290303
|""".stripMargin
291304
)
292305

306+
// format all modules
307+
addCommandAlias(
308+
"formatAll",
309+
""";compile-all
310+
|;bytes/scalafixAll
311+
|;bytes/scalafmtAll
312+
|;crypto/scalafixAll
313+
|;crypto/scalafmtAll
314+
|;rlp/scalafixAll
315+
|;rlp/scalafmtAll
316+
|;scalafixAll
317+
|;scalafmtAll
318+
|""".stripMargin
319+
)
320+
321+
// check modules formatting
322+
addCommandAlias(
323+
"formatCheck",
324+
""";compile-all
325+
|;bytes/scalafixAll --check
326+
|;bytes/scalafmtCheckAll
327+
|;crypto/scalafixAll --check
328+
|;crypto/scalafmtCheckAll
329+
|;rlp/scalafixAll --check
330+
|;rlp/scalafmtCheckAll
331+
|;scalafixAll --check
332+
|;scalafmtCheckAll
333+
|""".stripMargin
334+
)
335+
293336
// testAll
294337
addCommandAlias(
295338
"testAll",

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
1212
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
1313
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
1414
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.6")
15+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.29")

0 commit comments

Comments
 (0)