diff --git a/pkg/result/processors/autogenerated_exclude.go b/pkg/result/processors/autogenerated_exclude.go index f52e9b2f..cc5883d9 100644 --- a/pkg/result/processors/autogenerated_exclude.go +++ b/pkg/result/processors/autogenerated_exclude.go @@ -126,7 +126,7 @@ func getDoc(filePath string) (string, error) { if strings.HasPrefix(line, "//") { //nolint:gocritic text := strings.TrimSpace(strings.TrimPrefix(line, "//")) docLines = append(docLines, text) - } else if line == "" { + } else if line == "" || strings.HasPrefix(line, "package") { // go to next line } else { break diff --git a/pkg/result/processors/autogenerated_exclude_test.go b/pkg/result/processors/autogenerated_exclude_test.go index 89cfbd09..0ace0103 100644 --- a/pkg/result/processors/autogenerated_exclude_test.go +++ b/pkg/result/processors/autogenerated_exclude_test.go @@ -69,10 +69,26 @@ func TestIsAutogeneratedDetection(t *testing.T) { } func TestGetDoc(t *testing.T) { - const expectedDoc = `first line + testCases := []struct { + fpath string + doc string + }{ + { + fpath: filepath.Join("testdata", "autogen_exclude.go"), + doc: `first line second line -third line` - doc, err := getDoc(filepath.Join("testdata", "autogen_exclude.go")) - assert.NoError(t, err) - assert.Equal(t, expectedDoc, doc) +third line +and this text also`, + }, + { + fpath: filepath.Join("testdata", "autogen_exclude_doc.go"), + doc: `DO NOT EDIT`, + }, + } + + for _, tc := range testCases { + doc, err := getDoc(tc.fpath) + assert.NoError(t, err) + assert.Equal(t, tc.doc, doc) + } } diff --git a/pkg/result/processors/testdata/autogen_exclude.go b/pkg/result/processors/testdata/autogen_exclude.go index e2695998..f374f089 100644 --- a/pkg/result/processors/testdata/autogen_exclude.go +++ b/pkg/result/processors/testdata/autogen_exclude.go @@ -4,4 +4,4 @@ // third line package testdata // no this text -// and no this text too +// and this text also diff --git a/pkg/result/processors/testdata/autogen_exclude_doc.go b/pkg/result/processors/testdata/autogen_exclude_doc.go new file mode 100644 index 00000000..7eadceff --- /dev/null +++ b/pkg/result/processors/testdata/autogen_exclude_doc.go @@ -0,0 +1,10 @@ +package testdata + +// DO NOT EDIT + +import "fmt" + +// nolint +func PrintString(s string) { + fmt.Printf("%s", s) +}