Skip to content

Commit a2fe91e

Browse files
authored
Merge pull request #40 from gostaticanalysis/fix-isgenfile
Fix IsGeneratedFile
2 parents ecea7d7 + f81035d commit a2fe91e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ var genCommentRegexp = regexp.MustCompile(`^// Code generated .* DO NOT EDIT\.$`
2323
// IsGeneratedFile reports whether the file has been generated automatically.
2424
// If file is nil, IsGeneratedFile will return false.
2525
func IsGeneratedFile(file *ast.File) bool {
26-
if file == nil || file.Doc == nil {
26+
if file == nil || len(file.Comments) == 0 {
2727
return false
2828
}
29-
return genCommentRegexp.MatchString(file.Doc.List[0].Text)
29+
return genCommentRegexp.MatchString(file.Comments[0].List[0].Text)
3030
}

file_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestIsGeneratedFile(t *testing.T) {
2020
"true": {"// Code generated by test; DO NOT EDIT.", true},
2121
"false": {"//Code generated by test; DO NOT EDIT.", false},
2222
"empty": {"", false},
23+
"blank": {"// Code generated by test; DO NOT EDIT.\n", true},
2324
}
2425

2526
for name, tt := range cases {

0 commit comments

Comments
 (0)