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, 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