From eed932912438cf3099cef086c1e0ce2b95fbb183 Mon Sep 17 00:00:00 2001 From: Pat Downey Date: Sun, 15 Nov 2026 12:32:50 +0000 Subject: [PATCH] feat(configcheck): add Collector.Inert for settings that have no effect A setting that is populated but does nothing leaves an operator believing it applies. Inert reports each such setting as a finding at the collector's path, so a command rejects it alongside its other findings. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01SS4MAvnUSKyK9WP4pSz5Gg --- configcheck/configcheck.go | 11 +++++++++++ configcheck/configcheck_test.go | 15 +++++++++++++++ go.mod | 6 +++--- go.sum | 6 ++---- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/configcheck/configcheck.go b/configcheck/configcheck.go index d429012..de7920d 100644 --- a/configcheck/configcheck.go +++ b/configcheck/configcheck.go @@ -99,6 +99,17 @@ func (c *Collector) Errorf(format string, args ...any) { c.append(Finding{Path: c.path, Message: fmt.Sprintf(format, args...)}) } +// Inert adds a finding at c's path for each of names: a setting that is +// populated but has no effect in this configuration. A setting that silently +// does nothing leaves an operator believing it applies, so a command rejects +// it rather than warning. Each name may carry a short reason in parentheses. +// No names adds nothing. +func (c *Collector) Inert(names ...string) { + for _, name := range names { + c.Errorf("%s is set but has no effect, remove it", name) + } +} + // Add adds err to c. An *Error, such as one returned by Decode, contributes // each of its findings with c's path prefixed; any other error becomes one // finding at c's path. A nil err adds nothing. diff --git a/configcheck/configcheck_test.go b/configcheck/configcheck_test.go index c120061..9ca2ba2 100644 --- a/configcheck/configcheck_test.go +++ b/configcheck/configcheck_test.go @@ -58,6 +58,21 @@ func TestCollector_AddTurnsAPlainErrorIntoOneFinding(t *testing.T) { }, c.Findings()) } +func TestCollector_InertReportsEachSettingAtThePath(t *testing.T) { + t.Parallel() + + c := configcheck.NewCollector() + c.Inert() + assert.NoError(t, c.Err(), "no names adds nothing") + + c.Field("management").Inert("allow-non-loopback (only applies with a listener)", "debug") + + assert.Equal(t, []configcheck.Finding{ + {Path: "management", Message: "allow-non-loopback (only applies with a listener) is set but has no effect, remove it"}, + {Path: "management", Message: "debug is set but has no effect, remove it"}, + }, c.Findings()) +} + func TestCollector_ErrIsNilWithoutFindings(t *testing.T) { t.Parallel() diff --git a/go.mod b/go.mod index ae10b38..00dcc89 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/dioad/config -go 1.25.0 +go 1.26.0 require ( github.com/dioad/util v0.7.0 @@ -12,8 +12,8 @@ require ( github.com/dioad/generics v0.0.8 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect - github.com/rogpeppe/go-internal v1.14.1 // indirect - go.yaml.in/yaml/v3 v3.0.5 // indirect + github.com/rogpeppe/go-internal v1.16.0 // indirect + go.yaml.in/yaml/v3 v3.0.6 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 49a90d6..562a9ac 100644 --- a/go.sum +++ b/go.sum @@ -16,12 +16,10 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= -github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= +github.com/rogpeppe/go-internal v1.16.0 h1:O9DK+vNMDVGLr2BeZqmpLeMjiMNkuXfcqntWbZV6S5g= github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= -go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= -go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= +go.yaml.in/yaml/v3 v3.0.6 h1:zcDfvjXEqTQmpjniUBLc91xYJMB2c4QOFxEF/LCEckM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=