https://zenn.dev/sanpo_shiho/books/61bc1e1a30bf27/viewer/642fe9#funlen

[ちょっとその前に]非推奨のlinterって?


	 a
	  a

	var b interface{}
	bi := b.(int) // ERROR "type assertion must be checked"
	fmt.Println(bi)
}

Tool for detection of long functions

関数bodyの行数が長すぎる関数やstatementが多すぎる関数を報告します。

func TooManyLines() { // ERROR `Function 'TooManyLines' is too long \\(22 > 20\\)`
	t := struct {
		A string
		B string
		C string
		D string
		E string
		F string
		G string
		H string
		I string
	}{
		`a`,
		`b`,
		`c`,
		`d`,
		`e`,
		`f`,
		`g`,
		`h`,
		`i`,
	}
	_ = t
}

func TooManyStatements() { // ERROR `Function 'TooManyStatements' has too many statements \\(11 > 10\\)`
	a := 1
	b := a
	c := b
	d := c
	e := d
	f := e
	g := f
	h := g
	i := h
	j := i
	_ = j
}

gci

Gci control golang package import order and make it always deterministic.

goimportsみたいなやつです。autofixに対応しており、gciがちゃんとかけられているかどうかの確認もすることができます。 個人的には、結果が一意に決まるのでgoimportsではなく、gciを使うことが多いです。 例は公式のREADMEを見るのが分かりやすいです

package main
import (
  "golang.org/x/tools"

  "fmt"

  "github.com/daixiang0/gci"
)

package main
import (
  "fmt"

  "golang.org/x/tools"

  "github.com/daixiang0/gci"
)

gochecknoglobals

check that no global variables exist This analyzer checks for global variables and errors on any found. A global variable is a variable declared in package scope and that can be read and written to by any function within the package. Global variables can cause side effects which are difficult to keep track of. A code in one function may change the variables state while another unrelated chunk of code may be effected by it.

グローバル変数を報告します。しかし以下の例にもあるように特定の表現に関しては報告を行いません。 READMEを見ると具体的にどのような表現には報告を行わないか記載があります

var noGlobalsVar int // ERROR "noGlobalsVar is a global variable"
var ErrSomeType = errors.New("test that global erorrs aren't warned")

var (
	OnlyDigites = regexp.MustCompile(`^\\d+$`)
	BadNamedErr = errors.New("this is bad") // ERROR "BadNamedErr is a global variable"
)

gochecknoinits