Skip to content

Commit

Permalink
Fix: goheader linter can throw nil pointer exception in case of a sou…
Browse files Browse the repository at this point in the history
…rce file has not issues (#1209)

* fix potential nil pointer exception

Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>

* add test to cover

Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>
  • Loading branch information
denis-tingaikin committed Jul 5, 2020
1 parent afa9be6 commit dfa0013
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/golinters/goheader.go
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions test/linters_test.go
Expand Up @@ -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
}
Expand Down
@@ -1,4 +1,5 @@
/*MY TITLE!*/ // ERROR "Expected:TITLE., Actual: TITLE!"

//args: -Egoheader
//config_path: testdata/configs/go-header.yml
package testdata
5 changes: 5 additions & 0 deletions test/testdata/go-header_good.go
@@ -0,0 +1,5 @@
/*MY TITLE.*/

//args: -Egoheader
//config_path: testdata/configs/go-header.yml
package testdata

0 comments on commit dfa0013

Please sign in to comment.