Skip to content

Commit 60f79ae

Browse files
authored
feat(.golangci.yaml): add godoclint linter (#3085)
Replace custom TestExportedSymbolsHaveDocs test with godoclint linter.
1 parent cb6a9da commit 60f79ae

File tree

6 files changed

+24
-74
lines changed

6 files changed

+24
-74
lines changed

.golangci.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,20 @@ linters:
3030
- unparam
3131
- unused
3232
- usetesting
33+
settings:
34+
godoclint:
35+
default: all
36+
options:
37+
max-len:
38+
length: 120
39+
exclusions:
40+
rules:
41+
- path: _test\.go$
42+
linters:
43+
- godoclint
44+
- path: internal/sidekick/sample/
45+
linters:
46+
- godoclint
47+
- path: internal/legacylibrarian/
48+
linters:
49+
- godoclint

all_test.go

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ package librarian
1717
import (
1818
"bytes"
1919
"errors"
20-
"go/ast"
21-
"go/parser"
22-
"go/token"
2320
"io"
2421
"io/fs"
2522
"os"
@@ -267,73 +264,3 @@ func rungo(t *testing.T, args ...string) {
267264
t.Fatalf("%v: %v\n%s", cmd, err, output)
268265
}
269266
}
270-
271-
func TestExportedSymbolsHaveDocs(t *testing.T) {
272-
packageHasComment := make(map[string]bool)
273-
err := filepath.WalkDir(".", func(path string, d os.DirEntry, err error) error {
274-
if err != nil || d.IsDir() || !strings.HasSuffix(path, ".go") ||
275-
strings.HasSuffix(path, "_test.go") || strings.HasSuffix(path, ".pb.go") || strings.Contains(path, "testdata") {
276-
return nil
277-
}
278-
279-
fset := token.NewFileSet()
280-
node, err := parser.ParseFile(fset, path, nil, parser.ParseComments)
281-
if err != nil {
282-
t.Errorf("failed to parse file %q: %v", path, err)
283-
return nil
284-
}
285-
286-
recordPackageCommentStatus(t, node, packageHasComment)
287-
288-
// Visit every top-level declaration in the file.
289-
for _, decl := range node.Decls {
290-
gen, ok := decl.(*ast.GenDecl)
291-
if ok && (gen.Tok == token.TYPE || gen.Tok == token.VAR) {
292-
for _, spec := range gen.Specs {
293-
switch s := spec.(type) {
294-
case *ast.TypeSpec:
295-
checkDoc(t, s.Name, gen.Doc, path)
296-
case *ast.ValueSpec:
297-
for _, name := range s.Names {
298-
checkDoc(t, name, gen.Doc, path)
299-
}
300-
}
301-
}
302-
}
303-
if fn, ok := decl.(*ast.FuncDecl); ok {
304-
checkDoc(t, fn.Name, fn.Doc, path)
305-
}
306-
}
307-
return nil
308-
})
309-
if err != nil {
310-
t.Fatal(err)
311-
}
312-
313-
for name, hasPkgComment := range packageHasComment {
314-
if !hasPkgComment {
315-
t.Errorf("package %s does not have package comment", name)
316-
}
317-
}
318-
}
319-
320-
func checkDoc(t *testing.T, name *ast.Ident, doc *ast.CommentGroup, path string) {
321-
t.Helper()
322-
if !name.IsExported() {
323-
return
324-
}
325-
if doc == nil {
326-
t.Errorf("%s: %q is missing doc comment",
327-
path, name.Name)
328-
}
329-
}
330-
331-
// recordPackageCommentStatus updates the seen map with the package comment status for a given package, processing each
332-
// package only once.
333-
func recordPackageCommentStatus(t *testing.T, file *ast.File, packageHasComment map[string]bool) {
334-
t.Helper()
335-
pkg := file.Name.String()
336-
if !packageHasComment[pkg] {
337-
packageHasComment[pkg] = file.Doc != nil
338-
}
339-
}

cmd/sidekick/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// Command sidekick is a code generator for Google Cloud client libraries.
1516
package main
1617

1718
import (

internal/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// Package config provides types and functions for reading and writing
16+
// librarian.yaml configuration files.
1517
package config
1618

1719
import (

internal/language/generate.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// Package language provides library generation functionality for different
16+
// programming languages.
1517
package language
1618

1719
import (

internal/sidekick/parser/httprule/http_rule_parser.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ const (
299299
unreserved = alpha + digit + "-._~"
300300
)
301301

302-
// parseLiteral validates that the provided string conforms to the LITERAL definition, and returns a Literal type if it does.
302+
// parseLiteral validates that the provided string conforms to the LITERAL
303+
// definition, and returns a Literal type if it does.
303304
func parseLiteral(literal string) (*Literal, int, error) {
304305
var pos int
305306
for pos < len(literal) {

0 commit comments

Comments
 (0)