Skip to content

Commit

Permalink
🧹 lint error for duplicate uids in a query pack
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Aug 27, 2024
1 parent 5f0fcb8 commit e0b1814
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/bundle/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ package bundle
import (
"context"
"fmt"
"strconv"

"go.mondoo.com/cnquery/v11/explorer"
"go.mondoo.com/cnquery/v11/providers"
"strconv"
)

func Lint(queryPackBundle *explorer.Bundle) []string {
Expand All @@ -29,12 +30,17 @@ func Lint(queryPackBundle *explorer.Bundle) []string {
errors = append(errors, fmt.Sprintf("pack %s does not define a name", packId))
}

queryUids := map[string]struct{}{}
for j := range pack.Queries {
query := pack.Queries[j]
queryId := strconv.Itoa(j)
if query.Uid == "" {
errors = append(errors, fmt.Sprintf("query %s/%s does not define a uid", packId, queryId))
} else {
if _, ok := queryUids[query.Uid]; ok {
errors = append(errors, fmt.Sprintf("query %s/%s has a duplicate uid", packId, query.Uid))
}
queryUids[query.Uid] = struct{}{}
queryId = query.Uid
}

Expand Down

0 comments on commit e0b1814

Please sign in to comment.