scalasbtscalafmt

How can I run `scalafmt` on a specific file?


I know if I do sbt scalafmt it will run it on the entire project. How can I do this for a specific file?


Solution

  • sbt-scalafmt provides a scalafmtOnly task for this. It's documented at https://scalameta.org/scalafmt/docs/installation.html#task-keys , where we see:

    scalafmtOnly <file>...: Format specified files listed

    (You could also, outside of sbt, use the scalafmt command, which is installable via Coursier.)