-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc_comments_test.go
More file actions
47 lines (44 loc) · 1 KB
/
Copy pathdoc_comments_test.go
File metadata and controls
47 lines (44 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"go/ast"
"go/parser"
"go/token"
"io/fs"
"path/filepath"
"strings"
"testing"
)
func TestNonTestFunctionsHaveDocComments(t *testing.T) {
err := filepath.WalkDir(".", func(path string, entry fs.DirEntry, walkErr error) error {
if walkErr != nil {
return walkErr
}
if entry.IsDir() {
if path != "." && strings.HasPrefix(entry.Name(), ".") {
return filepath.SkipDir
}
return nil
}
if !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {
return nil
}
fileSet := token.NewFileSet()
file, err := parser.ParseFile(fileSet, path, nil, parser.ParseComments)
if err != nil {
return err
}
for _, declaration := range file.Decls {
function, ok := declaration.(*ast.FuncDecl)
if !ok {
continue
}
if function.Doc == nil || strings.TrimSpace(function.Doc.Text()) == "" {
t.Errorf("%s: %s lacks a doc comment", fileSet.Position(function.Pos()), function.Name.Name)
}
}
return nil
})
if err != nil {
t.Fatal(err)
}
}