@@ -17,9 +17,6 @@ package librarian
1717import (
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- }
0 commit comments