Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: if all tags negate return true on no hits #1624

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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