diff --git a/main.go b/main.go index 8959fa5..77b38c8 100644 --- a/main.go +++ b/main.go @@ -355,6 +355,9 @@ func checkGeneratedCode(f *ast.File) bool { if ast.IsGenerated(f) { return true } + if f.Doc == nil { + return false + } for _, comm := range f.Doc.List { if strings.Contains(comm.Text, "@generated") { return true diff --git a/main_test.go b/main_test.go index 5994f9b..5f38da8 100644 --- a/main_test.go +++ b/main_test.go @@ -252,6 +252,10 @@ func TestCheckGeneratedCode(t *testing.T) { }, }, }, + { + name: "non-generated code with no package comment", + file: &ast.File{}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {