Skip to content

Commit

Permalink
parser: if all tags negate return true on no hits (#1624)
Browse files Browse the repository at this point in the history
* parser: if all tags negate return true on no hits
  • Loading branch information
rsmarples committed Jul 17, 2023
1 parent 0cee1c5 commit fe971d2
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,18 +867,29 @@ func getTagsFromComment(comment string) (tags []string) {
}

func (parser *Parser) matchTags(comments []*ast.Comment) (match bool) {
if len(parser.tags) != 0 {
for _, comment := range comments {
for _, tag := range getTagsFromComment(comment.Text) {
if _, has := parser.tags["!"+tag]; has {
return false
}
if _, has := parser.tags[tag]; has {
match = true // keep iterating as it may contain a tag that is excluded
}
if len(parser.tags) == 0 {
return true
}

match = false
for _, comment := range comments {
for _, tag := range getTagsFromComment(comment.Text) {
if _, has := parser.tags["!"+tag]; has {
return false
}
if _, has := parser.tags[tag]; has {
match = true // keep iterating as it may contain a tag that is excluded
}
}
}

if !match {
// If all tags are negation then we should return true
for key := range parser.tags {
if key[0] != '!' {
return false
}
}
return
}
return true
}
Expand Down

0 comments on commit fe971d2

Please sign in to comment.