Fix autogen exclude for comments under package (#831)
This commit is contained in:
parent
2346cd8e56
commit
ecccb24cb7
@ -126,7 +126,7 @@ func getDoc(filePath string) (string, error) {
|
|||||||
if strings.HasPrefix(line, "//") { //nolint:gocritic
|
if strings.HasPrefix(line, "//") { //nolint:gocritic
|
||||||
text := strings.TrimSpace(strings.TrimPrefix(line, "//"))
|
text := strings.TrimSpace(strings.TrimPrefix(line, "//"))
|
||||||
docLines = append(docLines, text)
|
docLines = append(docLines, text)
|
||||||
} else if line == "" {
|
} else if line == "" || strings.HasPrefix(line, "package") {
|
||||||
// go to next line
|
// go to next line
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
|
@ -69,10 +69,26 @@ func TestIsAutogeneratedDetection(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetDoc(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
|
second line
|
||||||
third line`
|
third line
|
||||||
doc, err := getDoc(filepath.Join("testdata", "autogen_exclude.go"))
|
and this text also`,
|
||||||
assert.NoError(t, err)
|
},
|
||||||
assert.Equal(t, expectedDoc, doc)
|
{
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,4 @@
|
|||||||
// third line
|
// third line
|
||||||
|
|
||||||
package testdata // no this text
|
package testdata // no this text
|
||||||
// and no this text too
|
// and this text also
|
||||||
|
10
pkg/result/processors/testdata/autogen_exclude_doc.go
vendored
Normal file
10
pkg/result/processors/testdata/autogen_exclude_doc.go
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package testdata
|
||||||
|
|
||||||
|
// DO NOT EDIT
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// nolint
|
||||||
|
func PrintString(s string) {
|
||||||
|
fmt.Printf("%s", s)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user