From 41b3237c07718e79f8bb1faf96b04d62d4e1c592 Mon Sep 17 00:00:00 2001 From: ZverGuy Date: Tue, 10 Nov 2026 00:46:05 +0700 Subject: [PATCH] refactor(observability-proxy): state the keyword and duration tests positively staticcheck flags the negated disjunctions; naming the duration characters and spelling out both word boundaries reads the same way the rule is stated. Assisted-by: LLM Signed-off-by: ZverGuy --- internal/observabilityproxy/metricslookback.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/observabilityproxy/metricslookback.go b/internal/observabilityproxy/metricslookback.go index ed7e9d166..e55d189a5 100644 --- a/internal/observabilityproxy/metricslookback.go +++ b/internal/observabilityproxy/metricslookback.go @@ -128,9 +128,7 @@ func queryLookback(query string, step time.Duration) (time.Duration, bool) { if negative { arg = strings.TrimLeft(arg[1:], " \t\n\r") } - end := strings.IndexFunc(arg, func(r rune) bool { - return !(r >= '0' && r <= '9' || r >= 'a' && r <= 'z' || r == '.' || r == '_') - }) + end := strings.IndexFunc(arg, func(r rune) bool { return !inDuration(r) }) if end < 0 { end = len(arg) } @@ -156,7 +154,12 @@ func queryLookback(query string, step time.Duration) (time.Duration, bool) { // isKeyword reports whether lower[start:end] stands on its own rather than // inside an identifier. func isKeyword(lower string, start, end int) bool { - return !(start > 0 && continuesIdent(lower[start-1], false) || end < len(lower) && continuesIdent(lower[end], true)) + return (start == 0 || !continuesIdent(lower[start-1], false)) && + (end == len(lower) || !continuesIdent(lower[end], true)) +} + +func inDuration(r rune) bool { + return r >= '0' && r <= '9' || r >= 'a' && r <= 'z' || r == '.' || r == '_' } func hasKeyword(lower, word string) bool {