Skip to content

Commit

Permalink
Fix matching test case tags (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
5nord committed Oct 23, 2020
1 parent c627d17 commit 10c544f
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions internal/cmds/lint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,33 +379,32 @@ func checkTags(fset *loc.FileSet, n ast.Node, patterns map[string]string) {
return
}

tags := doc.FindAllTags(ast.FirstToken(n).Comments())

// If a syntax node does not have any tags, we still invoke
// checkPattern, so the user get reports about missing tags.
if len(tags) == 0 {
checkPatterns(fset, n, patterns, "")
return
}

for i := range tags {
checkPatterns(fset, n, patterns, strings.Join(tags[i], ":"))
var tags []string
for _, t := range doc.FindAllTags(ast.FirstToken(n).Comments()) {
tags = append(tags, strings.Join(t, ":"))
}

return
checkPatterns(fset, n, patterns, tags...)
}

func checkPatterns(fset *loc.FileSet, n ast.Node, patterns map[string]string, s string) {
func checkPatterns(fset *loc.FileSet, n ast.Node, patterns map[string]string, ss ...string) {
next:
for p, msg := range patterns {
expect := true
if strings.HasPrefix(p, "!") {
expect = false
p = p[1:]
}

if regexes[p].MatchString(s) != expect {
report(&errPattern{fset: fset, node: n, msg: msg})
// Match any.
for _, s := range ss {
if regexes[p].MatchString(s) == expect {
continue next
}
}

// If we could not match any, we report an error
report(&errPattern{fset: fset, node: n, msg: msg})
}
}

Expand Down

0 comments on commit 10c544f

Please sign in to comment.