Add scalafmt and scalafix checks to CI - #8
Merged
Merged
Conversation
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
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.sbtにsemanticdbEnabled(RemoveUnusedが必要とする SemanticDB 出力)、scalafmtOnCompile(ローカルでの自動整形)、-Wunused:all(RemoveUnusedの入力となる警告)を追加.scalafmt.confにalign.tokensを追加。build.sbtとplugins.sbtの:=/%%の縦揃えを維持するため.github/workflows/ci.ymlのcompileジョブで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が成功するscalafixAll --checkが失敗する(RemoveUnusedが機能していることの確認)Main.scalaは無変更。差分は設定ファイルと CI のみ./build.shでネイティブリンクが通り、./comport --showが動作する🤖 Generated with Claude Code