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 <maximbel2003@gmail.com>
This commit is contained in:
ZverGuy committed 2026-11-10 03:56:18 +07:00
1 parent 3e2472280e
commit 41b3237c07
1 file changed
+7 -4
@@ -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 {