LoginSignup
2
0

More than 5 years have passed since last update.

Scalaのフォーマッティングツール scalafmt導入

Posted at

scala関西summitで気になったので導入だけやってみた備忘録

ドキュメントはこちら

intellij

scalafmtのプラグインを入れるだけ。
Command(⌘) + Shift(⇧) + Lでファイルのフォーマットを実行。

フォルダで実行するとフォルダ以下、ファイルで実行するとファイル以下を実行してくれます。

sbt 0.13

公式のsbtプラグイン「sbt-scalafmt」があるが、0.13に対応していない模様。
非公式の「neo-sbt-scalafmt」があります。
使ったレポート送ってくれたら公式にする可能性あるよって言ってます。

以下は公式の方の「sbt-scalafmt」を何とか使う方法です。

project/plugin.sbt
libraryDependencies += "com.geirsson" %% "scalafmt-bootstrap" % "0.6.6"
build.sbt
def latestScalafmt = "1.2.0"
commands += Command.args("scalafmt", "Run scalafmt cli.") {
  case (state, args) =>
    val Right(scalafmt) =
      org.scalafmt.bootstrap.ScalafmtBootstrap.fromVersion(latestScalafmt)
    scalafmt.main("--non-interactive" +: args.toArray)
    state
}

以下実行方法です。

ヘルプ

sbt "scalafmt -help"

テスト(フォーマットはしない)

sbt "scalafmt --test"

フォーマット実行

sbt scalafmt

お試しあれ。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0