From e08d0f9c7f805730c3d4b9da6eacd1800868b277 Mon Sep 17 00:00:00 2001 From: Ralph Caraveo Date: Fri, 22 Dec 2023 14:56:19 -0800 Subject: [PATCH] fixed a bug on nil tags --- .golangci.yml | 2 ++ app/filters.go | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6383959..e27ad0a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,10 +4,12 @@ linters: disable-all: true enable: - bidichk + - goconst - gofmt - goimports - govet - misspell + - musttag - revive # Configuration for how we run golangci-lint diff --git a/app/filters.go b/app/filters.go index 4cf8332..11f0a00 100644 --- a/app/filters.go +++ b/app/filters.go @@ -115,11 +115,14 @@ func executeFilters(ctx context.Context, devList []tailscale.Device, // Filter by 'tag' when provided - currently only supports full matching. if f, exists := cfg.Filters["tag"]; exists { normalizedTags := normalizeTags(dev.Tags) + wantsNoTags := f.Contains("nil") // User wants to filter out rows with tags. - // If the user does a filter like: 'tag:nil' they want to filter out those rows WITH tags. - wantsEmpty := f.Contains("nil") + // Determine if the device should be skipped based on tag presence and user's filter. + hasTags := len(dev.Tags) > 0 + matchesTags := f.ContainsAny(normalizedTags...) - if !wantsEmpty && (len(dev.Tags) == 0) || !f.Contains(normalizedTags...) { + // Skip device if it doesn't match the filter criteria. + if (wantsNoTags && hasTags) || (!wantsNoTags && !matchesTags) { continue } }