0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

VSCode + Metals で保存時に Scalafix を実行する

Posted at

VSCode を使って保存時に Scalafix を自動で実行する方法メモ。

Metals が必要なのは当然として、今回はさらに Run on Save という拡張機能を使用します:

VSCode の設定に以下の項目を書き加えます:

{
  # ...
  "runOnSave.commands": [
    {
      "commandBeforeSaving": "metals.scalafix-run",
      "match": ".*\\.(scala|sbt)$",
      "runIn": "vscode"
    }
  ],
  # ...
}

これで、保存時に Scalafix が実行されるようになります。ありがてぇ。

(余談)

なお、Scalafix に scalafix-organize-imports ルールを導入することで、import の最適化 (並び替えなど) も同時におこなえるようになります:

ただし、Scala 3 の場合は不要な import の削除をおこなうことができないため、.scalafix.conf に以下の項目を書き加えておく必要があります:

rules = [OrganizeImports]

OrganizeImports {
  preset = DEFAULT
  removeUnused = false   # Scala 3 の場合は必須
}

おわり。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?