Fix autogen exclude for comments under package (#831)

This commit is contained in:
Igor Zibarev 2019-10-22 06:49:47 +00:00 committed by Isaev Denis
parent 2346cd8e56
commit ecccb24cb7
4 changed files with 33 additions and 7 deletions

View File

@ -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

View File

@ -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)
}
}

View File

@ -4,4 +4,4 @@
// third line
package testdata // no this text
// and no this text too
// and this text also

View File

@ -0,0 +1,10 @@
package testdata
// DO NOT EDIT
import "fmt"
// nolint
func PrintString(s string) {
fmt.Printf("%s", s)
}