LoginSignup
7
6

More than 3 years have passed since last update.

IntelliJとgometalinterで逐一Lintを実行する

Last updated at Posted at 2018-07-12

IntelliJ IDEAをgometalinterと連携させる方法を探したところ External Toolを使ずとも File Watchersgometalinterに対応しているようなので手順を書き残しておきます。

GoLandでも同様。

利用バージョン

  • IntelliJ IDEA: 2018.1.5 (Ultimate Edition)
  • Plugin
    • GoVersion: 181.5087.39.204
    • File Watchers: 181.4668.7

設定方法

※ Goプラグインはインストール済み

1. Preferences > Plugins > Browse repositories を開き 「File Watchers」 をインストールする

2. Preferences > Tools > File Watchers を開き、プラスボタンをクリックし、NewWatherとして gometalinter を作成する。チェックを入れて OK で保存する

  • gometalinterは必要に応じて go get -u github.com/alecthomas/gometalinter する

Preferences.png

3. gometalinter --install --updateで各種lintやフォーマッタ等をまとめてインストールする

```bash
$ gometalinter --install --update

Installing:
  deadcode
  dupl
  errcheck
  gas
  goconst
  gocyclo
  goimports
  golint
  gosimple
  gotype
  gotypex
  ineffassign
  interfacer
  lll
  maligned
  megacheck
  misspell
  nakedret
  safesql
  staticcheck
  structcheck
  unconvert
  unparam
  unused
  varcheck
  vet
```

4. File Watchersのスコープ(デフォルトはProject Files)に変更があれば gometalintergolint等を走らせます。

5. チェックする項目が多すぎるので、gometalinter のArguments:を変更して実行するlinter, formatterを絞る

私は以下のようにしています。
Argments: --exclude="\bexported \w+ (\S*['.]*)([a-zA-Z'.*]*) should have comment or be unexported\b" --disable-all --enable=golint --enable=vet $FileDir$

Edit_Watcher.png

公式記事は正義

7
6
1

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