LoginSignup
9
7

More than 3 years have passed since last update.

Scalaのコードフォーマットの簡易設定メモ

Last updated at Posted at 2019-02-03

InteliJ IDEAとsbtの設定について記載しています。自分用メモです。

参考
https://scalameta.org/scalafmt/

InteliJ IDEA

scalafmtのインストール

  1. openPreferences > Plugins
  2. open Browse repositories
  3. search for scalafmt
  4. click "Install"
  5. restart IntelliJ

img1-1.png

.scalafmtの作成

プロジェクト直下に.scalafmt.confを配置。
以下は一例。

詳細な設定は以下参照。
https://scalameta.org/scalafmt/docs/configuration.html

scalafmt.conf
includeCurlyBraceInSelectChains = false
newlines.penalizeSingleSelectMultiArgList = false

保存されたらフォーマットが実行されるようにする

  • 現在のプロジェクトに対して実行されるようにする場合 (recommended):
    • Preferences > Tools > Scalafmt
  • 新しくつくるプロジェクトすべてに対して実行されるようにする場合:
    • File > Other settings > Preferences for new projects > Tools > Scalafmt

img2-1.png

sbt

project/plugin.sbtの設定追加

project/plugin.sbt
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.1")

.scalafmtの設定

プロジェクト直下に.scalafmt.confを配置

scalafmt.conf
version=2.0.0-RC8
includeCurlyBraceInSelectChains = false
newlines.penalizeSingleSelectMultiArgList = false

フォーマットの実行

sbt clean scalafmtSbt scalafmtAll

フォーマットの検証

sbt clean scalafmtSbtCheck scalafmtCheckAll
9
7
2

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
9
7