Denis Isaev 87aae77943 Update gocritic
Fix #324, relates #314

1. Update gocritic to the latest version
2. Use proper gocritic checkers repo, old repo was archived
3. Get enabled by default gocritic checks in sync with go-critic: don't
enable performance, experimental and opinionated checks by default
4. Support of `enabled-tags` options for gocritic
5. Enable almost all gocritic checks for the project
6. Make rich debugging for gocritic
7. Meticulously validate gocritic checks config
2019-01-09 09:51:48 +03:00

50 lines
1.1 KiB
Go

package checkers
import (
"go/ast"
"github.com/go-lintpack/lintpack"
"github.com/go-lintpack/lintpack/astwalk"
)
func init() {
var info lintpack.CheckerInfo
info.Name = "captLocal"
info.Tags = []string{"style"}
info.Params = lintpack.CheckerParams{
"paramsOnly": {
Value: true,
Usage: "whether to restrict checker to params only",
},
}
info.Summary = "Detects capitalized names for local variables"
info.Before = `func f(IN int, OUT *int) (ERR error) {}`
info.After = `func f(in int, out *int) (err error) {}`
collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker {
c := &captLocalChecker{ctx: ctx}
c.paramsOnly = info.Params.Bool("paramsOnly")
return astwalk.WalkerForLocalDef(c, ctx.TypesInfo)
})
}
type captLocalChecker struct {
astwalk.WalkHandler
ctx *lintpack.CheckerContext
paramsOnly bool
}
func (c *captLocalChecker) VisitLocalDef(def astwalk.Name, _ ast.Expr) {
if c.paramsOnly && def.Kind != astwalk.NameParam {
return
}
if ast.IsExported(def.ID.Name) {
c.warn(def.ID)
}
}
func (c *captLocalChecker) warn(id ast.Node) {
c.ctx.Warn(id, "`%s' should not be capitalized", id)
}