From b0281e853e276506b531a03b4aff36ea1aaea5d1 Mon Sep 17 00:00:00 2001 From: Denis Isaev Date: Mon, 10 Jun 2019 00:32:36 +0300 Subject: [PATCH] update ineffassign --- go.mod | 2 +- go.sum | 8 ++-- .../golangci/ineffassign/ineffassign.go | 48 ++++++++++++------- vendor/modules.txt | 2 +- 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index dec5e3dc..a07c8473 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/golangci/gocyclo v0.0.0-20180528134321-2becd97e67ee github.com/golangci/gofmt v0.0.0-20181105071733-0b8337e80d98 github.com/golangci/gosec v0.0.0-20180901114220-66fb7fc33547 - github.com/golangci/ineffassign v0.0.0-20180808204949-2ee8f2867dde + github.com/golangci/ineffassign v0.0.0-20180808204949-42439a7714cc github.com/golangci/lint-1 v0.0.0-20180610141402-ee948d087217 github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca github.com/golangci/misspell v0.0.0-20180809174111-950f5d19e770 diff --git a/go.sum b/go.sum index d08aa2d4..d65cb97d 100644 --- a/go.sum +++ b/go.sum @@ -60,8 +60,8 @@ github.com/golangci/gofmt v0.0.0-20181105071733-0b8337e80d98 h1:ir6/L2ZOJfFrJlOT github.com/golangci/gofmt v0.0.0-20181105071733-0b8337e80d98/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU= github.com/golangci/gosec v0.0.0-20180901114220-66fb7fc33547 h1:qMomh8bv+kDazm1dSLZ9S3zZ2PJZMHL4ilfBjxFOlmI= github.com/golangci/gosec v0.0.0-20180901114220-66fb7fc33547/go.mod h1:0qUabqiIQgfmlAmulqxyiGkkyF6/tOGSnY2cnPVwrzU= -github.com/golangci/ineffassign v0.0.0-20180808204949-2ee8f2867dde h1:qEGp3ZF1Qw6TkbWKn6GdJ12Ssu/CpJBaBcJ4hrUjrSo= -github.com/golangci/ineffassign v0.0.0-20180808204949-2ee8f2867dde/go.mod h1:e5tpTHCfVze+7EpLEozzMB3eafxo2KT5veNg1k6byQU= +github.com/golangci/ineffassign v0.0.0-20180808204949-42439a7714cc h1:XRFao922N8F3EcIXBSNX8Iywk+GI0dxD/8FicMX2D/c= +github.com/golangci/ineffassign v0.0.0-20180808204949-42439a7714cc/go.mod h1:e5tpTHCfVze+7EpLEozzMB3eafxo2KT5veNg1k6byQU= github.com/golangci/lint-1 v0.0.0-20180610141402-ee948d087217 h1:r7vyX+SN24x6+5AnpnrRn/bdwBb7U+McZqCHOVtXDuk= github.com/golangci/lint-1 v0.0.0-20180610141402-ee948d087217/go.mod h1:66R6K6P6VWk9I95jvqGxkqJxVWGFy9XlDwLwVz1RCFg= github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca h1:kNY3/svz5T29MYHubXix4aDDuE3RWHkPvopM/EDv/MA= @@ -156,14 +156,14 @@ github.com/spf13/viper v1.0.2 h1:Ncr3ZIuJn322w2k1qmzXDnkLAdQMlJqBa9kfAH+irso= github.com/spf13/viper v1.0.2/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/timakin/bodyclose v0.0.0-20190407043127-4a873e97b2bb h1:lI9ufgFfvuqRctP9Ny8lDDLbSWCMxBPletcSqrnyFYM= +github.com/timakin/bodyclose v0.0.0-20190407043127-4a873e97b2bb/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.2.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s= github.com/valyala/quicktemplate v1.1.1 h1:C58y/wN0FMTi2PR0n3onltemfFabany53j7M6SDDB8k= github.com/valyala/quicktemplate v1.1.1/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOVRUAfrukLPuGJ4= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= -github.com/timakin/bodyclose v0.0.0-20190407043127-4a873e97b2bb h1:lI9ufgFfvuqRctP9Ny8lDDLbSWCMxBPletcSqrnyFYM= -github.com/timakin/bodyclose v0.0.0-20190407043127-4a873e97b2bb/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a h1:YX8ljsm6wXlHZO+aRz9Exqr0evNhKRNe5K/gi+zKh4U= golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/vendor/github.com/golangci/ineffassign/ineffassign.go b/vendor/github.com/golangci/ineffassign/ineffassign.go index 3b61b36f..5cda3982 100644 --- a/vendor/github.com/golangci/ineffassign/ineffassign.go +++ b/vendor/github.com/golangci/ineffassign/ineffassign.go @@ -240,7 +240,7 @@ func (bld *builder) Visit(n ast.Node) ast.Visitor { bld.use(id) } // Don't treat explicit initialization to zero as assignment; it is often used as shorthand for a bare declaration. - if n.Tok == token.DEFINE && i < len(n.Rhs) && isZeroLiteral(n.Rhs[i]) { + if n.Tok == token.DEFINE && i < len(n.Rhs) && isZeroInitializer(n.Rhs[i]) { bld.use(id) } else { bld.assign(id) @@ -278,18 +278,17 @@ func (bld *builder) Visit(n ast.Node) ast.Visitor { for _, x := range n.Results { bld.walk(x) } - res := bld.results[len(bld.results)-1] - if res == nil { - break - } - for _, f := range res.List { - for _, id := range f.Names { - if n.Results != nil { - bld.assign(id) + if res := bld.results[len(bld.results)-1]; res != nil { + for _, f := range res.List { + for _, id := range f.Names { + if n.Results != nil { + bld.assign(id) + } + bld.use(id) } - bld.use(id) } } + bld.newBlock() case *ast.SendStmt: bld.maybePanic() return bld @@ -350,15 +349,30 @@ func (bld *builder) Visit(n ast.Node) ast.Visitor { return nil } -func isZeroLiteral(x ast.Expr) bool { - b, ok := x.(*ast.BasicLit) - if !ok { - return false +func isZeroInitializer(x ast.Expr) bool { + // Assume that a call expression of a single argument is a conversion expression. We can't do better without type information. + if c, ok := x.(*ast.CallExpr); ok { + switch c.Fun.(type) { + case *ast.Ident, *ast.SelectorExpr: + default: + return false + } + if len(c.Args) != 1 { + return false + } + x = c.Args[0] } - switch b.Value { - case "0", "0.0", "0.", ".0", `""`: - return true + + switch x := x.(type) { + case *ast.BasicLit: + switch x.Value { + case "0", "0.0", "0.", ".0", `""`: + return true + } + case *ast.Ident: + return x.Name == "false" && x.Obj == nil } + return false } diff --git a/vendor/modules.txt b/vendor/modules.txt index 2a1d9f7f..431c8a76 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -92,7 +92,7 @@ github.com/golangci/gofmt/goimports # github.com/golangci/gosec v0.0.0-20180901114220-66fb7fc33547 github.com/golangci/gosec github.com/golangci/gosec/rules -# github.com/golangci/ineffassign v0.0.0-20180808204949-2ee8f2867dde +# github.com/golangci/ineffassign v0.0.0-20180808204949-42439a7714cc github.com/golangci/ineffassign # github.com/golangci/lint-1 v0.0.0-20180610141402-ee948d087217 github.com/golangci/lint-1