Search code examples
scalasbtscalafmt

scalafmt to check only modified files


sbt scalafmtCheckAll checks the format of all files in the repo, how to check only the format of the modified files.

And whats the difference between sbt scalafmtCheckAll and sbt scalafmtCheck?


Solution

  • According to the documentation, you could use the scalafmtFilter: diff-dirty feature.

    [since v2.4.5] scalafmtFilter: String (default ""): optionally limits the set of files considered for formatting:

    • diff-dirty: only the files modified in the git working tree (git status)
    • diff-ref=: only the tracked files modified since (git diff)
    • [since v2.4.6] none: no restrictions
    • otherwise if project.git = true (.scalafmt.conf): only files tracked by git (git ls-tree)
    • otherwise, no restrictions

    See https://scalameta.org/scalafmt/docs/installation.html#task-keys