From 43660e84f6000ec019eb8594af69b52b5dc68141 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Wed, 28 Jan 2026 14:05:46 +0000 Subject: [PATCH] golangci: add forbidigo rule for zerolog field constants Add a lint rule to enforce use of zf.* constants for zerolog field names instead of inline string literals. This catches at lint time any new code that doesn't follow the convention. The rule matches common zerolog field methods (Str, Int, Bool, etc.) and flags any usage with a string literal first argument. --- .golangci.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.golangci.yaml b/.golangci.yaml index eda3bed4..7e1ab297 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -37,6 +37,13 @@ linters: time.Sleep is forbidden. In tests: use assert.EventuallyWithT for polling/waiting patterns. In production code: use a backoff strategy (e.g., cenkalti/backoff) or proper synchronization primitives. + # Forbid inline string literals in zerolog field methods - use zf.* constants + - pattern: '\.(Str|Int|Int8|Int16|Int32|Int64|Uint|Uint8|Uint16|Uint32|Uint64|Float32|Float64|Bool|Dur|Time|TimeDiff|Strs|Ints|Uints|Floats|Bools|Any|Interface)\("[^"]+"' + msg: >- + Use zf.* constants for zerolog field names instead of string literals. + Import "github.com/juanfont/headscale/hscontrol/util/zlog/zf" and use + constants like zf.NodeID, zf.UserName, etc. Add new constants to + hscontrol/util/zlog/zf/fields.go if needed. analyze-types: true gocritic: disabled-checks: