From 1e323394d0ceaccda49f263dc81456e33af4263b Mon Sep 17 00:00:00 2001 From: SuperQ Date: Tue, 28 Oct 2025 13:58:34 +0100 Subject: [PATCH] Cleanup linting issues * Remove unused linting settings from golangci-lint config. * Fixup linting issues. Signed-off-by: SuperQ --- .golangci.yml | 21 ------------------- config/http_config.go | 8 ++++---- config/http_config_test.go | 2 +- expfmt/openmetrics_create.go | 40 ++++++++++++++++++------------------ expfmt/text_create.go | 30 +++++++++++++-------------- 5 files changed, 40 insertions(+), 61 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 02bf7fb0..db2ad414 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -30,19 +30,11 @@ linters: - common-false-positives - legacy - std-error-handling - paths: - - third_party$ - - builtin$ - - examples$ rules: - linters: - errcheck # Taken from the default exclusions in v1. text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked - - linters: - - govet - # We use many Seek methods that do not follow the usual pattern. - text: "stdmethods: method Seek.* should have signature Seek" - linters: - revive # We have stopped at some point to write doc comments on exported symbols. @@ -51,15 +43,6 @@ linters: - linters: - gocritic text: "appendAssign" - - linters: - - errcheck - path: _test.go - - linters: - - errorlint - path: "tsdb/head_wal.go" - - linters: - - godot - source: "^// ===" warn-unused: true settings: depguard: @@ -182,7 +165,3 @@ formatters: - github.com/prometheus/common exclusions: generated: lax - paths: - - third_party$ - - builtin$ - - examples$ diff --git a/config/http_config.go b/config/http_config.go index b3943bd0..dd967330 100644 --- a/config/http_config.go +++ b/config/http_config.go @@ -1508,19 +1508,19 @@ func (c *ProxyConfig) Proxy() (fn func(*http.Request) (*url.URL, error)) { fn = c.proxyFunc }() if c.proxyFunc != nil { - return + return fn } if c.ProxyFromEnvironment { proxyFn := httpproxy.FromEnvironment().ProxyFunc() c.proxyFunc = func(req *http.Request) (*url.URL, error) { return proxyFn(req.URL) } - return + return fn } if c.ProxyURL.URL != nil && c.ProxyURL.String() != "" { if c.NoProxy == "" { c.proxyFunc = http.ProxyURL(c.ProxyURL.URL) - return + return fn } proxy := &httpproxy.Config{ HTTPProxy: c.ProxyURL.String(), @@ -1532,7 +1532,7 @@ func (c *ProxyConfig) Proxy() (fn func(*http.Request) (*url.URL, error)) { return proxyFn(req.URL) } } - return + return fn } // ProxyConnectHeader() return the Proxy Connext Headers. diff --git a/config/http_config_test.go b/config/http_config_test.go index d60b9060..c5be6c33 100644 --- a/config/http_config_test.go +++ b/config/http_config_test.go @@ -1977,7 +1977,7 @@ func TestTLSRoundTripper_NoCAConfigured(t *testing.T) { defer os.RemoveAll(tmpDir) cert, key := filepath.Join(tmpDir, "cert"), filepath.Join(tmpDir, "key") - handler := func(w http.ResponseWriter, r *http.Request) { + handler := func(w http.ResponseWriter, _ *http.Request) { fmt.Fprint(w, ExpectedMessage) } testServer, err := newTestServer(handler) diff --git a/expfmt/openmetrics_create.go b/expfmt/openmetrics_create.go index 8c8bbaa6..21b93bca 100644 --- a/expfmt/openmetrics_create.go +++ b/expfmt/openmetrics_create.go @@ -160,38 +160,38 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E n, err = w.WriteString("# HELP ") written += n if err != nil { - return + return written, err } n, err = writeName(w, compliantName) written += n if err != nil { - return + return written, err } err = w.WriteByte(' ') written++ if err != nil { - return + return written, err } n, err = writeEscapedString(w, *in.Help, true) written += n if err != nil { - return + return written, err } err = w.WriteByte('\n') written++ if err != nil { - return + return written, err } } n, err = w.WriteString("# TYPE ") written += n if err != nil { - return + return written, err } n, err = writeName(w, compliantName) written += n if err != nil { - return + return written, err } switch metricType { case dto.MetricType_COUNTER: @@ -215,34 +215,34 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E } written += n if err != nil { - return + return written, err } if toOM.withUnit && in.Unit != nil { n, err = w.WriteString("# UNIT ") written += n if err != nil { - return + return written, err } n, err = writeName(w, compliantName) written += n if err != nil { - return + return written, err } err = w.WriteByte(' ') written++ if err != nil { - return + return written, err } n, err = writeEscapedString(w, *in.Unit, true) written += n if err != nil { - return + return written, err } err = w.WriteByte('\n') written++ if err != nil { - return + return written, err } } @@ -306,7 +306,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E ) written += n if err != nil { - return + return written, err } } n, err = writeOpenMetricsSample( @@ -316,7 +316,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E ) written += n if err != nil { - return + return written, err } n, err = writeOpenMetricsSample( w, compliantName, "_count", metric, "", 0, @@ -349,7 +349,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E ) written += n if err != nil { - return + return written, err } if math.IsInf(b.GetUpperBound(), +1) { infSeen = true @@ -367,7 +367,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E // out if needed). written += n if err != nil { - return + return written, err } } n, err = writeOpenMetricsSample( @@ -377,7 +377,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E ) written += n if err != nil { - return + return written, err } if metric.Histogram.GetSampleCountFloat() > 0 { return written, fmt.Errorf( @@ -401,10 +401,10 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E } written += n if err != nil { - return + return written, err } } - return + return written, err } // FinalizeOpenMetrics writes the final `# EOF\n` line required by OpenMetrics. diff --git a/expfmt/text_create.go b/expfmt/text_create.go index 7e1d23ca..6b897814 100644 --- a/expfmt/text_create.go +++ b/expfmt/text_create.go @@ -108,38 +108,38 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e n, err = w.WriteString("# HELP ") written += n if err != nil { - return + return written, err } n, err = writeName(w, name) written += n if err != nil { - return + return written, err } err = w.WriteByte(' ') written++ if err != nil { - return + return written, err } n, err = writeEscapedString(w, *in.Help, false) written += n if err != nil { - return + return written, err } err = w.WriteByte('\n') written++ if err != nil { - return + return written, err } } n, err = w.WriteString("# TYPE ") written += n if err != nil { - return + return written, err } n, err = writeName(w, name) written += n if err != nil { - return + return written, err } metricType := in.GetType() switch metricType { @@ -161,7 +161,7 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e } written += n if err != nil { - return + return written, err } // Finally the samples, one line for each. @@ -211,7 +211,7 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e ) written += n if err != nil { - return + return written, err } } n, err = writeSample( @@ -220,7 +220,7 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e ) written += n if err != nil { - return + return written, err } n, err = writeSample( w, name, "_count", metric, "", 0, @@ -245,7 +245,7 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e ) written += n if err != nil { - return + return written, err } if math.IsInf(b.GetUpperBound(), +1) { infSeen = true @@ -263,7 +263,7 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e ) written += n if err != nil { - return + return written, err } } n, err = writeSample( @@ -272,7 +272,7 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e ) written += n if err != nil { - return + return written, err } v := metric.Histogram.GetSampleCountFloat() if v == 0 { @@ -286,10 +286,10 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e } written += n if err != nil { - return + return written, err } } - return + return written, err } // writeSample writes a single sample in text format to w, given the metric