From 734f50d8fcb4df4cf611e774123b835f9fc5666b Mon Sep 17 00:00:00 2001 From: Joseph Richey Date: Sun, 11 Feb 2018 20:39:12 -0800 Subject: [PATCH] golint: Use fork that respects vendor directory Ideally, we would just use "golint ./..." to check all our our source files for lint error. However, this does not work because it will include all packages in the vendor directory. The pull request at: https://github.com/golang/lint/pull/325 fixes this issue, so we will use it until the PR has been merged. --- Gopkg.lock | 7 +- Gopkg.toml | 5 ++ .../github.com/golang/lint/golint/golint.go | 5 +- vendor/github.com/golang/lint/lint.go | 87 ++----------------- 4 files changed, 19 insertions(+), 85 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 2a5953a..d6dd34e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,13 +2,14 @@ [[projects]] - branch = "master" + branch = "lukyth/feature/ignore-vendor" name = "github.com/golang/lint" packages = [ ".", "golint" ] - revision = "e14d9b0f1d332b1420c1ffa32562ad2dc84d645d" + revision = "0dcd199f6e2c9e5fb738b78bfa2170de4c78a25f" + source = "github.com/lukyth/lint" [[projects]] name = "github.com/golang/protobuf" @@ -113,6 +114,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "65c9e40abcc4d3679513c43ba962f87115e94ced6497ac13e9ef5685815c7da8" + inputs-digest = "13bc740ba83539fecd6dd4b7d026fd221077369cb6b170e83d288383d0fde474" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 29da3c7..8336862 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -7,6 +7,11 @@ required = [ "github.com/wadey/gocovmerge" ] +[[constraint]] + name = "github.com/golang/lint" + branch = "lukyth/feature/ignore-vendor" + source = "github.com/lukyth/lint" + # Source dependancies [[constraint]] name = "github.com/golang/protobuf" diff --git a/vendor/github.com/golang/lint/golint/golint.go b/vendor/github.com/golang/lint/golint/golint.go index d8360ad..0088274 100644 --- a/vendor/github.com/golang/lint/golint/golint.go +++ b/vendor/github.com/golang/lint/golint/golint.go @@ -48,9 +48,12 @@ func main() { var dirsRun, filesRun, pkgsRun int var args []string for _, arg := range flag.Args() { - if strings.HasSuffix(arg, "/...") && isDir(arg[:len(arg)-len("/...")]) { + if trimmedArg := strings.TrimSuffix(arg, "/..."); trimmedArg != arg && isDir(trimmedArg) { dirsRun = 1 for _, dirname := range allPackagesInFS(arg) { + if strings.Contains(dirname[len(trimmedArg):], "/vendor/") { + continue + } args = append(args, dirname) } } else if isDir(arg) { diff --git a/vendor/github.com/golang/lint/lint.go b/vendor/github.com/golang/lint/lint.go index 8bb1faa..fb47da0 100644 --- a/vendor/github.com/golang/lint/lint.go +++ b/vendor/github.com/golang/lint/lint.go @@ -199,7 +199,6 @@ func (f *file) lint() { f.lintNames() f.lintVarDecls() f.lintElses() - f.lintIfError() f.lintRanges() f.lintErrorf() f.lintErrors() @@ -1238,7 +1237,7 @@ func (f *file) lintReceiverNames() { name := names[0].Name const ref = styleGuideBase + "#receiver-names" if name == "_" { - f.errorf(n, 1, link(ref), category("naming"), `receiver name should not be an underscore, omit the name if it is unused`) + f.errorf(n, 1, link(ref), category("naming"), `receiver name should not be an underscore`) return true } if name == "this" || name == "self" { @@ -1467,85 +1466,6 @@ func (f *file) lintContextArgs() { }) } -// containsComments returns whether the interval [start, end) contains any -// comments without "// MATCH " prefix. -func (f *file) containsComments(start, end token.Pos) bool { - for _, cgroup := range f.f.Comments { - comments := cgroup.List - if comments[0].Slash >= end { - // All comments starting with this group are after end pos. - return false - } - if comments[len(comments)-1].Slash < start { - // Comments group ends before start pos. - continue - } - for _, c := range comments { - if start <= c.Slash && c.Slash < end && !strings.HasPrefix(c.Text, "// MATCH ") { - return true - } - } - } - return false -} - -func (f *file) lintIfError() { - f.walk(func(node ast.Node) bool { - switch v := node.(type) { - case *ast.BlockStmt: - for i := 0; i < len(v.List)-1; i++ { - // if var := whatever; var != nil { return var } - s, ok := v.List[i].(*ast.IfStmt) - if !ok || s.Body == nil || len(s.Body.List) != 1 || s.Else != nil { - continue - } - assign, ok := s.Init.(*ast.AssignStmt) - if !ok || len(assign.Lhs) != 1 || !(assign.Tok == token.DEFINE || assign.Tok == token.ASSIGN) { - continue - } - id, ok := assign.Lhs[0].(*ast.Ident) - if !ok { - continue - } - expr, ok := s.Cond.(*ast.BinaryExpr) - if !ok || expr.Op != token.NEQ { - continue - } - if lhs, ok := expr.X.(*ast.Ident); !ok || lhs.Name != id.Name { - continue - } - if rhs, ok := expr.Y.(*ast.Ident); !ok || rhs.Name != "nil" { - continue - } - r, ok := s.Body.List[0].(*ast.ReturnStmt) - if !ok || len(r.Results) != 1 { - continue - } - if r, ok := r.Results[0].(*ast.Ident); !ok || r.Name != id.Name { - continue - } - - // return nil - r, ok = v.List[i+1].(*ast.ReturnStmt) - if !ok || len(r.Results) != 1 { - continue - } - if r, ok := r.Results[0].(*ast.Ident); !ok || r.Name != "nil" { - continue - } - - // check if there are any comments explaining the construct, don't emit an error if there are some. - if f.containsComments(s.Pos(), r.Pos()) { - continue - } - - f.errorf(v.List[i], 0.9, "redundant if ...; err != nil check, just return error instead.") - } - } - return true - }) -} - // receiverType returns the named type of the method receiver, sans "*", // or "invalid-type" if fn.Recv is ill formed. func receiverType(fn *ast.FuncDecl) string { @@ -1606,6 +1526,11 @@ func isPkgDot(expr ast.Expr, pkg, name string) bool { return ok && isIdent(sel.X, pkg) && isIdent(sel.Sel, name) } +func isZero(expr ast.Expr) bool { + lit, ok := expr.(*ast.BasicLit) + return ok && lit.Kind == token.INT && lit.Value == "0" +} + func isOne(expr ast.Expr) bool { lit, ok := expr.(*ast.BasicLit) return ok && lit.Kind == token.INT && lit.Value == "1" -- 2.39.5