1

Following https://scalameta.org/scalafmt/docs/installation.html I'm trying to reformat my Scala code via command line.

How to execute the scalafmt command ?

Loading sbt from the project can I invoke scalafmt ?

Using below returns error :

sbt:skeleton> scalafmt
[error] Not a valid command: scalafmt (similar: last)
[error] Not a valid project ID: scalafmt
[error] Expected ':'
[error] Not a valid key: scalafmt (similar: scalaHome, scalaArtifacts, scalaInstance)
[error] scalafmt
[error]         ^
sbt:skeleton> my-project/scalafmt
[error] Expected ':'
[error] Not a valid key: scalafmt (similar: scalaHome, scalaArtifacts, scalaInstance)
[error] my-project/scalafmt
[error]                    ^
sbt:skeleton>
Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
blue-sky
  • 51,962
  • 152
  • 427
  • 752
  • Could you check your project/plugins.sbt ? It should include ```addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.2") ``` – Alex Amorales Jul 30 '19 at 14:21

1 Answers1

3

First I would suggest checking your project/plugins.sbt if it includes

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % scalaMetaVersion) 

looks like it can't find scalafmt command.

Second run sbt plugins to check if it's enabled - you should have something like this: org.scalafmt.sbt.ScalafmtPlugin: enabled in skeleton

Alex Amorales
  • 323
  • 3
  • 9