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 <denis.tingajkin@xored.com> * add test to cover Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>
This commit is contained in:
parent
afa9be632b
commit
dfa0013583
@ -51,6 +51,9 @@ func NewGoHeader() *goanalysis.Linter {
|
|||||||
var res []goanalysis.Issue
|
var res []goanalysis.Issue
|
||||||
for _, file := range pass.Files {
|
for _, file := range pass.Files {
|
||||||
i := a.Analyze(file)
|
i := a.Analyze(file)
|
||||||
|
if i == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
issue := result.Issue{
|
issue := result.Issue{
|
||||||
Pos: token.Position{
|
Pos: token.Position{
|
||||||
Line: i.Location().Line + 1,
|
Line: i.Location().Line + 1,
|
||||||
|
@ -193,6 +193,9 @@ func extractRunContextFromComments(t *testing.T, sourcePath string) *runContext
|
|||||||
skipMultilineComment(scanner)
|
skipMultilineComment(scanner)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if strings.TrimSpace(line) == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if !strings.HasPrefix(line, "//") {
|
if !strings.HasPrefix(line, "//") {
|
||||||
return rc
|
return rc
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*MY TITLE!*/ // ERROR "Expected:TITLE., Actual: TITLE!"
|
/*MY TITLE!*/ // ERROR "Expected:TITLE., Actual: TITLE!"
|
||||||
|
|
||||||
//args: -Egoheader
|
//args: -Egoheader
|
||||||
//config_path: testdata/configs/go-header.yml
|
//config_path: testdata/configs/go-header.yml
|
||||||
package testdata
|
package testdata
|
5
test/testdata/go-header_good.go
vendored
Normal file
5
test/testdata/go-header_good.go
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/*MY TITLE.*/
|
||||||
|
|
||||||
|
//args: -Egoheader
|
||||||
|
//config_path: testdata/configs/go-header.yml
|
||||||
|
package testdata
|
Loading…
x
Reference in New Issue
Block a user