diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f479903..b624a50 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,12 @@ jobs: distribution: temurin java-version: 17 - uses: sbt/setup-sbt@8feba82adc7f01ddcf8165b86f778bdb5b82cebc # v1 - - run: sbt compile + # scalafmt は非コンパイルで最速に落ち、scalafix は semanticdb 付きの + # コンパイルを伴うため、その後の compile は追加コストがほぼない。 + # sbtn (thin client) は argv を 1 本の文字列に連結するため引数付きの + # タスクをクォートで区切れない。`;` 区切りの単一コマンドとして渡す。 + - name: Lint and compile + run: sbt "scalafmtCheckAll; scalafmtSbtCheck; scalafixAll --check; compile" build-linux: if: github.event_name == 'push' || github.event_name == 'pull_request' diff --git a/.scalafix.conf b/.scalafix.conf new file mode 100644 index 0000000..c033c70 --- /dev/null +++ b/.scalafix.conf @@ -0,0 +1,13 @@ +rules = [ + OrganizeImports + RemoveUnused + RedundantSyntax + DisableSyntax +] + +# unused import の削除は RemoveUnused に任せて二重適用を避ける +OrganizeImports.removeUnused = false +OrganizeImports.targetDialect = Scala3 + +DisableSyntax.noFinalize = true +DisableSyntax.noReturns = true diff --git a/.scalafmt.conf b/.scalafmt.conf index 08f6ef6..fe23d4c 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -4,3 +4,10 @@ runner.dialect = scala3 runner.dialectOverride.allowSignificantIndentation = false # allows `if x then y` runner.dialectOverride.allowQuietSyntax = true + +# build.sbt / plugins.sbt の縦揃えを維持する。val の = は揃えない +align.tokens."+" = [ + { code = ":=" } + { code = "%" } + { code = "%%" } +] diff --git a/build.sbt b/build.sbt index de8b31b..dea297e 100644 --- a/build.sbt +++ b/build.sbt @@ -2,10 +2,13 @@ import scala.scalanative.build.* enablePlugins(ScalaNativePlugin) +ThisBuild / semanticdbEnabled := true +ThisBuild / scalafmtOnCompile := true + name := "comport" organization := "dev.capslock" scalaVersion := "3.8.2" -scalacOptions += "-no-indent" +scalacOptions ++= Seq("-no-indent", "-Wunused:all") libraryDependencies ++= Seq( "com.lihaoyi" %% "mainargs" % "0.7.8", diff --git a/project/plugins.sbt b/project/plugins.sbt index a4fc4a7..9a4cc4d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1 +1,3 @@ addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.12") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.6.2") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.14.7")