Skip to content

Commit dfa0013

Browse files
Fix: goheader linter can throw nil pointer exception in case of a source file has not issues (#1209)
* fix potential nil pointer exception Signed-off-by: denis-tingajkin <[email protected]> * add test to cover Signed-off-by: denis-tingajkin <[email protected]>
1 parent afa9be6 commit dfa0013

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

pkg/golinters/goheader.go

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ func NewGoHeader() *goanalysis.Linter {
5151
var res []goanalysis.Issue
5252
for _, file := range pass.Files {
5353
i := a.Analyze(file)
54+
if i == nil {
55+
continue
56+
}
5457
issue := result.Issue{
5558
Pos: token.Position{
5659
Line: i.Location().Line + 1,

test/linters_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ func extractRunContextFromComments(t *testing.T, sourcePath string) *runContext
193193
skipMultilineComment(scanner)
194194
continue
195195
}
196+
if strings.TrimSpace(line) == "" {
197+
continue
198+
}
196199
if !strings.HasPrefix(line, "//") {
197200
return rc
198201
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*MY TITLE!*/ // ERROR "Expected:TITLE., Actual: TITLE!"
2+
23
//args: -Egoheader
34
//config_path: testdata/configs/go-header.yml
45
package testdata

test/testdata/go-header_good.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*MY TITLE.*/
2+
3+
//args: -Egoheader
4+
//config_path: testdata/configs/go-header.yml
5+
package testdata

0 commit comments

Comments
 (0)