Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: goheader linter can throw nil pointer exception in case of a source file has not issues #1209

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/golinters/goheader.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*MY TITLE.*/

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