Skip to content

Instantly share code, notes, and snippets.

@mattn
Created February 17, 2015 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/8fb7bbe0e515e316aa57 to your computer and use it in GitHub Desktop.
Save mattn/8fb7bbe0e515e316aa57 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"fmt"
"go/ast"
"go/parser"
"go/token"
"log"
"os"
"strings"
)
func main() {
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, os.Args[1], nil, parser.ParseComments|parser.SpuriousErrors)
if err != nil {
log.Fatal(err)
}
ast.Inspect(file, func(n ast.Node) bool {
switch x := n.(type) {
case *ast.FuncDecl:
if x.Doc == nil {
fmt.Printf("%s: %s: missing doc\n", os.Args[1], x.Name.Name)
} else {
var buf bytes.Buffer
for _, doc := range x.Doc.List {
buf.WriteString(doc.Text + "\n")
}
if !strings.HasPrefix(buf.String(), "// "+x.Name.Name) {
fmt.Printf("%s: %s: maybe typo in doc\n", os.Args[1], x.Name.Name)
}
}
}
return true
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment