aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-linter
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-07-10 18:50:44 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-07-10 19:15:46 +0200
commit78178cfb8c749a862d7df2ac09ee66b956565027 (patch)
tree18fcf83ab4f030042c675e391cb4c9c1f2d03a36 /tools/syz-linter
parentd4c58caef7e5fbae992399cb3b28681694468b39 (diff)
tools/syz-linter: fix comments check
Turns out ast.Inspect does not visit most comments. Walk file.Comments manually. Update #1876
Diffstat (limited to 'tools/syz-linter')
-rw-r--r--tools/syz-linter/linter.go29
-rw-r--r--tools/syz-linter/testdata/src/lintertest/lintertest.go4
2 files changed, 19 insertions, 14 deletions
diff --git a/tools/syz-linter/linter.go b/tools/syz-linter/linter.go
index d69ca0a2a..8bc8eda23 100644
--- a/tools/syz-linter/linter.go
+++ b/tools/syz-linter/linter.go
@@ -63,9 +63,12 @@ func run(p *analysis.Pass) (interface{}, error) {
for _, file := range pass.Files {
ast.Inspect(file, func(n ast.Node) bool {
switch n := n.(type) {
- case *ast.Comment:
- pass.checkMulitlineComments(n)
- pass.checkCommentSpace(n)
+ case *ast.File:
+ for _, group := range n.Comments {
+ for _, comment := range group.List {
+ pass.checkComment(comment)
+ }
+ }
case *ast.BinaryExpr:
pass.checkStringLenCompare(n)
case *ast.FuncType:
@@ -94,19 +97,17 @@ func (pass *Pass) typ(e ast.Expr) types.Type {
return pass.TypesInfo.Types[e].Type
}
-// checkMulitlineComments warns about C++-style multiline comments.
-// We don't use them in the codebase.
-func (pass *Pass) checkMulitlineComments(n *ast.Comment) {
- if !strings.HasPrefix(n.Text, "/*") {
+// checkComment warns about C++-style multiline comments (we don't use them in the codebase)
+// and about "//nospace", "// tabs and spaces" and similar.
+func (pass *Pass) checkComment(n *ast.Comment) {
+ if strings.HasPrefix(n.Text, "/*") {
+ pass.report(n, "Use C-style comments // instead of /* */")
return
}
- pass.report(n, "Use C-style comments // instead of /* */")
-}
-
-// checkCommentSpace warns about "//nospace", "// tabs and spaces" and similar.
-func (pass *Pass) checkCommentSpace(n *ast.Comment) {
- if !strings.HasPrefix(n.Text, "//") ||
- allowedComments.MatchString(n.Text) {
+ if allowedComments.MatchString(n.Text) {
+ return
+ }
+ if strings.HasPrefix(n.Text, "//go:generate") {
return
}
pass.report(n, "Use either //<one-or-more-spaces>comment or //<one-or-more-tabs>comment format for comments")
diff --git a/tools/syz-linter/testdata/src/lintertest/lintertest.go b/tools/syz-linter/testdata/src/lintertest/lintertest.go
index 9a8c965b8..12553c230 100644
--- a/tools/syz-linter/testdata/src/lintertest/lintertest.go
+++ b/tools/syz-linter/testdata/src/lintertest/lintertest.go
@@ -32,8 +32,12 @@ func returnString() string { return "foo" }
// Tab and spaces. // want "Use either //<one-or-more-spaces>comment or //<one-or-more-tabs>comment format for comments"
// Space and tab. // want "Use either //<one-or-more-spaces>comment or //<one-or-more-tabs>comment format for comments"
func checkCommentSpace() {
+ // Comment without a dot at the end
+ checkCommentSpace()
}
+//No space. // want "Use either //<one-or-more-spaces>comment or //<one-or-more-tabs>comment format for comments"
+
func funcArgsGood(a, b int) (int, int) {
return 0, 0
}