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?


  • sbt-scalafmt provides a scalafmtOnly task for this. It's documented at , where we see:

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

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