diff --git a/.golangci.yml b/.golangci.yml index 85b508e6c6c0..006a5637b07a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -38,7 +38,6 @@ linters-settings: - experimental disabled-checks: - wrapperFunc - - dupImport # https://github.com/go-critic/go-critic/issues/845 linters: enable-all: true diff --git a/README.md b/README.md index e7f4be6bbc51..ec9f4864eaa8 100644 --- a/README.md +++ b/README.md @@ -850,7 +850,6 @@ linters-settings: - experimental disabled-checks: - wrapperFunc - - dupImport # https://github.com/go-critic/go-critic/issues/845 linters: enable-all: true diff --git a/go.mod b/go.mod index 1c452be00629..1c9b223e29f2 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,10 @@ require ( github.com/OpenPeeDeeP/depguard v0.0.0-20180806142446-a69c782687b2 github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect github.com/fatih/color v1.6.0 - github.com/go-critic/go-critic v0.0.0-20181204210945-1df300866540 + github.com/go-critic/go-critic v0.3.4 github.com/go-lintpack/lintpack v0.5.2 github.com/go-ole/go-ole v1.2.1 // indirect + github.com/go-toolsmith/astfmt v1.0.0 // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/golang/mock v1.0.0 github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 @@ -19,7 +20,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-42439a7714cc + github.com/golangci/ineffassign v0.0.0-20180808204949-2ee8f2867dde 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 58ababec8916..b43345699558 100644 --- a/go.sum +++ b/go.sum @@ -10,16 +10,17 @@ github.com/fatih/color v1.6.0 h1:66qjqZk8kalYAvDRtM1AdAJQI0tj4Wrue3Eq3B3pmFU= github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/go-critic/go-critic v0.0.0-20181204210945-1df300866540 h1:7CU1IXBpPvxpQ/NqJrpuMXMHAw+FB2vfqtRF8tgW9fw= -github.com/go-critic/go-critic v0.0.0-20181204210945-1df300866540/go.mod h1:+sE8vrLDS2M0pZkBk0wy6+nLdKexVDrl/jBqQOTDThA= +github.com/go-critic/go-critic v0.3.4 h1:FYaiaLjX0Nqei80KPhm4CyFQUBbmJwSrHxQ73taaGBc= +github.com/go-critic/go-critic v0.3.4/go.mod h1:AHR42Lk/E/aOznsrYdMYeIQS5RH10HZHSqP+rD6AJrc= +github.com/go-lintpack/lintpack v0.5.1/go.mod h1:NwZuYi2nUHho8XEIZ6SIxihrnPoqBTDqfpXvXAN0sXM= github.com/go-lintpack/lintpack v0.5.2 h1:DI5mA3+eKdWeJ40nU4d6Wc26qmdG8RCi/btYq0TuRN0= github.com/go-lintpack/lintpack v0.5.2/go.mod h1:NwZuYi2nUHho8XEIZ6SIxihrnPoqBTDqfpXvXAN0sXM= github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= -github.com/go-toolsmith/astcast v1.0.0 h1:JojxlmI6STnFVG9yOImLeGREv8W2ocNUM+iOhR6jE7g= -github.com/go-toolsmith/astcast v1.0.0/go.mod h1:mt2OdQTeAQcY4DQgPSArJjHCcOwlX+Wl/kwN+LbLGQ4= -github.com/go-toolsmith/astcopy v1.0.0 h1:OMgl1b1MEpjFQ1m5ztEO06rz5CUd3oBv9RF7+DyvdG8= -github.com/go-toolsmith/astcopy v1.0.0/go.mod h1:vrgyG+5Bxrnz4MZWPF+pI4R8h3qKRjjyvV/DSez4WVQ= +github.com/go-toolsmith/astcast v0.0.0-20181028201508-b7a89ed70af1 h1:h+1eMw+tZAlgTVclcVN0/rdPaBI/RUzG0peblT6df+Q= +github.com/go-toolsmith/astcast v0.0.0-20181028201508-b7a89ed70af1/go.mod h1:TEo3Ghaj7PsZawQHxT/oBvo4HK/sl1RcuUHDKTTju+o= +github.com/go-toolsmith/astcopy v0.0.0-20180903214859-79b422d080c4 h1:wVs9OMjICHbAryp9hcIuWqUOi+NqEbUSZy9zMe3W//I= +github.com/go-toolsmith/astcopy v0.0.0-20180903214859-79b422d080c4/go.mod h1:c9CPdq2AzM8oPomdlPniEfPAC6g1s7NqZzODt8y6ib8= github.com/go-toolsmith/astequal v0.0.0-20180903214952-dcb477bfacd6 h1:aTBUNRTatDDU24gbOEKEoLiDwxtc98ga6K/iMTm6fvs= github.com/go-toolsmith/astequal v0.0.0-20180903214952-dcb477bfacd6/go.mod h1:H+xSiq0+LtiDC11+h1G32h7Of5O3CYFJ99GVbS5lDKY= github.com/go-toolsmith/astequal v1.0.0 h1:4zxD8j3JRFNyLN46lodQuqz3xdKSrur7U/sr0SDS/gQ= @@ -28,19 +29,15 @@ github.com/go-toolsmith/astfmt v0.0.0-20180903215011-8f8ee99c3086 h1:EIMuvbE9fbt github.com/go-toolsmith/astfmt v0.0.0-20180903215011-8f8ee99c3086/go.mod h1:mP93XdblcopXwlyN4X4uodxXQhldPGZbcEJIimQHrkg= github.com/go-toolsmith/astfmt v1.0.0 h1:A0vDDXt+vsvLEdbMFJAUBI/uTbRw1ffOPnxsILnFL6k= github.com/go-toolsmith/astfmt v1.0.0/go.mod h1:cnWmsOAuq4jJY6Ct5YWlVLmcmLMn1JUPuQIHCY7CJDw= -github.com/go-toolsmith/astinfo v0.0.0-20180906194353-9809ff7efb21/go.mod h1:dDStQCHtmZpYOmjRP/8gHHnCCch3Zz3oEgCdZVdtweU= github.com/go-toolsmith/astp v0.0.0-20180903215135-0af7e3c24f30 h1:zRJPftZJNLPDiOtvYbFRwjSbaJAcVOf80TeEmWGe2kQ= github.com/go-toolsmith/astp v0.0.0-20180903215135-0af7e3c24f30/go.mod h1:SV2ur98SGypH1UjcPpCatrV5hPazG6+IfNHbkDXBRrk= -github.com/go-toolsmith/astp v1.0.0 h1:alXE75TXgcmupDsMK1fRAy0YUzLzqPVvBKoyWV+KPXg= -github.com/go-toolsmith/astp v1.0.0/go.mod h1:RSyrtpVlfTFGDYRbrjyWP1pYu//tSFcvdYrA8meBmLI= github.com/go-toolsmith/pkgload v0.0.0-20181119091011-e9e65178eee8 h1:vVouagbdmqTVlCIAxpyYsNNTbkKZ3V66VpKOLU/s6W4= github.com/go-toolsmith/pkgload v0.0.0-20181119091011-e9e65178eee8/go.mod h1:WoMrjiy4zvdS+Bg6z9jZH82QXwkcgCBX6nOfnmdaHks= -github.com/go-toolsmith/pkgload v1.0.0 h1:4DFWWMXVfbcN5So1sBNW9+yeiMqLFGl1wFLTL5R0Tgg= -github.com/go-toolsmith/pkgload v1.0.0/go.mod h1:5eFArkbO80v7Z0kdngIxsRXRMTaX4Ilcwuh3clNrQJc= +github.com/go-toolsmith/strparse v0.0.0-20180903215201-830b6daa1241/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8= github.com/go-toolsmith/strparse v1.0.0 h1:Vcw78DnpCAKlM20kSbAyO4mPfJn/lyYA4BJUDxe2Jb4= github.com/go-toolsmith/strparse v1.0.0/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8= -github.com/go-toolsmith/typep v1.0.0 h1:zKymWyA1TRYvqYrYDrfEMZULyrhcnGY3x7LDKU2XQaA= -github.com/go-toolsmith/typep v1.0.0/go.mod h1:JSQCQMUPdRlMZFswiq3TGpNp1GMktqkR2Ns5AIQkATU= +github.com/go-toolsmith/typep v0.0.0-20181030061450-d63dc7650676 h1:6Qrsp0+25KEkaS2bB26UE0giFgRrIc8mYXboDL5OVMA= +github.com/go-toolsmith/typep v0.0.0-20181030061450-d63dc7650676/go.mod h1:JSQCQMUPdRlMZFswiq3TGpNp1GMktqkR2Ns5AIQkATU= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo= @@ -67,8 +64,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-42439a7714cc h1:XRFao922N8F3EcIXBSNX8Iywk+GI0dxD/8FicMX2D/c= -github.com/golangci/ineffassign v0.0.0-20180808204949-42439a7714cc/go.mod h1:e5tpTHCfVze+7EpLEozzMB3eafxo2KT5veNg1k6byQU= +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/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= @@ -110,7 +107,6 @@ github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRU github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936 h1:kw1v0NlnN+GZcU8Ma8CLF2Zzgjfx95gs3/GN3vYAPpo= @@ -133,7 +129,6 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI= github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= github.com/shirou/gopsutil v0.0.0-20180427012116-c95755e4bcd7 h1:80VN+vGkqM773Br/uNNTSheo3KatTgV8IpjIKjvVLng= @@ -196,7 +191,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20170915040203-e531a2a1c15f/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181117154741-2ddaf7f79a09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190110163146-51295c7ec13a/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181205014116-22934f0fdb62/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190121143147-24cd39ecf745/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190311215038-5c2858a9cfe5/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= diff --git a/vendor/github.com/go-critic/go-critic/LICENSE b/vendor/github.com/go-critic/go-critic/LICENSE index b944b4bbdbec..f677137d1d85 100644 --- a/vendor/github.com/go-critic/go-critic/LICENSE +++ b/vendor/github.com/go-critic/go-critic/LICENSE @@ -1,7 +1,7 @@ MIT License -Copyright (c) 2018-2019 Alekseev Artem -Copyright (c) 2018-2019 Ravil Bikbulatov +Copyright (c) 2018 Alekseev Artem +Copyright (c) 2018 Ravil Bikbulatov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/vendor/github.com/go-critic/go-critic/checkers/appendCombine_checker.go b/vendor/github.com/go-critic/go-critic/checkers/appendCombine_checker.go index 63f5d9fea4e6..a81fdab6e6d4 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/appendCombine_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/appendCombine_checker.go @@ -4,9 +4,9 @@ import ( "go/ast" "go/token" + "github.com/go-critic/go-critic/checkers/internal/lintutil" "github.com/go-lintpack/lintpack" "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astcast" "github.com/go-toolsmith/astequal" ) @@ -73,7 +73,7 @@ func (c *appendCombineChecker) matchAppend(stmt ast.Stmt, slice ast.Expr) *ast.C // xs are 0-N append arguments, but not variadic argument, // because it makes append combining impossible. - assign := astcast.ToAssignStmt(stmt) + assign := lintutil.AsAssignStmt(stmt) if len(assign.Lhs) != 1 || len(assign.Rhs) != 1 { return nil } diff --git a/vendor/github.com/go-critic/go-critic/checkers/argOrder_checker.go b/vendor/github.com/go-critic/go-critic/checkers/argOrder_checker.go deleted file mode 100644 index 85a6f7c664ea..000000000000 --- a/vendor/github.com/go-critic/go-critic/checkers/argOrder_checker.go +++ /dev/null @@ -1,98 +0,0 @@ -package checkers - -import ( - "go/ast" - "go/types" - - "github.com/go-lintpack/lintpack" - "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astcast" - "github.com/go-toolsmith/astcopy" - "github.com/go-toolsmith/astp" - "github.com/go-toolsmith/typep" -) - -func init() { - var info lintpack.CheckerInfo - info.Name = "argOrder" - info.Tags = []string{"diagnostic", "experimental"} - info.Summary = "Detects suspicious arguments order" - info.Before = `strings.HasPrefix("#", userpass)` - info.After = `strings.HasPrefix(userpass, "#")` - - collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - return astwalk.WalkerForExpr(&argOrderChecker{ctx: ctx}) - }) -} - -type argOrderChecker struct { - astwalk.WalkHandler - ctx *lintpack.CheckerContext -} - -func (c *argOrderChecker) VisitExpr(expr ast.Expr) { - call := astcast.ToCallExpr(expr) - - // For now only handle functions of 2 args. - // TODO(Quasilyte): generalize the algorithm and add more patterns. - if len(call.Args) != 2 { - return - } - - calledExpr := astcast.ToSelectorExpr(call.Fun) - obj, ok := c.ctx.TypesInfo.ObjectOf(astcast.ToIdent(calledExpr.X)).(*types.PkgName) - if !ok || !isStdlibPkg(obj.Imported()) { - return - } - - x := call.Args[0] - y := call.Args[1] - switch calledExpr.Sel.Name { - case "HasPrefix", "HasSuffix", "Contains", "TrimPrefix", "TrimSuffix", "Split": - if obj.Name() != "bytes" && obj.Name() != "strings" { - return - } - if c.isConstLiteral(x) && !c.isConstLiteral(y) { - c.warn(call) - } - } -} - -func (c *argOrderChecker) isConstLiteral(x ast.Expr) bool { - if c.ctx.TypesInfo.Types[x].Value != nil { - return true - } - - // Also permit byte slices. - switch x := x.(type) { - case *ast.CallExpr: - // Handle `[]byte("abc")` as well. - if len(x.Args) != 1 || !astp.IsBasicLit(x.Args[0]) { - return false - } - typ, ok := c.ctx.TypesInfo.TypeOf(x.Fun).(*types.Slice) - return ok && typep.HasUint8Kind(typ.Elem()) - - case *ast.CompositeLit: - // Check if it's a const byte slice. - typ, ok := c.ctx.TypesInfo.TypeOf(x).(*types.Slice) - if !ok || !typep.HasUint8Kind(typ.Elem()) { - return false - } - for _, elt := range x.Elts { - if !astp.IsBasicLit(elt) { - return false - } - } - return true - - default: - return false - } -} - -func (c *argOrderChecker) warn(call *ast.CallExpr) { - fixed := astcopy.CallExpr(call) - fixed.Args[0], fixed.Args[1] = fixed.Args[1], fixed.Args[0] - c.ctx.Warn(call, "probably meant `%s`", fixed) -} diff --git a/vendor/github.com/go-critic/go-critic/checkers/assignOp_checker.go b/vendor/github.com/go-critic/go-critic/checkers/assignOp_checker.go index eb34286636c8..e4e82c98b1a3 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/assignOp_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/assignOp_checker.go @@ -74,29 +74,8 @@ func (c *assignOpChecker) VisitStmt(stmt ast.Stmt) { } func (c *assignOpChecker) warn(cause *ast.AssignStmt, op token.Token, rhs ast.Expr) { - suggestion := c.simplify(cause, op, rhs) - c.ctx.Warn(cause, "replace `%s` with `%s`", cause, suggestion) -} - -func (c *assignOpChecker) simplify(cause *ast.AssignStmt, op token.Token, rhs ast.Expr) ast.Stmt { - if lit, ok := rhs.(*ast.BasicLit); ok && lit.Kind == token.INT && lit.Value == "1" { - switch op { - case token.ADD_ASSIGN: - return &ast.IncDecStmt{ - X: cause.Lhs[0], - TokPos: cause.TokPos, - Tok: token.INC, - } - case token.SUB_ASSIGN: - return &ast.IncDecStmt{ - X: cause.Lhs[0], - TokPos: cause.TokPos, - Tok: token.DEC, - } - } - } suggestion := astcopy.AssignStmt(cause) suggestion.Tok = op suggestion.Rhs[0] = rhs - return suggestion + c.ctx.Warn(cause, "replace `%s` with `%s`", cause, suggestion) } diff --git a/vendor/github.com/go-critic/go-critic/checkers/badCall_checker.go b/vendor/github.com/go-critic/go-critic/checkers/badCall_checker.go deleted file mode 100644 index 150cc690426c..000000000000 --- a/vendor/github.com/go-critic/go-critic/checkers/badCall_checker.go +++ /dev/null @@ -1,63 +0,0 @@ -package checkers - -import ( - "go/ast" - - "github.com/go-lintpack/lintpack" - "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astcast" - "github.com/go-toolsmith/astcopy" -) - -func init() { - var info lintpack.CheckerInfo - info.Name = "badCall" - info.Tags = []string{"diagnostic", "experimental"} - info.Summary = "Detects suspicious function calls" - info.Before = `strings.Replace(s, from, to, 0)` - info.After = `strings.Replace(s, from, to, -1)` - - collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - return astwalk.WalkerForExpr(&badCallChecker{ctx: ctx}) - }) -} - -type badCallChecker struct { - astwalk.WalkHandler - ctx *lintpack.CheckerContext -} - -func (c *badCallChecker) VisitExpr(expr ast.Expr) { - call := astcast.ToCallExpr(expr) - if len(call.Args) == 0 { - return - } - - // TODO(quasilyte): handle methods. - - switch qualifiedName(call.Fun) { - case "strings.Replace", "bytes.Replace": - if n := astcast.ToBasicLit(call.Args[3]); n.Value == "0" { - c.warnBadArg(n, "-1") - } - case "strings.SplitN", "bytes.SplitN": - if n := astcast.ToBasicLit(call.Args[2]); n.Value == "0" { - c.warnBadArg(n, "-1") - } - case "append": - if len(call.Args) == 1 { - c.warnAppend(call) - } - } -} - -func (c *badCallChecker) warnBadArg(badArg *ast.BasicLit, correction string) { - goodArg := astcopy.BasicLit(badArg) - goodArg.Value = correction - c.ctx.Warn(badArg, "suspicious arg %s, probably meant %s", - badArg, goodArg) -} - -func (c *badCallChecker) warnAppend(call *ast.CallExpr) { - c.ctx.Warn(call, "no-op append call, probably missing arguments") -} diff --git a/vendor/github.com/go-critic/go-critic/checkers/boolExprSimplify_checker.go b/vendor/github.com/go-critic/go-critic/checkers/boolExprSimplify_checker.go index f4eb9ed73940..65b08143a401 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/boolExprSimplify_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/boolExprSimplify_checker.go @@ -1,18 +1,14 @@ package checkers import ( - "fmt" "go/ast" "go/token" - "strconv" "github.com/go-critic/go-critic/checkers/internal/lintutil" "github.com/go-lintpack/lintpack" "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astcast" "github.com/go-toolsmith/astcopy" "github.com/go-toolsmith/astequal" - "github.com/go-toolsmith/astp" "github.com/go-toolsmith/typep" "golang.org/x/tools/go/ast/astutil" ) @@ -41,10 +37,6 @@ type boolExprSimplifyChecker struct { } func (c *boolExprSimplifyChecker) VisitExpr(x ast.Expr) { - if !astp.IsBinaryExpr(x) && !astp.IsUnaryExpr(x) { - return - } - // Throw away non-bool expressions and avoid redundant // AST copying below. if typ := c.ctx.TypesInfo.TypeOf(x); typ == nil || !typep.HasBoolKind(typ.Underlying()) { @@ -73,16 +65,14 @@ func (c *boolExprSimplifyChecker) simplifyBool(x ast.Expr) ast.Expr { c.negatedEquals(cur) || c.invertComparison(cur) || c.combineChecks(cur) || - c.removeIncDec(cur) || - c.foldRanges(cur) || true }).(ast.Expr) } func (c *boolExprSimplifyChecker) doubleNegation(cur *astutil.Cursor) bool { - neg1 := astcast.ToUnaryExpr(cur.Node()) - neg2 := astcast.ToUnaryExpr(astutil.Unparen(neg1.X)) - if neg1.Op == token.NOT && neg2.Op == token.NOT { + neg1 := lintutil.AsUnaryExprOp(cur.Node(), token.NOT) + neg2 := lintutil.AsUnaryExprOp(astutil.Unparen(neg1.X), token.NOT) + if !lintutil.IsNil(neg1) && !lintutil.IsNil(neg2) { cur.Replace(astutil.Unparen(neg2.X)) return true } @@ -94,9 +84,9 @@ func (c *boolExprSimplifyChecker) negatedEquals(cur *astutil.Cursor) bool { if !ok || x.Op != token.EQL { return false } - neg1 := astcast.ToUnaryExpr(x.X) - neg2 := astcast.ToUnaryExpr(x.Y) - if neg1.Op == token.NOT && neg2.Op == token.NOT { + neg1 := lintutil.AsUnaryExprOp(x.X, token.NOT) + neg2 := lintutil.AsUnaryExprOp(x.Y, token.NOT) + if !lintutil.IsNil(neg1) && !lintutil.IsNil(neg2) { x.X = neg1.X x.Y = neg2.X return true @@ -109,9 +99,9 @@ func (c *boolExprSimplifyChecker) invertComparison(cur *astutil.Cursor) bool { return false } - neg := astcast.ToUnaryExpr(cur.Node()) - cmp := astcast.ToBinaryExpr(astutil.Unparen(neg.X)) - if neg.Op != token.NOT { + neg := lintutil.AsUnaryExprOp(cur.Node(), token.NOT) + cmp := lintutil.AsBinaryExpr(astutil.Unparen(neg.X)) + if lintutil.IsNil(neg) || lintutil.IsNil(cmp) { return false } @@ -137,23 +127,17 @@ func (c *boolExprSimplifyChecker) invertComparison(cur *astutil.Cursor) bool { return true } -func (c *boolExprSimplifyChecker) isSafe(x ast.Expr) bool { - return typep.SideEffectFree(c.ctx.TypesInfo, x) -} - func (c *boolExprSimplifyChecker) combineChecks(cur *astutil.Cursor) bool { - or, ok := cur.Node().(*ast.BinaryExpr) - if !ok || or.Op != token.LOR { - return false - } - - lhs := astcast.ToBinaryExpr(astutil.Unparen(or.X)) - rhs := astcast.ToBinaryExpr(astutil.Unparen(or.Y)) + or := lintutil.AsBinaryExprOp(cur.Node(), token.LOR) + lhs := lintutil.AsBinaryExpr(astutil.Unparen(or.X)) + rhs := lintutil.AsBinaryExpr(astutil.Unparen(or.Y)) if !astequal.Expr(lhs.X, rhs.X) || !astequal.Expr(lhs.Y, rhs.Y) { return false } - if !c.isSafe(lhs.X) || !c.isSafe(lhs.Y) { + safe := typep.SideEffectFree(c.ctx.TypesInfo, lhs.X) && + typep.SideEffectFree(c.ctx.TypesInfo, lhs.Y) + if !safe { return false } @@ -177,167 +161,6 @@ func (c *boolExprSimplifyChecker) combineChecks(cur *astutil.Cursor) bool { return false } -func (c *boolExprSimplifyChecker) removeIncDec(cur *astutil.Cursor) bool { - cmp := astcast.ToBinaryExpr(cur.Node()) - - matchOneWay := func(op token.Token, x, y *ast.BinaryExpr) bool { - if x.Op != op || astcast.ToBasicLit(x.Y).Value != "1" { - return false - } - if y.Op == op && astcast.ToBasicLit(y.Y).Value == "1" { - return false - } - return true - } - replace := func(lhsOp, rhsOp, replacement token.Token) bool { - lhs := astcast.ToBinaryExpr(cmp.X) - rhs := astcast.ToBinaryExpr(cmp.Y) - switch { - case matchOneWay(lhsOp, lhs, rhs): - cmp.X = lhs.X - cmp.Op = replacement - cur.Replace(cmp) - return true - case matchOneWay(rhsOp, rhs, lhs): - cmp.Y = rhs.X - cmp.Op = replacement - cur.Replace(cmp) - return true - default: - return false - } - } - - switch cmp.Op { - case token.GTR: - // `x > y-1` => `x >= y` - // `x+1 > y` => `x >= y` - return replace(token.ADD, token.SUB, token.GEQ) - - case token.GEQ: - // `x >= y+1` => `x > y` - // `x-1 >= y` => `x > y` - return replace(token.SUB, token.ADD, token.GTR) - - case token.LSS: - // `x < y+1` => `x <= y` - // `x-1 < y` => `x <= y` - return replace(token.SUB, token.ADD, token.LEQ) - - case token.LEQ: - // `x <= y-1` => `x < y` - // `x+1 <= y` => `x < y` - return replace(token.ADD, token.SUB, token.LSS) - - default: - return false - } -} - -func (c *boolExprSimplifyChecker) foldRanges(cur *astutil.Cursor) bool { - if c.hasFloats { // See #848 - return false - } - - e, ok := cur.Node().(*ast.BinaryExpr) - if !ok { - return false - } - lhs := astcast.ToBinaryExpr(e.X) - rhs := astcast.ToBinaryExpr(e.Y) - if !c.isSafe(lhs.X) || !c.isSafe(rhs.X) { - return false - } - if !astequal.Expr(lhs.X, rhs.X) { - return false - } - - c1, ok := c.int64val(lhs.Y) - if !ok { - return false - } - c2, ok := c.int64val(rhs.Y) - if !ok { - return false - } - - type combination struct { - lhsOp token.Token - rhsOp token.Token - rhsDiff int64 - resDelta int64 - } - match := func(comb *combination) bool { - if lhs.Op != comb.lhsOp || rhs.Op != comb.rhsOp { - return false - } - if c2-c1 != comb.rhsDiff { - return false - } - return true - } - - switch e.Op { - case token.LAND: - combTable := [...]combination{ - // `x > c && x < c+2` => `x == c+1` - {token.GTR, token.LSS, 2, 1}, - // `x >= c && x < c+1` => `x == c` - {token.GEQ, token.LSS, 1, 0}, - // `x > c && x <= c+1` => `x == c+1` - {token.GTR, token.LEQ, 1, 1}, - // `x >= c && x <= c` => `x == c` - {token.GEQ, token.LEQ, 0, 0}, - } - for _, comb := range combTable { - if match(&comb) { - lhs.Op = token.EQL - v := c1 + comb.resDelta - lhs.Y.(*ast.BasicLit).Value = fmt.Sprint(v) - cur.Replace(lhs) - return true - } - } - - case token.LOR: - combTable := [...]combination{ - // `x < c || x > c` => `x != c` - {token.LSS, token.GTR, 0, 0}, - // `x <= c || x > c+1` => `x != c+1` - {token.LEQ, token.GTR, 1, 1}, - // `x < c || x >= c+1` => `x != c` - {token.LSS, token.GEQ, 1, 0}, - // `x <= c || x >= c+2` => `x != c+1` - {token.LEQ, token.GEQ, 2, 1}, - } - for _, comb := range combTable { - if match(&comb) { - lhs.Op = token.NEQ - v := c1 + comb.resDelta - lhs.Y.(*ast.BasicLit).Value = fmt.Sprint(v) - cur.Replace(lhs) - return true - } - } - } - - return false -} - -func (c *boolExprSimplifyChecker) int64val(x ast.Expr) (int64, bool) { - // TODO(Quasilyte): if we had types info, we could use TypesInfo.Types[x].Value, - // but since copying erases leaves us without it, only basic literals are handled. - lit, ok := x.(*ast.BasicLit) - if !ok { - return 0, false - } - v, err := strconv.ParseInt(lit.Value, 10, 64) - if err != nil { - return 0, false - } - return v, true -} - func (c *boolExprSimplifyChecker) warn(cause, suggestion ast.Expr) { c.SkipChilds = true c.ctx.Warn(cause, "can simplify `%s` to `%s`", cause, suggestion) diff --git a/vendor/github.com/go-critic/go-critic/checkers/builtinShadow_checker.go b/vendor/github.com/go-critic/go-critic/checkers/builtinShadow_checker.go index 24d8b7fff4f3..f7928f8ff7d4 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/builtinShadow_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/builtinShadow_checker.go @@ -16,17 +16,68 @@ func init() { info.After = `length := 10` collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - return astwalk.WalkerForLocalDef(&builtinShadowChecker{ctx: ctx}, ctx.TypesInfo) + builtins := map[string]bool{ + // Types + "bool": true, + "byte": true, + "complex64": true, + "complex128": true, + "error": true, + "float32": true, + "float64": true, + "int": true, + "int8": true, + "int16": true, + "int32": true, + "int64": true, + "rune": true, + "string": true, + "uint": true, + "uint8": true, + "uint16": true, + "uint32": true, + "uint64": true, + "uintptr": true, + + // Constants + "true": true, + "false": true, + "iota": true, + + // Zero value + "nil": true, + + // Functions + "append": true, + "cap": true, + "close": true, + "complex": true, + "copy": true, + "delete": true, + "imag": true, + "len": true, + "make": true, + "new": true, + "panic": true, + "print": true, + "println": true, + "real": true, + "recover": true, + } + c := &builtinShadowChecker{ctx: ctx, builtins: builtins} + return astwalk.WalkerForLocalDef(c, ctx.TypesInfo) }) } type builtinShadowChecker struct { astwalk.WalkHandler ctx *lintpack.CheckerContext + + builtins map[string]bool } func (c *builtinShadowChecker) VisitLocalDef(name astwalk.Name, _ ast.Expr) { - if isBuiltin(name.ID.Name) { + if _, isBuiltin := c.builtins[name.ID.String()]; isBuiltin { c.warn(name.ID) } } diff --git a/vendor/github.com/go-critic/go-critic/checkers/caseOrder_checker.go b/vendor/github.com/go-critic/go-critic/checkers/caseOrder_checker.go index 1ef4b53b7fff..3da6f5c87d11 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/caseOrder_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/caseOrder_checker.go @@ -57,10 +57,6 @@ func (c *caseOrderChecker) checkTypeSwitch(s *ast.TypeSwitchStmt) { cc := cc.(*ast.CaseClause) for _, x := range cc.List { typ := c.ctx.TypesInfo.TypeOf(x) - if typ == nil { - c.warnTypeImpl(cc, x) - return - } for _, iface := range ifaces { if types.Implements(typ, iface.typ) { c.warnTypeSwitch(cc, x, iface.node) @@ -78,10 +74,6 @@ func (c *caseOrderChecker) warnTypeSwitch(cause, concrete, iface ast.Node) { c.ctx.Warn(cause, "case %s must go before the %s case", concrete, iface) } -func (c *caseOrderChecker) warnTypeImpl(cause, concrete ast.Node) { - c.ctx.Warn(cause, "type is not defined %s", concrete) -} - func (c *caseOrderChecker) checkSwitch(s *ast.SwitchStmt) { // TODO(Quasilyte): can handle expression cases that overlap. // Cases that have narrower value range should go before wider ones. diff --git a/vendor/github.com/go-critic/go-critic/checkers/checkers.go b/vendor/github.com/go-critic/go-critic/checkers/checkers.go index 96202221e2be..7cf972944ac3 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/checkers.go +++ b/vendor/github.com/go-critic/go-critic/checkers/checkers.go @@ -6,5 +6,5 @@ import ( ) var collection = &lintpack.CheckerCollection{ - URL: "https://github.com/go-critic/go-critic/checkers", + URL: "https://github.com/go-critic/checkers", } diff --git a/vendor/github.com/go-critic/go-critic/checkers/codegenComment_checker.go b/vendor/github.com/go-critic/go-critic/checkers/codegenComment_checker.go deleted file mode 100644 index 14d89da374b3..000000000000 --- a/vendor/github.com/go-critic/go-critic/checkers/codegenComment_checker.go +++ /dev/null @@ -1,61 +0,0 @@ -package checkers - -import ( - "go/ast" - "regexp" - "strings" - - "github.com/go-lintpack/lintpack" - "github.com/go-lintpack/lintpack/astwalk" -) - -func init() { - var info lintpack.CheckerInfo - info.Name = "codegenComment" - info.Tags = []string{"diagnostic", "experimental"} - info.Summary = "Detects malformed 'code generated' file comments" - info.Before = `// This file was automatically generated by foogen` - info.After = `// Code generated by foogen. DO NOT EDIT.` - - collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - patterns := []string{ - "this (?:file|code) (?:was|is) auto(?:matically)? generated", - "this (?:file|code) (?:was|is) generated automatically", - "this (?:file|code) (?:was|is) generated by", - "this (?:file|code) (?:was|is) (?:auto(?:matically)? )?generated", - "this (?:file|code) (?:was|is) generated", - "code in this file (?:was|is) auto(?:matically)? generated", - "generated (?:file|code) - do not edit", - // TODO(Quasilyte): more of these. - } - re := regexp.MustCompile("(?i)" + strings.Join(patterns, "|")) - return &codegenCommentChecker{ - ctx: ctx, - badCommentRE: re, - } - }) -} - -type codegenCommentChecker struct { - astwalk.WalkHandler - ctx *lintpack.CheckerContext - - badCommentRE *regexp.Regexp -} - -func (c *codegenCommentChecker) WalkFile(f *ast.File) { - if f.Doc == nil { - return - } - - for _, comment := range f.Doc.List { - if c.badCommentRE.MatchString(comment.Text) { - c.warn(comment) - return - } - } -} - -func (c *codegenCommentChecker) warn(cause ast.Node) { - c.ctx.Warn(cause, "comment should match `Code generated .* DO NOT EDIT.` regexp") -} diff --git a/vendor/github.com/go-critic/go-critic/checkers/commentFormatting_checker.go b/vendor/github.com/go-critic/go-critic/checkers/commentFormatting_checker.go index ed75015e0950..b5dc17e4d061 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/commentFormatting_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/commentFormatting_checker.go @@ -20,13 +20,7 @@ func init() { info.After = `// This is a comment` collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - parts := []string{ - `^//\w+:.*$`, //key: value - `^//nolint$`, //nolint - `^//line /.*:\d+`, //line /path/to/file:123 - } - pat := "(?m)" + strings.Join(parts, "|") - pragmaRE := regexp.MustCompile(pat) + pragmaRE := regexp.MustCompile(`(?m)^//\w+:.*$`) return astwalk.WalkerForComment(&commentFormattingChecker{ ctx: ctx, pragmaRE: pragmaRE, diff --git a/vendor/github.com/go-critic/go-critic/checkers/commentedOutCode_checker.go b/vendor/github.com/go-critic/go-critic/checkers/commentedOutCode_checker.go index 0554e365ed3f..77b36ef33bab 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/commentedOutCode_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/commentedOutCode_checker.go @@ -1,7 +1,6 @@ package checkers import ( - "fmt" "go/ast" "go/token" "regexp" @@ -33,16 +32,10 @@ foo(1, 2)` type commentedOutCodeChecker struct { astwalk.WalkHandler ctx *lintpack.CheckerContext - fn *ast.FuncDecl notQuiteFuncCall *regexp.Regexp } -func (c *commentedOutCodeChecker) EnterFunc(fn *ast.FuncDecl) bool { - c.fn = fn // Need to store current function inside checker context - return fn.Body != nil -} - func (c *commentedOutCodeChecker) VisitLocalComment(cg *ast.CommentGroup) { s := cg.Text() // Collect text once @@ -84,44 +77,13 @@ func (c *commentedOutCodeChecker) VisitLocalComment(cg *ast.CommentGroup) { } stmt := strparse.Stmt(s) - - if c.isPermittedStmt(stmt) { - return + if stmt == strparse.BadStmt { + return // Most likely not a code } - if stmt != strparse.BadStmt { + if !c.isPermittedStmt(stmt) { c.warn(cg) - return - } - - // Don't try to parse one-liner as block statement - if len(cg.List) == 1 && !strings.Contains(s, "\n") { - return - } - - // Some attempts to avoid false positives. - if c.skipBlock(s) { - return } - - // Add braces to make block statement from - // multiple statements. - stmt = strparse.Stmt(fmt.Sprintf("{ %s }", s)) - - if stmt, ok := stmt.(*ast.BlockStmt); ok && len(stmt.List) != 0 { - c.warn(cg) - } -} - -func (c *commentedOutCodeChecker) skipBlock(s string) bool { - lines := strings.Split(s, "\n") // There is at least 1 line, that's invariant - - // Special example test block. - if isExampleTestFunc(c.fn) && strings.Contains(lines[0], "Output:") { - return true - } - - return false } func (c *commentedOutCodeChecker) isPermittedStmt(stmt ast.Stmt) bool { diff --git a/vendor/github.com/go-critic/go-critic/checkers/deprecatedComment_checker.go b/vendor/github.com/go-critic/go-critic/checkers/deprecatedComment_checker.go index 37675735b86c..f8b3e5625c9a 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/deprecatedComment_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/deprecatedComment_checker.go @@ -27,9 +27,6 @@ func FuncOld() int` c.commonPatterns = []*regexp.Regexp{ regexp.MustCompile(`(?i)this (?:function|type) is deprecated`), regexp.MustCompile(`(?i)deprecated[.!]? use \S* instead`), - regexp.MustCompile(`(?i)\[\[deprecated\]\].*`), - regexp.MustCompile(`(?i)note: deprecated\b.*`), - regexp.MustCompile(`(?i)deprecated in.*`), // TODO(quasilyte): more of these? } @@ -49,7 +46,6 @@ func FuncOld() int` "Deprecate: ", "Derpecate: ", "Derpecated: ", - "Depreacted: ", } for i := range c.commonTypos { c.commonTypos[i] = strings.ToUpper(c.commonTypos[i]) diff --git a/vendor/github.com/go-critic/go-critic/checkers/dupArg_checker.go b/vendor/github.com/go-critic/go-critic/checkers/dupArg_checker.go index 2e6a0cbfa004..3eb885aa4ed3 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/dupArg_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/dupArg_checker.go @@ -2,11 +2,9 @@ package checkers import ( "go/ast" - "go/types" "github.com/go-lintpack/lintpack" "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astcast" "github.com/go-toolsmith/astequal" ) @@ -50,9 +48,6 @@ func init() { c.matchers = map[string]func(*ast.CallExpr) bool{ "copy": m["(x, x, ...)"], - "math.Max": m["(x, x, ...)"], - "math.Min": m["(x, x, ...)"], - "reflect.Copy": m["(x, x, ...)"], "reflect.DeepEqual": m["(x, x, ...)"], @@ -109,16 +104,6 @@ func (c *dupArgChecker) VisitExpr(expr ast.Expr) { return } - // TODO(quasilyte): this kind of check is needed in multiple - // places and the code is somewhat duplicated around. - // We probably need to stop using qualifiedName for non-experimental checkers. - if calledExpr, ok := call.Fun.(*ast.SelectorExpr); ok { - obj, ok := c.ctx.TypesInfo.ObjectOf(astcast.ToIdent(calledExpr.X)).(*types.PkgName) - if !ok || !isStdlibPkg(obj.Imported()) { - return - } - } - m := c.matchers[qualifiedName(call.Fun)] if m != nil && m(call) { c.warn(call) diff --git a/vendor/github.com/go-critic/go-critic/checkers/dupImports_checker.go b/vendor/github.com/go-critic/go-critic/checkers/dupImports_checker.go deleted file mode 100644 index d531413a11c9..000000000000 --- a/vendor/github.com/go-critic/go-critic/checkers/dupImports_checker.go +++ /dev/null @@ -1,63 +0,0 @@ -package checkers - -import ( - "fmt" - "go/ast" - - "github.com/go-lintpack/lintpack" -) - -func init() { - var info lintpack.CheckerInfo - info.Name = "dupImport" - info.Tags = []string{"style", "experimental"} - info.Summary = "Detects multiple imports of the same package under different aliases" - info.Before = ` -import ( - "fmt" - priting "fmt" // Imported the second time -)` - info.After = ` -import( - "fmt" -)` - - collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - return &dupImportChecker{ctx: ctx} - }) -} - -type dupImportChecker struct { - ctx *lintpack.CheckerContext -} - -func (c *dupImportChecker) WalkFile(f *ast.File) { - imports := make(map[string][]*ast.ImportSpec) - for _, importDcl := range f.Imports { - pkg := importDcl.Path.Value - imports[pkg] = append(imports[pkg], importDcl) - } - - for _, importList := range imports { - if len(importList) == 1 { - continue - } - c.warn(importList) - } -} - -func (c *dupImportChecker) warn(importList []*ast.ImportSpec) { - msg := fmt.Sprintf("package is imported %d times under different aliases on lines", len(importList)) - for idx, importDcl := range importList { - switch { - case idx == len(importList)-1: - msg += " and" - case idx > 0: - msg += "," - } - msg += fmt.Sprintf(" %d", c.ctx.FileSet.Position(importDcl.Pos()).Line) - } - for _, importDcl := range importList { - c.ctx.Warn(importDcl, msg) - } -} diff --git a/vendor/github.com/go-critic/go-critic/checkers/equalFold_checker.go b/vendor/github.com/go-critic/go-critic/checkers/equalFold_checker.go index 265b2f79beee..3f4fb914bb6e 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/equalFold_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/equalFold_checker.go @@ -7,7 +7,6 @@ import ( "github.com/go-lintpack/lintpack" "github.com/go-lintpack/lintpack/astwalk" "github.com/go-toolsmith/astcast" - "github.com/go-toolsmith/astequal" ) func init() { @@ -58,9 +57,7 @@ func (c *equalFoldChecker) checkBytes(expr *ast.CallExpr) { if !ok1 && !ok2 { return } - if !astequal.Expr(x, y) { - c.warnBytes(expr, x, y) - } + c.warnBytes(expr, x, y) } func (c *equalFoldChecker) checkStrings(expr *ast.BinaryExpr) { @@ -73,9 +70,7 @@ func (c *equalFoldChecker) checkStrings(expr *ast.BinaryExpr) { if !ok1 && !ok2 { return } - if !astequal.Expr(x, y) { - c.warnStrings(expr, x, y) - } + c.warnStrings(expr, x, y) } func (c *equalFoldChecker) warnStrings(cause ast.Node, x, y ast.Expr) { diff --git a/vendor/github.com/go-critic/go-critic/checkers/evalOrder_checker.go b/vendor/github.com/go-critic/go-critic/checkers/evalOrder_checker.go deleted file mode 100644 index f76519cd7c87..000000000000 --- a/vendor/github.com/go-critic/go-critic/checkers/evalOrder_checker.go +++ /dev/null @@ -1,87 +0,0 @@ -package checkers - -import ( - "go/ast" - "go/token" - "go/types" - - "github.com/go-critic/go-critic/checkers/internal/lintutil" - "github.com/go-lintpack/lintpack" - "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astcast" - "github.com/go-toolsmith/astequal" - "github.com/go-toolsmith/typep" -) - -func init() { - var info lintpack.CheckerInfo - info.Name = "evalOrder" - info.Tags = []string{"diagnostic", "experimental"} - info.Summary = "Detects unwanted dependencies on the evaluation order" - info.Before = `return x, f(&x)` - info.After = ` -err := f(&x) -return x, err -` - - collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - return astwalk.WalkerForStmt(&evalOrderChecker{ctx: ctx}) - }) -} - -type evalOrderChecker struct { - astwalk.WalkHandler - ctx *lintpack.CheckerContext -} - -func (c *evalOrderChecker) VisitStmt(stmt ast.Stmt) { - ret := astcast.ToReturnStmt(stmt) - if len(ret.Results) < 2 { - return - } - - // TODO(quasilyte): handle selector expressions like o.val in addition - // to bare identifiers. - addrTake := &ast.UnaryExpr{Op: token.AND} - for _, res := range ret.Results { - id, ok := res.(*ast.Ident) - if !ok { - continue - } - addrTake.X = id // addrTake is &id now - for _, res := range ret.Results { - call, ok := res.(*ast.CallExpr) - if !ok { - continue - } - - // 1. Check if there is a call in form of id.method() where - // method takes id by a pointer. - if sel, ok := call.Fun.(*ast.SelectorExpr); ok { - if astequal.Node(sel.X, id) && c.hasPtrRecv(sel.Sel) { - c.warn(call) - } - } - - // 2. Check that there is no call that uses &id as an argument. - dependency := lintutil.ContainsNode(call, func(n ast.Node) bool { - return astequal.Node(addrTake, n) - }) - if dependency { - c.warn(call) - } - } - } -} - -func (c *evalOrderChecker) hasPtrRecv(fn *ast.Ident) bool { - sig, ok := c.ctx.TypesInfo.TypeOf(fn).(*types.Signature) - if !ok { - return false - } - return typep.IsPointer(sig.Recv().Type()) -} - -func (c *evalOrderChecker) warn(call *ast.CallExpr) { - c.ctx.Warn(call, "may want to evaluate %s before the return statement", call) -} diff --git a/vendor/github.com/go-critic/go-critic/checkers/exitAfterDefer_checker.go b/vendor/github.com/go-critic/go-critic/checkers/exitAfterDefer_checker.go deleted file mode 100644 index 05ed6ae9e1aa..000000000000 --- a/vendor/github.com/go-critic/go-critic/checkers/exitAfterDefer_checker.go +++ /dev/null @@ -1,78 +0,0 @@ -package checkers - -import ( - "go/ast" - - "github.com/go-lintpack/lintpack" - "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astfmt" - "github.com/go-toolsmith/astp" - "golang.org/x/tools/go/ast/astutil" -) - -func init() { - var info lintpack.CheckerInfo - info.Name = "exitAfterDefer" - info.Tags = []string{"diagnostic", "experimental"} - info.Summary = "Detects calls to exit/fatal inside functions that use defer" - info.Before = ` -defer os.Remove(filename) -if bad { - log.Fatalf("something bad happened") -}` - info.After = ` -defer os.Remove(filename) -if bad { - log.Printf("something bad happened") - return -}` - - collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - return astwalk.WalkerForFuncDecl(&exitAfterDeferChecker{ctx: ctx}) - }) -} - -type exitAfterDeferChecker struct { - astwalk.WalkHandler - ctx *lintpack.CheckerContext -} - -func (c *exitAfterDeferChecker) VisitFuncDecl(fn *ast.FuncDecl) { - // TODO(Quasilyte): handle goto and other kinds of flow that break - // the algorithm below that expects the latter statement to be - // executed after the ones that come before it. - - var deferStmt *ast.DeferStmt - pre := func(cur *astutil.Cursor) bool { - // Don't recurse into local anonymous functions. - return !astp.IsFuncLit(cur.Node()) - } - post := func(cur *astutil.Cursor) bool { - switch n := cur.Node().(type) { - case *ast.DeferStmt: - deferStmt = n - case *ast.CallExpr: - if deferStmt != nil { - switch qualifiedName(n.Fun) { - case "log.Fatal", "log.Fatalf", "log.Fatalln", "os.Exit": - c.warn(n, deferStmt) - return false - } - } - } - return true - } - astutil.Apply(fn.Body, pre, post) -} - -func (c *exitAfterDeferChecker) warn(cause *ast.CallExpr, deferStmt *ast.DeferStmt) { - var s string - if fnlit, ok := deferStmt.Call.Fun.(*ast.FuncLit); ok { - // To avoid long and multi-line warning messages, - // collapse the function literals. - s = "defer " + astfmt.Sprint(fnlit.Type) + "{...}(...)" - } else { - s = astfmt.Sprint(deferStmt) - } - c.ctx.Warn(cause, "%s clutters `%s`", cause.Fun, s) -} diff --git a/vendor/github.com/go-critic/go-critic/checkers/flagName_checker.go b/vendor/github.com/go-critic/go-critic/checkers/flagName_checker.go index 1d43ba52113f..f8d8fc677e46 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/flagName_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/flagName_checker.go @@ -3,7 +3,6 @@ package checkers import ( "go/ast" "go/constant" - "go/types" "strings" "github.com/go-lintpack/lintpack" @@ -31,14 +30,13 @@ type flagNameChecker struct { func (c *flagNameChecker) VisitExpr(expr ast.Expr) { call := astcast.ToCallExpr(expr) - calledExpr := astcast.ToSelectorExpr(call.Fun) - obj, ok := c.ctx.TypesInfo.ObjectOf(astcast.ToIdent(calledExpr.X)).(*types.PkgName) - if !ok { + sym := astcast.ToIdent(astcast.ToSelectorExpr(call.Fun).Sel) + obj := c.ctx.TypesInfo.ObjectOf(sym) + if obj == nil { return } - sym := calledExpr.Sel - pkg := obj.Imported() - if pkg.Path() != "flag" { + pkg := obj.Pkg() + if !isStdlibPkg(pkg) || pkg.Name() != "flag" { return } diff --git a/vendor/github.com/go-critic/go-critic/checkers/hexLiteral_checker.go b/vendor/github.com/go-critic/go-critic/checkers/hexLiteral_checker.go deleted file mode 100644 index a700314cf3db..000000000000 --- a/vendor/github.com/go-critic/go-critic/checkers/hexLiteral_checker.go +++ /dev/null @@ -1,60 +0,0 @@ -package checkers - -import ( - "go/ast" - "go/token" - "strings" - - "github.com/go-lintpack/lintpack" - "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astcast" -) - -func init() { - var info lintpack.CheckerInfo - info.Name = "hexLiteral" - info.Tags = []string{"style", "experimental"} - info.Summary = "Detects hex literals that have mixed case letter digits" - info.Before = ` -x := 0X12 -y := 0xfF` - info.After = ` -x := 0x12 -// (A) -y := 0xff -// (B) -y := 0xFF` - - collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - return astwalk.WalkerForExpr(&hexLiteralChecker{ctx: ctx}) - }) -} - -type hexLiteralChecker struct { - astwalk.WalkHandler - ctx *lintpack.CheckerContext -} - -func (c *hexLiteralChecker) warn0X(lit *ast.BasicLit) { - suggest := "0x" + lit.Value[len("0X"):] - c.ctx.Warn(lit, "prefer 0x over 0X, s/%s/%s/", lit.Value, suggest) -} - -func (c *hexLiteralChecker) warnMixedDigits(lit *ast.BasicLit) { - c.ctx.Warn(lit, "don't mix hex literal letter digits casing") -} - -func (c *hexLiteralChecker) VisitExpr(expr ast.Expr) { - lit := astcast.ToBasicLit(expr) - if lit.Kind != token.INT || len(lit.Value) < 3 { - return - } - if strings.HasPrefix(lit.Value, "0X") { - c.warn0X(lit) - return - } - digits := lit.Value[len("0x"):] - if strings.ToLower(digits) != digits && strings.ToUpper(digits) != digits { - c.warnMixedDigits(lit) - } -} diff --git a/vendor/github.com/go-critic/go-critic/checkers/internal/lintutil/coerce.go b/vendor/github.com/go-critic/go-critic/checkers/internal/lintutil/coerce.go new file mode 100644 index 000000000000..8a3e35684a32 --- /dev/null +++ b/vendor/github.com/go-critic/go-critic/checkers/internal/lintutil/coerce.go @@ -0,0 +1,121 @@ +package lintutil + +import ( + "go/ast" + "go/token" +) + +var ( + nilIdent = &ast.Ident{} + nilSelectorExpr = &ast.SelectorExpr{} + nilUnaryExpr = &ast.UnaryExpr{} + nilBinaryExpr = &ast.BinaryExpr{} + nilCallExpr = &ast.CallExpr{} + nilParenExpr = &ast.ParenExpr{} + nilAssignStmt = &ast.AssignStmt{} +) + +// IsNil reports whether x is nil. +// Unlike simple nil check, also detects nil AST sentinels. +func IsNil(x ast.Node) bool { + switch x := x.(type) { + case *ast.Ident: + return x == nilIdent || x == nil + case *ast.SelectorExpr: + return x == nilSelectorExpr || x == nil + case *ast.UnaryExpr: + return x == nilUnaryExpr || x == nil + case *ast.BinaryExpr: + return x == nilBinaryExpr || x == nil + case *ast.CallExpr: + return x == nilCallExpr || x == nil + case *ast.ParenExpr: + return x == nilParenExpr || x == nil + case *ast.AssignStmt: + return x == nilAssignStmt || x == nil + + default: + return x == nil + } +} + +// AsIdent coerces x into non-nil ident. +func AsIdent(x ast.Node) *ast.Ident { + e, ok := x.(*ast.Ident) + if !ok { + return nilIdent + } + return e +} + +// AsSelectorExpr coerces x into non-nil selector expr. +func AsSelectorExpr(x ast.Node) *ast.SelectorExpr { + e, ok := x.(*ast.SelectorExpr) + if !ok { + return nilSelectorExpr + } + return e +} + +// AsUnaryExpr coerces x into non-nil unary expr. +func AsUnaryExpr(x ast.Node) *ast.UnaryExpr { + e, ok := x.(*ast.UnaryExpr) + if !ok { + return nilUnaryExpr + } + return e +} + +// AsUnaryExprOp is like AsUnaryExpr, but also checks for op token. +func AsUnaryExprOp(x ast.Node, op token.Token) *ast.UnaryExpr { + e, ok := x.(*ast.UnaryExpr) + if !ok || e.Op != op { + return nilUnaryExpr + } + return e +} + +// AsBinaryExpr coerces x into non-nil binary expr. +func AsBinaryExpr(x ast.Node) *ast.BinaryExpr { + e, ok := x.(*ast.BinaryExpr) + if !ok { + return nilBinaryExpr + } + return e +} + +// AsBinaryExprOp is like AsBinaryExpr, but also checks for op token. +func AsBinaryExprOp(x ast.Node, op token.Token) *ast.BinaryExpr { + e, ok := x.(*ast.BinaryExpr) + if !ok || e.Op != op { + return nilBinaryExpr + } + return e +} + +// AsCallExpr coerces x into non-nil call expr. +func AsCallExpr(x ast.Node) *ast.CallExpr { + e, ok := x.(*ast.CallExpr) + if !ok { + return nilCallExpr + } + return e +} + +// AsParenExpr coerces x into non-nil paren expr. +func AsParenExpr(x ast.Node) *ast.ParenExpr { + e, ok := x.(*ast.ParenExpr) + if !ok { + return nilParenExpr + } + return e +} + +// AsAssignStmt coerces x into non-nil assign stmt. +func AsAssignStmt(x ast.Node) *ast.AssignStmt { + stmt, ok := x.(*ast.AssignStmt) + if !ok { + return nilAssignStmt + } + return stmt +} diff --git a/vendor/github.com/go-critic/go-critic/checkers/internal/lintutil/zero_value.go b/vendor/github.com/go-critic/go-critic/checkers/internal/lintutil/zero_value.go deleted file mode 100644 index 4370f58185a4..000000000000 --- a/vendor/github.com/go-critic/go-critic/checkers/internal/lintutil/zero_value.go +++ /dev/null @@ -1,94 +0,0 @@ -package lintutil - -import ( - "go/ast" - "go/constant" - "go/token" - "go/types" -) - -// IsZeroValue reports whether x represents zero value of its type. -// -// The functions is conservative and may return false for zero values -// if some cases are not handled in a comprehensive way -// but is should never return true for something that's not a proper zv. -func IsZeroValue(info *types.Info, x ast.Expr) bool { - switch x := x.(type) { - case *ast.BasicLit: - typ := info.TypeOf(x).Underlying().(*types.Basic) - v := info.Types[x].Value - var z constant.Value - switch { - case typ.Kind() == types.String: - z = constant.MakeString("") - case typ.Info()&types.IsInteger != 0: - z = constant.MakeInt64(0) - case typ.Info()&types.IsUnsigned != 0: - z = constant.MakeUint64(0) - case typ.Info()&types.IsFloat != 0: - z = constant.MakeFloat64(0) - default: - return false - } - return constant.Compare(v, token.EQL, z) - - case *ast.CompositeLit: - return len(x.Elts) == 0 - - default: - // Note that this function is not comprehensive. - return false - } -} - -// ZeroValueOf returns a zero value expression for typeExpr of type typ. -// If function can't find such a value, nil is returned. -func ZeroValueOf(typeExpr ast.Expr, typ types.Type) ast.Expr { - switch utyp := typ.Underlying().(type) { - case *types.Basic: - info := utyp.Info() - var zv ast.Expr - switch { - case info&types.IsInteger != 0: - zv = &ast.BasicLit{Kind: token.INT, Value: "0"} - case info&types.IsFloat != 0: - zv = &ast.BasicLit{Kind: token.FLOAT, Value: "0.0"} - case info&types.IsString != 0: - zv = &ast.BasicLit{Kind: token.STRING, Value: `""`} - case info&types.IsBoolean != 0: - zv = &ast.Ident{Name: "false"} - } - if isDefaultLiteralType(typ) { - return zv - } - return &ast.CallExpr{ - Fun: typeExpr, - Args: []ast.Expr{zv}, - } - - case *types.Slice, *types.Map, *types.Pointer, *types.Interface: - return &ast.CallExpr{ - Fun: typeExpr, - Args: []ast.Expr{&ast.Ident{Name: "nil"}}, - } - - case *types.Array, *types.Struct: - return &ast.CompositeLit{Type: typeExpr} - - default: - return nil - } -} - -func isDefaultLiteralType(typ types.Type) bool { - btyp, ok := typ.(*types.Basic) - if !ok { - return false - } - switch btyp.Kind() { - case types.Bool, types.Int, types.Float64, types.String: - return true - default: - return false - } -} diff --git a/vendor/github.com/go-critic/go-critic/checkers/newDeref_checker.go b/vendor/github.com/go-critic/go-critic/checkers/newDeref_checker.go deleted file mode 100644 index 75e7f642824a..000000000000 --- a/vendor/github.com/go-critic/go-critic/checkers/newDeref_checker.go +++ /dev/null @@ -1,45 +0,0 @@ -package checkers - -import ( - "go/ast" - - "github.com/go-critic/go-critic/checkers/internal/lintutil" - "github.com/go-lintpack/lintpack" - "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astcast" - "golang.org/x/tools/go/ast/astutil" -) - -func init() { - var info lintpack.CheckerInfo - info.Name = "newDeref" - info.Tags = []string{"style", "experimental"} - info.Summary = "Detects immediate dereferencing of `new` expressions" - info.Before = `x := *new(bool)` - info.After = `x := false` - - collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - return astwalk.WalkerForExpr(&newDerefChecker{ctx: ctx}) - }) -} - -type newDerefChecker struct { - astwalk.WalkHandler - ctx *lintpack.CheckerContext -} - -func (c *newDerefChecker) VisitExpr(expr ast.Expr) { - deref := astcast.ToStarExpr(expr) - call := astcast.ToCallExpr(deref.X) - if astcast.ToIdent(call.Fun).Name == "new" { - typ := c.ctx.TypesInfo.TypeOf(call.Args[0]) - zv := lintutil.ZeroValueOf(astutil.Unparen(call.Args[0]), typ) - if zv != nil { - c.warn(expr, zv) - } - } -} - -func (c *newDerefChecker) warn(cause, suggestion ast.Expr) { - c.ctx.Warn(cause, "replace `%s` with `%s`", cause, suggestion) -} diff --git a/vendor/github.com/go-critic/go-critic/checkers/octalLiteral_checker.go b/vendor/github.com/go-critic/go-critic/checkers/octalLiteral_checker.go deleted file mode 100644 index e40ec6db5e35..000000000000 --- a/vendor/github.com/go-critic/go-critic/checkers/octalLiteral_checker.go +++ /dev/null @@ -1,82 +0,0 @@ -package checkers - -import ( - "go/ast" - "go/token" - "go/types" - - "github.com/go-lintpack/lintpack" - "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astcast" -) - -func init() { - var info lintpack.CheckerInfo - info.Name = "octalLiteral" - info.Tags = []string{"diagnostic", "experimental"} - info.Summary = "Detects octal literals passed to functions" - info.Before = `foo(02)` - info.After = `foo(2)` - - collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - c := &octalLiteralChecker{ - ctx: ctx, - octFriendlyPkg: map[string]bool{ - "os": true, - "io/ioutil": true, - }, - } - return astwalk.WalkerForExpr(c) - }) -} - -type octalLiteralChecker struct { - astwalk.WalkHandler - ctx *lintpack.CheckerContext - - octFriendlyPkg map[string]bool -} - -func (c *octalLiteralChecker) VisitExpr(expr ast.Expr) { - call := astcast.ToCallExpr(expr) - calledExpr := astcast.ToSelectorExpr(call.Fun) - ident := astcast.ToIdent(calledExpr.X) - - if obj, ok := c.ctx.TypesInfo.ObjectOf(ident).(*types.PkgName); ok { - pkg := obj.Imported() - if c.octFriendlyPkg[pkg.Path()] { - return - } - } - - for _, arg := range call.Args { - if lit := astcast.ToBasicLit(c.unsign(arg)); len(lit.Value) > 1 && - c.isIntLiteral(lit) && - c.isOctalLiteral(lit) { - c.warn(call) - return - } - } -} - -func (c *octalLiteralChecker) unsign(e ast.Expr) ast.Expr { - u, ok := e.(*ast.UnaryExpr) - if !ok { - return e - } - return u.X -} - -func (c *octalLiteralChecker) isIntLiteral(lit *ast.BasicLit) bool { - return lit.Kind == token.INT -} - -func (c *octalLiteralChecker) isOctalLiteral(lit *ast.BasicLit) bool { - return lit.Value[0] == '0' && - lit.Value[1] != 'x' && - lit.Value[1] != 'X' -} - -func (c *octalLiteralChecker) warn(expr ast.Expr) { - c.ctx.Warn(expr, "suspicious octal args in `%s`", expr) -} diff --git a/vendor/github.com/go-critic/go-critic/checkers/rangeValCopy_checker.go b/vendor/github.com/go-critic/go-critic/checkers/rangeValCopy_checker.go index 182538a9f0aa..0e24369225c7 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/rangeValCopy_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/rangeValCopy_checker.go @@ -70,6 +70,6 @@ func (c *rangeValCopyChecker) VisitStmt(stmt ast.Stmt) { } } -func (c *rangeValCopyChecker) warn(n ast.Node, size int64) { - c.ctx.Warn(n, "each iteration copies %d bytes (consider pointers or indexing)", size) +func (c *rangeValCopyChecker) warn(node ast.Node, size int64) { + c.ctx.Warn(node, "each iteration copies %d bytes (consider pointers or indexing)", size) } diff --git a/vendor/github.com/go-critic/go-critic/checkers/stringXbytes_checker.go b/vendor/github.com/go-critic/go-critic/checkers/stringXbytes_checker.go deleted file mode 100644 index 74570108e698..000000000000 --- a/vendor/github.com/go-critic/go-critic/checkers/stringXbytes_checker.go +++ /dev/null @@ -1,47 +0,0 @@ -package checkers - -import ( - "go/ast" - - "github.com/go-lintpack/lintpack" - "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/typep" -) - -func init() { - var info lintpack.CheckerInfo - info.Name = "stringXbytes" - info.Tags = []string{"style", "experimental"} - info.Summary = "Detects redundant conversions between string and []byte" - info.Before = `copy(b, []byte(s))` - info.After = `copy(b, s)` - - collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - return astwalk.WalkerForExpr(&stringXbytes{ctx: ctx}) - }) -} - -type stringXbytes struct { - astwalk.WalkHandler - ctx *lintpack.CheckerContext -} - -func (c *stringXbytes) VisitExpr(expr ast.Expr) { - x, ok := expr.(*ast.CallExpr) - if !ok || qualifiedName(x.Fun) != "copy" { - return - } - - src := x.Args[1] - - byteCast, ok := src.(*ast.CallExpr) - if ok && typep.IsTypeExpr(c.ctx.TypesInfo, byteCast.Fun) && - typep.HasStringProp(c.ctx.TypesInfo.TypeOf(byteCast.Args[0])) { - - c.warn(byteCast, byteCast.Args[0]) - } -} - -func (c *stringXbytes) warn(cause *ast.CallExpr, suggestion ast.Expr) { - c.ctx.Warn(cause, "can simplify `%s` to `%s`", cause, suggestion) -} diff --git a/vendor/github.com/go-critic/go-critic/checkers/typeAssertChain_checker.go b/vendor/github.com/go-critic/go-critic/checkers/typeAssertChain_checker.go deleted file mode 100644 index c0c42e3511c1..000000000000 --- a/vendor/github.com/go-critic/go-critic/checkers/typeAssertChain_checker.go +++ /dev/null @@ -1,132 +0,0 @@ -package checkers - -import ( - "go/ast" - "go/token" - - "github.com/go-critic/go-critic/checkers/internal/lintutil" - "github.com/go-lintpack/lintpack" - "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astcast" - "github.com/go-toolsmith/astequal" - "github.com/go-toolsmith/astp" -) - -func init() { - var info lintpack.CheckerInfo - info.Name = "typeAssertChain" - info.Tags = []string{"style", "experimental"} - info.Summary = "Detects repeated type assertions and suggests to replace them with type switch statement" - info.Before = ` -if x, ok := v.(T1); ok { - // Code A, uses x. -} else if x, ok := v.(T2); ok { - // Code B, uses x. -} else if x, ok := v.(T3); ok { - // Code C, uses x. -}` - info.After = ` -switch x := v.(T1) { -case cond1: - // Code A, uses x. -case cond2: - // Code B, uses x. -default: - // Code C, uses x. -}` - - collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker { - return astwalk.WalkerForStmt(&typeAssertChainChecker{ctx: ctx}) - }) -} - -type typeAssertChainChecker struct { - astwalk.WalkHandler - ctx *lintpack.CheckerContext - - cause *ast.IfStmt - visited map[*ast.IfStmt]bool - typeSet lintutil.AstSet -} - -func (c *typeAssertChainChecker) EnterFunc(fn *ast.FuncDecl) bool { - if fn.Body == nil { - return false - } - c.visited = make(map[*ast.IfStmt]bool) - return true -} - -func (c *typeAssertChainChecker) VisitStmt(stmt ast.Stmt) { - ifstmt, ok := stmt.(*ast.IfStmt) - if !ok || c.visited[ifstmt] || ifstmt.Init == nil { - return - } - assertion := c.getTypeAssert(ifstmt) - if assertion == nil { - return - } - c.cause = ifstmt - c.checkIfStmt(ifstmt, assertion) -} - -func (c *typeAssertChainChecker) getTypeAssert(ifstmt *ast.IfStmt) *ast.TypeAssertExpr { - assign := astcast.ToAssignStmt(ifstmt.Init) - if len(assign.Lhs) != 2 || len(assign.Rhs) != 1 { - return nil - } - if !astp.IsIdent(assign.Lhs[0]) || assign.Tok != token.DEFINE { - return nil - } - if !astequal.Expr(assign.Lhs[1], ifstmt.Cond) { - return nil - } - - assertion, ok := assign.Rhs[0].(*ast.TypeAssertExpr) - if !ok { - return nil - } - return assertion -} - -func (c *typeAssertChainChecker) checkIfStmt(stmt *ast.IfStmt, assertion *ast.TypeAssertExpr) { - if c.countTypeAssertions(stmt, assertion) >= 2 { - c.warn() - } -} - -func (c *typeAssertChainChecker) countTypeAssertions(stmt *ast.IfStmt, assertion *ast.TypeAssertExpr) int { - c.typeSet.Clear() - - count := 1 - x := assertion.X - c.typeSet.Insert(assertion.Type) - for { - e, ok := stmt.Else.(*ast.IfStmt) - if !ok { - return count - } - assertion = c.getTypeAssert(e) - if assertion == nil { - return count - } - if !c.typeSet.Insert(assertion.Type) { - // Asserted type is duplicated. - // Type switch does not permit duplicate cases, - // so give up. - return 0 - } - if !astequal.Expr(x, assertion.X) { - // Mixed type asserting chain. - // Can't be easily translated to a type switch. - return 0 - } - stmt = e - count++ - c.visited[e] = true - } -} - -func (c *typeAssertChainChecker) warn() { - c.ctx.Warn(c.cause, "rewrite if-else to type switch statement") -} diff --git a/vendor/github.com/go-critic/go-critic/checkers/typeSwitchVar_checker.go b/vendor/github.com/go-critic/go-critic/checkers/typeSwitchVar_checker.go index a113597b6a72..527383a7641e 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/typeSwitchVar_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/typeSwitchVar_checker.go @@ -83,6 +83,6 @@ func (c *typeSwitchVarChecker) checkTypeSwitch(root *ast.TypeSwitchStmt) { } } -func (c *typeSwitchVarChecker) warn(n ast.Node, caseIndex int) { - c.ctx.Warn(n, "case %d can benefit from type switch with assignment", caseIndex) +func (c *typeSwitchVarChecker) warn(node ast.Node, caseIndex int) { + c.ctx.Warn(node, "case %d can benefit from type switch with assignment", caseIndex) } diff --git a/vendor/github.com/go-critic/go-critic/checkers/underef_checker.go b/vendor/github.com/go-critic/go-critic/checkers/underef_checker.go index dfc6077bbf1d..3c248ba8e17b 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/underef_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/underef_checker.go @@ -4,9 +4,9 @@ import ( "go/ast" "go/types" + "github.com/go-critic/go-critic/checkers/internal/lintutil" "github.com/go-lintpack/lintpack" "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astcast" "github.com/go-toolsmith/astp" ) @@ -45,7 +45,7 @@ type underefChecker struct { func (c *underefChecker) VisitExpr(expr ast.Expr) { switch n := expr.(type) { case *ast.SelectorExpr: - expr := astcast.ToParenExpr(n.X) + expr := lintutil.AsParenExpr(n.X) if c.skipRecvDeref && c.isPtrRecvMethodCall(n.Sel) { return } @@ -56,7 +56,7 @@ func (c *underefChecker) VisitExpr(expr ast.Expr) { } } case *ast.IndexExpr: - expr := astcast.ToParenExpr(n.X) + expr := lintutil.AsParenExpr(n.X) if expr, ok := expr.X.(*ast.StarExpr); ok { if !c.checkStarExpr(expr) { return diff --git a/vendor/github.com/go-critic/go-critic/checkers/unlambda_checker.go b/vendor/github.com/go-critic/go-critic/checkers/unlambda_checker.go index 846bb14d254c..e7231ce8b4e8 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/unlambda_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/unlambda_checker.go @@ -4,9 +4,9 @@ import ( "go/ast" "go/types" + "github.com/go-critic/go-critic/checkers/internal/lintutil" "github.com/go-lintpack/lintpack" "github.com/go-lintpack/lintpack/astwalk" - "github.com/go-toolsmith/astcast" "github.com/go-toolsmith/astequal" ) @@ -39,14 +39,11 @@ func (c *unlambdaChecker) VisitExpr(x ast.Expr) { return } - result := astcast.ToCallExpr(ret.Results[0]) + result := lintutil.AsCallExpr(ret.Results[0]) callable := qualifiedName(result.Fun) if callable == "" { return // Skip tricky cases; only handle simple calls } - if isBuiltin(callable) { - return // See #762 - } fnType := c.ctx.TypesInfo.TypeOf(fn) resultType := c.ctx.TypesInfo.TypeOf(result.Fun) if !types.Identical(fnType, resultType) { diff --git a/vendor/github.com/go-critic/go-critic/checkers/unnamedResult_checker.go b/vendor/github.com/go-critic/go-critic/checkers/unnamedResult_checker.go index 09423250ad47..0a575e818f12 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/unnamedResult_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/unnamedResult_checker.go @@ -44,7 +44,7 @@ func (c *unnamedResultChecker) VisitFuncDecl(decl *ast.FuncDecl) { switch { case results == nil: return // Function has no results - case len(results.List) != 0 && results.List[0].Names != nil: + case len(results.List) > 0 && results.List[0].Names != nil: return // Skip named results } diff --git a/vendor/github.com/go-critic/go-critic/checkers/utils.go b/vendor/github.com/go-critic/go-critic/checkers/utils.go index ba4777dbddad..b59e9188c017 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/utils.go +++ b/vendor/github.com/go-critic/go-critic/checkers/utils.go @@ -8,242 +8,9 @@ import ( "github.com/go-lintpack/lintpack" ) -// goStdlib contains `go list std` command output list. -// Used to detect packages that belong to standard Go packages distribution. -var goStdlib = map[string]bool{ - "archive/tar": true, - "archive/zip": true, - "bufio": true, - "bytes": true, - "compress/bzip2": true, - "compress/flate": true, - "compress/gzip": true, - "compress/lzw": true, - "compress/zlib": true, - "container/heap": true, - "container/list": true, - "container/ring": true, - "context": true, - "crypto": true, - "crypto/aes": true, - "crypto/cipher": true, - "crypto/des": true, - "crypto/dsa": true, - "crypto/ecdsa": true, - "crypto/elliptic": true, - "crypto/hmac": true, - "crypto/internal/randutil": true, - "crypto/internal/subtle": true, - "crypto/md5": true, - "crypto/rand": true, - "crypto/rc4": true, - "crypto/rsa": true, - "crypto/sha1": true, - "crypto/sha256": true, - "crypto/sha512": true, - "crypto/subtle": true, - "crypto/tls": true, - "crypto/x509": true, - "crypto/x509/pkix": true, - "database/sql": true, - "database/sql/driver": true, - "debug/dwarf": true, - "debug/elf": true, - "debug/gosym": true, - "debug/macho": true, - "debug/pe": true, - "debug/plan9obj": true, - "encoding": true, - "encoding/ascii85": true, - "encoding/asn1": true, - "encoding/base32": true, - "encoding/base64": true, - "encoding/binary": true, - "encoding/csv": true, - "encoding/gob": true, - "encoding/hex": true, - "encoding/json": true, - "encoding/pem": true, - "encoding/xml": true, - "errors": true, - "expvar": true, - "flag": true, - "fmt": true, - "go/ast": true, - "go/build": true, - "go/constant": true, - "go/doc": true, - "go/format": true, - "go/importer": true, - "go/internal/gccgoimporter": true, - "go/internal/gcimporter": true, - "go/internal/srcimporter": true, - "go/parser": true, - "go/printer": true, - "go/scanner": true, - "go/token": true, - "go/types": true, - "hash": true, - "hash/adler32": true, - "hash/crc32": true, - "hash/crc64": true, - "hash/fnv": true, - "html": true, - "html/template": true, - "image": true, - "image/color": true, - "image/color/palette": true, - "image/draw": true, - "image/gif": true, - "image/internal/imageutil": true, - "image/jpeg": true, - "image/png": true, - "index/suffixarray": true, - "internal/bytealg": true, - "internal/cpu": true, - "internal/nettrace": true, - "internal/poll": true, - "internal/race": true, - "internal/singleflight": true, - "internal/syscall/unix": true, - "internal/syscall/windows": true, - "internal/syscall/windows/registry": true, - "internal/syscall/windows/sysdll": true, - "internal/testenv": true, - "internal/testlog": true, - "internal/trace": true, - "io": true, - "io/ioutil": true, - "log": true, - "log/syslog": true, - "math": true, - "math/big": true, - "math/bits": true, - "math/cmplx": true, - "math/rand": true, - "mime": true, - "mime/multipart": true, - "mime/quotedprintable": true, - "net": true, - "net/http": true, - "net/http/cgi": true, - "net/http/cookiejar": true, - "net/http/fcgi": true, - "net/http/httptest": true, - "net/http/httptrace": true, - "net/http/httputil": true, - "net/http/internal": true, - "net/http/pprof": true, - "net/internal/socktest": true, - "net/mail": true, - "net/rpc": true, - "net/rpc/jsonrpc": true, - "net/smtp": true, - "net/textproto": true, - "net/url": true, - "os": true, - "os/exec": true, - "os/signal": true, - "os/signal/internal/pty": true, - "os/user": true, - "path": true, - "path/filepath": true, - "plugin": true, - "reflect": true, - "regexp": true, - "regexp/syntax": true, - "runtime": true, - "runtime/cgo": true, - "runtime/debug": true, - "runtime/internal/atomic": true, - "runtime/internal/sys": true, - "runtime/pprof": true, - "runtime/pprof/internal/profile": true, - "runtime/race": true, - "runtime/trace": true, - "sort": true, - "strconv": true, - "strings": true, - "sync": true, - "sync/atomic": true, - "syscall": true, - "testing": true, - "testing/internal/testdeps": true, - "testing/iotest": true, - "testing/quick": true, - "text/scanner": true, - "text/tabwriter": true, - "text/template": true, - "text/template/parse": true, - "time": true, - "unicode": true, - "unicode/utf16": true, - "unicode/utf8": true, - "unsafe": true, -} - -var goBuiltins = map[string]bool{ - // Types - "bool": true, - "byte": true, - "complex64": true, - "complex128": true, - "error": true, - "float32": true, - "float64": true, - "int": true, - "int8": true, - "int16": true, - "int32": true, - "int64": true, - "rune": true, - "string": true, - "uint": true, - "uint8": true, - "uint16": true, - "uint32": true, - "uint64": true, - "uintptr": true, - - // Constants - "true": true, - "false": true, - "iota": true, - - // Zero value - "nil": true, - - // Functions - "append": true, - "cap": true, - "close": true, - "complex": true, - "copy": true, - "delete": true, - "imag": true, - "len": true, - "make": true, - "new": true, - "panic": true, - "print": true, - "println": true, - "real": true, - "recover": true, -} - -// isBuiltin reports whether sym belongs to a predefined identifier set. -func isBuiltin(sym string) bool { - return goBuiltins[sym] -} - // isStdlibPkg reports whether pkg is a package from the Go standard library. func isStdlibPkg(pkg *types.Package) bool { - return pkg != nil && goStdlib[pkg.Path()] -} - -// isExampleTestFunc reports whether FuncDecl looks like a testable example function. -func isExampleTestFunc(fn *ast.FuncDecl) bool { - return len(fn.Type.Params.List) == 0 && strings.HasPrefix(fn.Name.String(), "Example") + return pkg != nil && pkg.Path() == pkg.Name() } // isUnitTestFunc reports whether FuncDecl declares testing function. diff --git a/vendor/github.com/go-critic/go-critic/checkers/wrapperFunc_checker.go b/vendor/github.com/go-critic/go-critic/checkers/wrapperFunc_checker.go index bba82e5ee856..e2308ff4b675 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/wrapperFunc_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/wrapperFunc_checker.go @@ -39,10 +39,6 @@ func init() { "sync.WaitGroup.Add => WaitGroup.Done": { {0, "-1"}, }, - - "bytes.Buffer.Truncate => Buffer.Reset": { - {0, "0"}, - }, } pkgPatterns := map[string][]arg{ @@ -50,9 +46,6 @@ func init() { {0, "http.NotFound"}, }, - "strings.SplitN => strings.Split": { - {2, "-1"}, - }, "strings.Replace => strings.ReplaceAll": { {3, "-1"}, }, @@ -63,9 +56,6 @@ func init() { {0, "unicode.ToTitle"}, }, - "bytes.SplitN => bytes.Split": { - {2, "-1"}, - }, "bytes.Replace => bytes.ReplaceAll": { {3, "-1"}, }, diff --git a/vendor/github.com/go-critic/go-critic/checkers/yodaStyleExpr_checker.go b/vendor/github.com/go-critic/go-critic/checkers/yodaStyleExpr_checker.go index ddd3099fd0be..06577788e0ca 100644 --- a/vendor/github.com/go-critic/go-critic/checkers/yodaStyleExpr_checker.go +++ b/vendor/github.com/go-critic/go-critic/checkers/yodaStyleExpr_checker.go @@ -33,8 +33,7 @@ func (c *yodaStyleExprChecker) VisitLocalExpr(expr ast.Expr) { if !ok { return } - switch binexpr.Op { - case token.EQL, token.NEQ, token.LSS, token.LEQ, token.GEQ, token.GTR: + if binexpr.Op == token.EQL || binexpr.Op == token.NEQ { if c.isConstExpr(binexpr.X) && !c.isConstExpr(binexpr.Y) { c.warn(binexpr) } @@ -45,22 +44,8 @@ func (c *yodaStyleExprChecker) isConstExpr(expr ast.Expr) bool { return qualifiedName(expr) == "nil" || astp.IsBasicLit(expr) } -func (c *yodaStyleExprChecker) invert(expr *ast.BinaryExpr) { - expr.X, expr.Y = expr.Y, expr.X - switch expr.Op { - case token.LSS: - expr.Op = token.GEQ - case token.LEQ: - expr.Op = token.GTR - case token.GEQ: - expr.Op = token.LSS - case token.GTR: - expr.Op = token.LEQ - } -} - func (c *yodaStyleExprChecker) warn(expr *ast.BinaryExpr) { e := astcopy.BinaryExpr(expr) - c.invert(e) + e.X, e.Y = e.Y, e.X c.ctx.Warn(expr, "consider to change order in expression to %s", e) } diff --git a/vendor/github.com/go-toolsmith/astcast/.travis.yml b/vendor/github.com/go-toolsmith/astcast/.travis.yml deleted file mode 100644 index c32ac00627d6..000000000000 --- a/vendor/github.com/go-toolsmith/astcast/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: go -go: - - 1.x -install: - - # Prevent default install action "go get -t -v ./...". -script: - - go get -t -v ./... - - go tool vet . - - go test -v -race ./... diff --git a/vendor/github.com/go-toolsmith/astcast/go.mod b/vendor/github.com/go-toolsmith/astcast/go.mod deleted file mode 100644 index 3e431993e3b0..000000000000 --- a/vendor/github.com/go-toolsmith/astcast/go.mod +++ /dev/null @@ -1,6 +0,0 @@ -module github.com/go-toolsmith/astcast - -require ( - github.com/go-toolsmith/astequal v1.0.0 // indirect - github.com/go-toolsmith/strparse v1.0.0 -) diff --git a/vendor/github.com/go-toolsmith/astcast/go.sum b/vendor/github.com/go-toolsmith/astcast/go.sum deleted file mode 100644 index aa0857030227..000000000000 --- a/vendor/github.com/go-toolsmith/astcast/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/go-toolsmith/astequal v1.0.0 h1:4zxD8j3JRFNyLN46lodQuqz3xdKSrur7U/sr0SDS/gQ= -github.com/go-toolsmith/astequal v1.0.0/go.mod h1:H+xSiq0+LtiDC11+h1G32h7Of5O3CYFJ99GVbS5lDKY= -github.com/go-toolsmith/strparse v1.0.0 h1:Vcw78DnpCAKlM20kSbAyO4mPfJn/lyYA4BJUDxe2Jb4= -github.com/go-toolsmith/strparse v1.0.0/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8= diff --git a/vendor/github.com/go-toolsmith/astcopy/go.mod b/vendor/github.com/go-toolsmith/astcopy/go.mod index 6f3b3027a8bc..f20e586e5950 100644 --- a/vendor/github.com/go-toolsmith/astcopy/go.mod +++ b/vendor/github.com/go-toolsmith/astcopy/go.mod @@ -1,6 +1 @@ module github.com/go-toolsmith/astcopy - -require ( - github.com/go-toolsmith/astequal v1.0.0 - github.com/go-toolsmith/strparse v1.0.0 -) diff --git a/vendor/github.com/go-toolsmith/astcopy/go.sum b/vendor/github.com/go-toolsmith/astcopy/go.sum deleted file mode 100644 index aa0857030227..000000000000 --- a/vendor/github.com/go-toolsmith/astcopy/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/go-toolsmith/astequal v1.0.0 h1:4zxD8j3JRFNyLN46lodQuqz3xdKSrur7U/sr0SDS/gQ= -github.com/go-toolsmith/astequal v1.0.0/go.mod h1:H+xSiq0+LtiDC11+h1G32h7Of5O3CYFJ99GVbS5lDKY= -github.com/go-toolsmith/strparse v1.0.0 h1:Vcw78DnpCAKlM20kSbAyO4mPfJn/lyYA4BJUDxe2Jb4= -github.com/go-toolsmith/strparse v1.0.0/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8= diff --git a/vendor/github.com/go-toolsmith/astp/go.mod b/vendor/github.com/go-toolsmith/astp/go.mod index 023a09392f98..32da1a33f753 100644 --- a/vendor/github.com/go-toolsmith/astp/go.mod +++ b/vendor/github.com/go-toolsmith/astp/go.mod @@ -1,6 +1 @@ module github.com/go-toolsmith/astp - -require ( - github.com/go-toolsmith/astequal v1.0.0 // indirect - github.com/go-toolsmith/strparse v1.0.0 -) diff --git a/vendor/github.com/go-toolsmith/astp/go.sum b/vendor/github.com/go-toolsmith/astp/go.sum deleted file mode 100644 index aa0857030227..000000000000 --- a/vendor/github.com/go-toolsmith/astp/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/go-toolsmith/astequal v1.0.0 h1:4zxD8j3JRFNyLN46lodQuqz3xdKSrur7U/sr0SDS/gQ= -github.com/go-toolsmith/astequal v1.0.0/go.mod h1:H+xSiq0+LtiDC11+h1G32h7Of5O3CYFJ99GVbS5lDKY= -github.com/go-toolsmith/strparse v1.0.0 h1:Vcw78DnpCAKlM20kSbAyO4mPfJn/lyYA4BJUDxe2Jb4= -github.com/go-toolsmith/strparse v1.0.0/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8= diff --git a/vendor/github.com/go-toolsmith/typep/.travis.yml b/vendor/github.com/go-toolsmith/typep/.travis.yml deleted file mode 100644 index c32ac00627d6..000000000000 --- a/vendor/github.com/go-toolsmith/typep/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: go -go: - - 1.x -install: - - # Prevent default install action "go get -t -v ./...". -script: - - go get -t -v ./... - - go tool vet . - - go test -v -race ./... diff --git a/vendor/github.com/go-toolsmith/typep/go.mod b/vendor/github.com/go-toolsmith/typep/go.mod deleted file mode 100644 index 197a57d30687..000000000000 --- a/vendor/github.com/go-toolsmith/typep/go.mod +++ /dev/null @@ -1 +0,0 @@ -module github.com/go-toolsmith/typep diff --git a/vendor/github.com/golangci/ineffassign/ineffassign.go b/vendor/github.com/golangci/ineffassign/ineffassign.go index 5cda3982d030..3b61b36f2b02 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) && isZeroInitializer(n.Rhs[i]) { + if n.Tok == token.DEFINE && i < len(n.Rhs) && isZeroLiteral(n.Rhs[i]) { bld.use(id) } else { bld.assign(id) @@ -278,17 +278,18 @@ func (bld *builder) Visit(n ast.Node) ast.Visitor { for _, x := range n.Results { bld.walk(x) } - 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) + 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) } + bld.use(id) } } - bld.newBlock() case *ast.SendStmt: bld.maybePanic() return bld @@ -349,30 +350,15 @@ func (bld *builder) Visit(n ast.Node) ast.Visitor { return nil } -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] +func isZeroLiteral(x ast.Expr) bool { + b, ok := x.(*ast.BasicLit) + if !ok { + return false } - - 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 + switch b.Value { + case "0", "0.0", "0.", ".0", `""`: + return true } - return false } diff --git a/vendor/modules.txt b/vendor/modules.txt index 0cb94687ff8f..dc2c8fa821b4 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -10,7 +10,7 @@ github.com/davecgh/go-spew/spew github.com/fatih/color # github.com/fsnotify/fsnotify v1.4.7 github.com/fsnotify/fsnotify -# github.com/go-critic/go-critic v0.0.0-20181204210945-1df300866540 +# github.com/go-critic/go-critic v0.3.4 github.com/go-critic/go-critic/checkers github.com/go-critic/go-critic/checkers/internal/lintutil # github.com/go-lintpack/lintpack v0.5.2 @@ -19,19 +19,19 @@ github.com/go-lintpack/lintpack/astwalk # github.com/go-ole/go-ole v1.2.1 github.com/go-ole/go-ole github.com/go-ole/go-ole/oleutil -# github.com/go-toolsmith/astcast v1.0.0 +# github.com/go-toolsmith/astcast v0.0.0-20181028201508-b7a89ed70af1 github.com/go-toolsmith/astcast -# github.com/go-toolsmith/astcopy v1.0.0 +# github.com/go-toolsmith/astcopy v0.0.0-20180903214859-79b422d080c4 github.com/go-toolsmith/astcopy # github.com/go-toolsmith/astequal v1.0.0 github.com/go-toolsmith/astequal # github.com/go-toolsmith/astfmt v1.0.0 github.com/go-toolsmith/astfmt -# github.com/go-toolsmith/astp v1.0.0 +# github.com/go-toolsmith/astp v0.0.0-20180903215135-0af7e3c24f30 github.com/go-toolsmith/astp # github.com/go-toolsmith/strparse v1.0.0 github.com/go-toolsmith/strparse -# github.com/go-toolsmith/typep v1.0.0 +# github.com/go-toolsmith/typep v0.0.0-20181030061450-d63dc7650676 github.com/go-toolsmith/typep # github.com/gobwas/glob v0.2.3 github.com/gobwas/glob @@ -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-42439a7714cc +# github.com/golangci/ineffassign v0.0.0-20180808204949-2ee8f2867dde github.com/golangci/ineffassign # github.com/golangci/lint-1 v0.0.0-20180610141402-ee948d087217 github.com/golangci/lint-1