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

566 views Asked by At

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

1

There are 1 answers

0
Seth Tisue On BEST ANSWER

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.

Scalafmt can be now be launched via scala-cli, so you can also:

scala-cli format <file>...