Skip to content

Commit fe971d2

Browse files
authoredJul 17, 2023
parser: if all tags negate return true on no hits (#1624)
* parser: if all tags negate return true on no hits
1 parent 0cee1c5 commit fe971d2

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed
 

‎parser.go

+21-10
Original file line numberDiff line numberDiff line change
@@ -867,18 +867,29 @@ func getTagsFromComment(comment string) (tags []string) {
867867
}
868868

869869
func (parser *Parser) matchTags(comments []*ast.Comment) (match bool) {
870-
if len(parser.tags) != 0 {
871-
for _, comment := range comments {
872-
for _, tag := range getTagsFromComment(comment.Text) {
873-
if _, has := parser.tags["!"+tag]; has {
874-
return false
875-
}
876-
if _, has := parser.tags[tag]; has {
877-
match = true // keep iterating as it may contain a tag that is excluded
878-
}
870+
if len(parser.tags) == 0 {
871+
return true
872+
}
873+
874+
match = false
875+
for _, comment := range comments {
876+
for _, tag := range getTagsFromComment(comment.Text) {
877+
if _, has := parser.tags["!"+tag]; has {
878+
return false
879+
}
880+
if _, has := parser.tags[tag]; has {
881+
match = true // keep iterating as it may contain a tag that is excluded
882+
}
883+
}
884+
}
885+
886+
if !match {
887+
// If all tags are negation then we should return true
888+
for key := range parser.tags {
889+
if key[0] != '!' {
890+
return false
879891
}
880892
}
881-
return
882893
}
883894
return true
884895
}

0 commit comments

Comments
 (0)
Please sign in to comment.