From eb6fa9f1c969304e59e3449163eee8a2376bf116 Mon Sep 17 00:00:00 2001 From: denis-tingajkin Date: Sun, 5 Jul 2020 13:06:02 +0700 Subject: [PATCH 1/2] fix potential nil pointer exception Signed-off-by: denis-tingajkin --- pkg/golinters/goheader.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/golinters/goheader.go b/pkg/golinters/goheader.go index 152069fa00b0..8517e173d3f5 100644 --- a/pkg/golinters/goheader.go +++ b/pkg/golinters/goheader.go @@ -51,6 +51,9 @@ func NewGoHeader() *goanalysis.Linter { var res []goanalysis.Issue for _, file := range pass.Files { i := a.Analyze(file) + if i == nil { + continue + } issue := result.Issue{ Pos: token.Position{ Line: i.Location().Line + 1, From e2c0d603c417ab261c94839185ab303063a0f9f7 Mon Sep 17 00:00:00 2001 From: denis-tingajkin Date: Sun, 5 Jul 2020 13:09:58 +0700 Subject: [PATCH 2/2] add test to cover Signed-off-by: denis-tingajkin --- test/linters_test.go | 3 +++ test/testdata/{go-header.go => go-header_bad.go} | 1 + test/testdata/go-header_good.go | 5 +++++ 3 files changed, 9 insertions(+) rename test/testdata/{go-header.go => go-header_bad.go} (99%) create mode 100644 test/testdata/go-header_good.go diff --git a/test/linters_test.go b/test/linters_test.go index ebe58ae8e5fd..191744a81f49 100644 --- a/test/linters_test.go +++ b/test/linters_test.go @@ -193,6 +193,9 @@ func extractRunContextFromComments(t *testing.T, sourcePath string) *runContext skipMultilineComment(scanner) continue } + if strings.TrimSpace(line) == "" { + continue + } if !strings.HasPrefix(line, "//") { return rc } diff --git a/test/testdata/go-header.go b/test/testdata/go-header_bad.go similarity index 99% rename from test/testdata/go-header.go rename to test/testdata/go-header_bad.go index 6714a867de57..17c3099eaa2a 100644 --- a/test/testdata/go-header.go +++ b/test/testdata/go-header_bad.go @@ -1,4 +1,5 @@ /*MY TITLE!*/ // ERROR "Expected:TITLE., Actual: TITLE!" + //args: -Egoheader //config_path: testdata/configs/go-header.yml package testdata diff --git a/test/testdata/go-header_good.go b/test/testdata/go-header_good.go new file mode 100644 index 000000000000..0e1b4241903a --- /dev/null +++ b/test/testdata/go-header_good.go @@ -0,0 +1,5 @@ +/*MY TITLE.*/ + +//args: -Egoheader +//config_path: testdata/configs/go-header.yml +package testdata