Created
February 17, 2015 02:07
-
-
Save mattn/8fb7bbe0e515e316aa57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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