From 2bbe9ff08f2d08086016c1d1a495843f6a1616da Mon Sep 17 00:00:00 2001 From: Denis Isaev Date: Mon, 9 Sep 2019 19:32:36 +0300 Subject: [PATCH] Fix funlen crash on cgo --- go.mod | 8 ++++++-- go.sum | 4 ++-- test/run_test.go | 10 +++++----- vendor/github.com/ultraware/funlen/main.go | 2 +- vendor/modules.txt | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index aa462b3b4399..89d74e5ebe83 100644 --- a/go.mod +++ b/go.mod @@ -65,5 +65,9 @@ require ( mvdan.cc/unparam v0.0.0-20190124213536-fbb59629db34 ) -// https://github.com/golang/tools/pull/139 -replace golang.org/x/tools => github.com/golangci/tools v0.0.0-20190713050349-979bdb7f8cc8 +replace ( + // https://github.com/ultraware/funlen/pull/1 + github.com/ultraware/funlen => github.com/golangci/funlen v0.0.0-20190909161642-5e59b9546114 + // https://github.com/golang/tools/pull/139 + golang.org/x/tools => github.com/golangci/tools v0.0.0-20190713050349-979bdb7f8cc8 +) diff --git a/go.sum b/go.sum index 2fcd2ddde6de..f9bfa128e76e 100644 --- a/go.sum +++ b/go.sum @@ -51,6 +51,8 @@ github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a h1:w8hkcTqaFpzKqonE9 github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a/go.mod h1:ryS0uhF+x9jgbj/N71xsEqODy9BN81/GonCZiOzirOk= github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6 h1:i2jIkQFb8RG45DuQs+ElyROY848cSJIoIkBM+7XXypA= github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6/go.mod h1:DbHgvLiFKX1Sh2T1w8Q/h4NAI8MHIpzCdnBUDTXU3I0= +github.com/golangci/funlen v0.0.0-20190909161642-5e59b9546114 h1:eubR6yxVUUlbUuBBn1ONXalxuCjCrDfKvRc0eF6Xnio= +github.com/golangci/funlen v0.0.0-20190909161642-5e59b9546114/go.mod h1:kJMYlbyWK6uaK+J3BjNrQMk0t3CgLgsXgQnOlS4iGeg= github.com/golangci/go-misc v0.0.0-20180628070357-927a3d87b613 h1:9kfjN3AdxcbsZBf8NjltjWihK2QfBBBZuv91cMFfDHw= github.com/golangci/go-misc v0.0.0-20180628070357-927a3d87b613/go.mod h1:SyvUF2NxV+sN8upjjeVYr5W7tyxaT1JVtvhKhOn2ii8= github.com/golangci/go-tools v0.0.0-20190318055746-e32c54105b7c h1:/7detzz5stiXWPzkTlPTzkBEIIE4WGpppBJYjKqBiPI= @@ -162,8 +164,6 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/timakin/bodyclose v0.0.0-00010101000000-87058b9bfcec h1:Ha5Eixh5Dgi14hDFFWsxoB/jR95rHjB1biKdK9VKkbQ= github.com/timakin/bodyclose v0.0.0-00010101000000-87058b9bfcec/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk= -github.com/ultraware/funlen v0.0.1 h1:UeC9tpM4wNWzUJfan8z9sFE4QCzjjzlCZmuJN+aOkH0= -github.com/ultraware/funlen v0.0.1/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA= 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= diff --git a/test/run_test.go b/test/run_test.go index 88ac071e8226..f42f61371208 100644 --- a/test/run_test.go +++ b/test/run_test.go @@ -54,16 +54,16 @@ func TestTestsAreLintedByDefault(t *testing.T) { } func TestCgoOk(t *testing.T) { - testshared.NewLintRunner(t).Run("--enable-all", getTestDataDir("cgo")).ExpectNoIssues() + testshared.NewLintRunner(t).Run("--no-config", "--enable-all", getTestDataDir("cgo")).ExpectNoIssues() } func TestCgoWithIssues(t *testing.T) { - testshared.NewLintRunner(t).Run("--enable-all", getTestDataDir("cgo_with_issues")). + testshared.NewLintRunner(t).Run("--no-config", "--enable-all", getTestDataDir("cgo_with_issues")). ExpectHasIssue("Printf format %t has arg cs of wrong type") } func TestUnsafeOk(t *testing.T) { - testshared.NewLintRunner(t).Run("--enable-all", getTestDataDir("unsafe")).ExpectNoIssues() + testshared.NewLintRunner(t).Run("--no-config", "--enable-all", getTestDataDir("unsafe")).ExpectNoIssues() } func TestGovetCustomFormatter(t *testing.T) { @@ -134,8 +134,8 @@ func TestConfigFileIsDetected(t *testing.T) { func TestEnableAllFastAndEnableCanCoexist(t *testing.T) { r := testshared.NewLintRunner(t) - r.Run(withCommonRunArgs("--fast", "--enable-all", "--enable=typecheck")...).ExpectNoIssues() - r.Run(withCommonRunArgs("--enable-all", "--enable=typecheck")...).ExpectExitCode(exitcodes.Failure) + r.Run(withCommonRunArgs("--no-config", "--fast", "--enable-all", "--enable=typecheck")...).ExpectNoIssues() + r.Run(withCommonRunArgs("--no-config", "--enable-all", "--enable=typecheck")...).ExpectExitCode(exitcodes.Failure) } func TestEnabledPresetsAreNotDuplicated(t *testing.T) { diff --git a/vendor/github.com/ultraware/funlen/main.go b/vendor/github.com/ultraware/funlen/main.go index 5a1ceeb791bd..19e48e2ff74b 100644 --- a/vendor/github.com/ultraware/funlen/main.go +++ b/vendor/github.com/ultraware/funlen/main.go @@ -22,7 +22,7 @@ func Run(file *ast.File, fset *token.FileSet, lineLimit, stmtLimit int) []Messag var msgs []Message for _, f := range file.Decls { decl, ok := f.(*ast.FuncDecl) - if !ok { + if !ok || decl.Body == nil { // decl.Body can be nil for e.g. cgo continue } diff --git a/vendor/modules.txt b/vendor/modules.txt index ff5df2b1b7aa..84c76869ac3d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -183,7 +183,7 @@ github.com/stretchr/testify/assert github.com/stretchr/testify/require # github.com/timakin/bodyclose v0.0.0-00010101000000-87058b9bfcec github.com/timakin/bodyclose/passes/bodyclose -# github.com/ultraware/funlen v0.0.1 +# github.com/ultraware/funlen v0.0.1 => github.com/golangci/funlen v0.0.0-20190909161642-5e59b9546114 github.com/ultraware/funlen # github.com/valyala/bytebufferpool v1.0.0 github.com/valyala/bytebufferpool