Open10

golangci-lintで検知されるコード

Daisuke OkuDaisuke Oku

gomnd

var errCheck = errors.New("error")

func check() (int, error) {
  for i := 0; i < 10; i++ {
    if i == 5 { // gomod
      return i, nil
    }
  }

  return 0, errCheck
}
Daisuke OkuDaisuke Oku

forbidigo

var errCheck = errors.New("error")

func check() (int, error) {
  for i := 0; i < 10; i++ {
    fmt.Println(i) // forbidigo
  }

return 0, errCheck
}
Daisuke OkuDaisuke Oku

errorlint

func main() {
  if err := valid(); err != nil {
    if err == errValid { // errorlint
      log.Println("errValid")
    }
  }
}
Daisuke OkuDaisuke Oku

gosimple

func tmp(ss []string) {
  if ss != nil { //gosimple
    for _, s := range ss {
      log.Println(s)
    }
  }
}