LoginSignup
0
0

More than 1 year has passed since last update.

Go Linter - Staticcheckを使ってみる

Last updated at Posted at 2021-12-06

この記事はWanoグループ Advent Calendar 2021 5日目の記事になります

Goには様々なlinterが存在しています。
元々Go公式のlinterはGolintですが、色々否定的な意見は少なく、今年ついにアーカイブされました。

代わりに使用するlinterとして GoやGoogleがサポートするStaticcheckが使ってみようかなと思います。

公式page (前身はGoSimple)

Install

go 1.17なら、以下のcmdで実行 (過去versionの場合、go installじゃなくgo get使うかも)

$ go install honnef.co/go/tools/cmd/staticcheck@latest

実行

早速使ってみる

$ staticcheck ./...

...(略)
xxxxxxxx.go:108:7: receiver name should be a reflection of its identity; don't use generic names such as "this" or "self" (ST1006)
xxxxxx:21:10: should use fmt.Errorf(...) instead of errors.New(fmt.Sprintf(...)) (S1028)
xxxxxx:21:21: the argument is already a string, there's no need to use fmt.Sprintf (S1025)
...(略)

後ろ付いてるの番号はCheck番号、説明一覧はここで

staticcheck.confを追加すれば、特定の番号だけ検知も可能です

staticcheck.conf
checks = ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023"]

他の細かい設定したいなら

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