Skip to content

Add scalafmt and scalafix checks to CI - #8

Merged
windymelt merged 3 commits into
mainfrom
ci-scalafmt-scalafix
Aug 10, 2026
Merged

windymelt merged 3 commits into
mainfrom
ci-scalafmt-scalafix

Conversation

@windymelt

@windymelt windymelt commented Aug 10, 2026

Copy link
Copy Markdown
Owner

概要

CI に scalafmt と scalafix のチェックを追加する。フォーマット崩れと未使用 import / 未使用メンバーを PR 段階で検出する。

変更内容

  • project/plugins.sbt に sbt-scalafmt 2.6.2 と sbt-scalafix 0.14.7 を追加(いずれも sbt 2 向けアーティファクト _sbt2_3 が公開済み)
  • .scalafix.conf を新規作成。OrganizeImports / RemoveUnused / RedundantSyntax / DisableSyntax を有効化。未使用 import の削除は RemoveUnused に任せ、OrganizeImports.removeUnused = false として二重適用を避けている
  • build.sbtsemanticdbEnabledRemoveUnused が必要とする SemanticDB 出力)、scalafmtOnCompile(ローカルでの自動整形)、-Wunused:allRemoveUnused の入力となる警告)を追加
  • .scalafmt.confalign.tokens を追加。build.sbtplugins.sbt:= / %% の縦揃えを維持するため
  • .github/workflows/ci.ymlcompile ジョブで sbt scalafmtCheckAll scalafmtSbtCheck "scalafixAll --check" compile を実行

build-linux / build-macos は既に needs: compile なので、lint 失敗時はバイナリビルドも走らない。ジョブおよび action の追加はないため SHA ピン留めの新規作業は発生していない。

設計上の判断

align.tokens の代わりに align.preset = more でも build.sbt の縦揃えは維持できるが、そちらは Scala ソース側の val= も揃えてしまい Main.scala に不要な差分が出るため採用しなかった。

lint を独立ジョブにせず既存の compile ジョブに同居させている。scalafixAll が SemanticDB 付きのコンパイルを行うため、後続の compile の追加コストがほぼないという理由。

動作確認

ローカル(Scala 3.8.2 / Scala Native 0.5.12 / sbt 2.0.2)で確認済み。

  • sbt scalafmtCheckAll scalafmtSbtCheck "scalafixAll --check" compile が成功する
  • 未使用 import を意図的に追加すると scalafixAll --check が失敗する(RemoveUnused が機能していることの確認)
  • Main.scala は無変更。差分は設定ファイルと CI のみ
  • ./build.sh でネイティブリンクが通り、./comport --show が動作する

🤖 Generated with Claude Code

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) <noreply@anthropic.com>
@windymelt
windymelt changed the base branch from migrate-to-sbt2 to main August 10, 2026 10:35
windymelt and others added 2 commits August 10, 2026 19:39
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) <noreply@anthropic.com>
@windymelt
windymelt merged commit 87ede70 into main Aug 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant