Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
liamg committed Jan 25, 2022
1 parent 26ed3c4 commit 57cab93
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions checkers/todoCommentWithoutDetail_checker.go
Expand Up @@ -3,7 +3,6 @@ package checkers
import (
"go/ast"
"regexp"
"strings"

"github.com/go-critic/go-critic/checkers/internal/astwalk"
"github.com/go-critic/go-critic/framework/linter"
Expand All @@ -25,7 +24,7 @@ fiiWithCtx(nil, a, b)
collection.AddChecker(&info, func(ctx *linter.CheckerContext) (linter.FileWalker, error) {
visitor := &todoCommentWithoutCodeChecker{
ctx: ctx,
regex: regexp.MustCompile(`^\s*(TODO|FIX|FIXME|BUG)\s*$`),
regex: regexp.MustCompile(`^(//|/\*)?\s*(TODO|FIX|FIXME|BUG)\s*(\*/)?$`),
}
return astwalk.WalkerForComment(visitor), nil
})
Expand All @@ -38,12 +37,11 @@ type todoCommentWithoutCodeChecker struct {
}

func (c *todoCommentWithoutCodeChecker) VisitComment(cg *ast.CommentGroup) {
comment := strings.TrimSpace(cg.Text())
if strings.Contains(comment, "\n") {
return
}
if c.regex.MatchString(comment) {
c.warn(cg)
for _, comment := range cg.List {
if c.regex.MatchString(comment.Text) {
c.warn(cg)
break
}
}
}

Expand Down

0 comments on commit 57cab93

Please sign in to comment.