Skip to content

Commit

Permalink
Fix IsGeneratedFile
Browse files Browse the repository at this point in the history
  • Loading branch information
tenntenn committed Nov 23, 2020
1 parent ecea7d7 commit f81035d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ var genCommentRegexp = regexp.MustCompile(`^// Code generated .* DO NOT EDIT\.$`
// IsGeneratedFile reports whether the file has been generated automatically.
// If file is nil, IsGeneratedFile will return false.
func IsGeneratedFile(file *ast.File) bool {
if file == nil || file.Doc == nil {
if file == nil || len(file.Comments) == 0 {
return false
}
return genCommentRegexp.MatchString(file.Doc.List[0].Text)
return genCommentRegexp.MatchString(file.Comments[0].List[0].Text)
}
1 change: 1 addition & 0 deletions file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestIsGeneratedFile(t *testing.T) {
"true": {"// Code generated by test; DO NOT EDIT.", true},
"false": {"//Code generated by test; DO NOT EDIT.", false},
"empty": {"", false},
"blank": {"// Code generated by test; DO NOT EDIT.\n", true},
}

for name, tt := range cases {
Expand Down

0 comments on commit f81035d

Please sign in to comment.