From 5505a2150a7353aa7f6f06cbaa354ed790d99801 Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Wed, 15 Nov 2023 12:35:41 -0700 Subject: [PATCH] chore: Enable bad regex gocritic linter (#14295) --- .golangci.yml | 1 + plugins/inputs/gnmi/path.go | 2 +- plugins/serializers/graphite/graphite.go | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4ccc72966..d8bb620f4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -81,6 +81,7 @@ linters-settings: - badCall - badCond - badLock + - badRegexp - badSorting - builtinShadowDecl - caseOrder diff --git a/plugins/inputs/gnmi/path.go b/plugins/inputs/gnmi/path.go index e00af0dd6..e6ac208f8 100644 --- a/plugins/inputs/gnmi/path.go +++ b/plugins/inputs/gnmi/path.go @@ -8,7 +8,7 @@ import ( ) // Regular expression to see if a path element contains an origin -var originPattern = regexp.MustCompile(`^([\w-_]+):`) +var originPattern = regexp.MustCompile(`^([\w-]+):`) type keySegment struct { name string diff --git a/plugins/serializers/graphite/graphite.go b/plugins/serializers/graphite/graphite.go index 289a0cbcb..f41669707 100644 --- a/plugins/serializers/graphite/graphite.go +++ b/plugins/serializers/graphite/graphite.go @@ -17,8 +17,8 @@ import ( const DefaultTemplate = "host.tags.measurement.field" var ( - compatibleAllowedCharsName = regexp.MustCompile(`[^ "-:\<>-\]_a-~\p{L}]`) - compatibleAllowedCharsValue = regexp.MustCompile(`[^ -:<-~\p{L}]`) + compatibleAllowedCharsName = regexp.MustCompile(`[^ "-:\<>-\]_a-~\p{L}]`) //nolint: gocritic // valid range for use-case + compatibleAllowedCharsValue = regexp.MustCompile(`[^ -:<-~\p{L}]`) //nolint: gocritic // valid range for use-case compatibleLeadingTildeDrop = regexp.MustCompile(`^[~]*(.*)`) hyphenChars = strings.NewReplacer( "/", "-",