From f4e16bab1586aa41698c8649522397717a3642b8 Mon Sep 17 00:00:00 2001 From: Windymelt Date: Mon, 10 Aug 2026 19:30:03 +0900 Subject: [PATCH 1/2] Add scalafmt and scalafix checks to CI Add sbt-scalafmt 2.6.2 and sbt-scalafix 0.14.7 (sbt 2 artifacts), and run scalafmtCheckAll, scalafmtSbtCheck and scalafixAll --check in the compile job before compile. scalafix requires a semanticdb-enabled compile, so the subsequent compile costs almost nothing. The align.tokens entries in .scalafmt.conf keep the existing vertical alignment in build.sbt and plugins.sbt without aligning `val` in Scala sources. Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/ci.yml | 5 ++++- .scalafix.conf | 13 +++++++++++++ .scalafmt.conf | 7 +++++++ build.sbt | 5 ++++- project/plugins.sbt | 2 ++ 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .scalafix.conf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f479903..f392591 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,10 @@ jobs: distribution: temurin java-version: 17 - uses: sbt/setup-sbt@8feba82adc7f01ddcf8165b86f778bdb5b82cebc # v1 - - run: sbt compile + # scalafmt は非コンパイルで最速に落ち、scalafix は semanticdb 付きの + # コンパイルを伴うため、その後の compile は追加コストがほぼない + - 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") From 6f91679e3aad54be6ba2a2cd97ce6c875aa40097 Mon Sep 17 00:00:00 2001 From: Windymelt Date: Mon, 10 Aug 2026 19:44:30 +0900 Subject: [PATCH 2/2] Pass lint tasks to sbt as one semicolon-separated command sbtn (the thin client) joins argv into a single string, so quoting `scalafixAll --check` as one shell argument does not survive. sbt then parsed `--check` as a separate command and failed. Use a single semicolon-separated command string, which works with both sbtn and the JVM launcher. Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f392591..b624a50 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,11 @@ jobs: java-version: 17 - uses: sbt/setup-sbt@8feba82adc7f01ddcf8165b86f778bdb5b82cebc # v1 # scalafmt は非コンパイルで最速に落ち、scalafix は semanticdb 付きの - # コンパイルを伴うため、その後の compile は追加コストがほぼない + # コンパイルを伴うため、その後の compile は追加コストがほぼない。 + # sbtn (thin client) は argv を 1 本の文字列に連結するため引数付きの + # タスクをクォートで区切れない。`;` 区切りの単一コマンドとして渡す。 - name: Lint and compile - run: sbt scalafmtCheckAll scalafmtSbtCheck "scalafixAll --check" compile + run: sbt "scalafmtCheckAll; scalafmtSbtCheck; scalafixAll --check; compile" build-linux: if: github.event_name == 'push' || github.event_name == 'pull_request'