From dbc272e99fcb11ece1fb24f3d8587decaf97a521 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Tue, 26 Aug 2025 18:42:05 +0200 Subject: [PATCH] Enable unconvert linter Signed-off-by: Arve Knudsen --- .golangci.yml | 2 +- config/http_config.go | 6 +++--- model/metric_test.go | 2 +- model/time.go | 4 ++-- model/value.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f22a4bcdf..7d9a66e22 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,7 +19,7 @@ linters: - revive - sloglint - testifylint - #- unconvert + - unconvert - unused #- usestdlibvars - whitespace diff --git a/config/http_config.go b/config/http_config.go index 5d3f1941b..3238607ab 100644 --- a/config/http_config.go +++ b/config/http_config.go @@ -72,7 +72,7 @@ var TLSVersions = map[string]TLSVersion{ func (tv *TLSVersion) UnmarshalYAML(unmarshal func(interface{}) error) error { var s string - err := unmarshal((*string)(&s)) + err := unmarshal(&s) if err != nil { return err } @@ -363,7 +363,7 @@ func (c *HTTPClientConfig) Validate() error { if (c.BasicAuth != nil || c.OAuth2 != nil) && (len(c.BearerToken) > 0 || len(c.BearerTokenFile) > 0) { return errors.New("at most one of basic_auth, oauth2, bearer_token & bearer_token_file must be configured") } - if c.BasicAuth != nil && nonZeroCount(string(c.BasicAuth.Username) != "", c.BasicAuth.UsernameFile != "", c.BasicAuth.UsernameRef != "") > 1 { + if c.BasicAuth != nil && nonZeroCount(c.BasicAuth.Username != "", c.BasicAuth.UsernameFile != "", c.BasicAuth.UsernameRef != "") > 1 { return errors.New("at most one of basic_auth username, username_file & username_ref must be configured") } if c.BasicAuth != nil && nonZeroCount(string(c.BasicAuth.Password) != "", c.BasicAuth.PasswordFile != "", c.BasicAuth.PasswordRef != "") > 1 { @@ -1224,7 +1224,7 @@ func (c *TLSConfig) getClientCertificate(ctx context.Context, secretManager Secr } } - keySecret, err := toSecret(secretManager, Secret(c.Key), c.KeyFile, c.KeyRef) + keySecret, err := toSecret(secretManager, c.Key, c.KeyFile, c.KeyRef) if err != nil { return nil, fmt.Errorf("unable to use client key: %w", err) } diff --git a/model/metric_test.go b/model/metric_test.go index 161f93142..7a4ee7b7a 100644 --- a/model/metric_test.go +++ b/model/metric_test.go @@ -354,7 +354,7 @@ func TestValidationScheme_IsMetricNameValid(t *testing.T) { if LegacyValidation.IsValidMetricName(s.mn) != s.legacyValid { t.Errorf("Expected %v for %q using LegacyValidation.IsValidMetricName", s.legacyValid, s.mn) } - if MetricNameRE.MatchString(string(s.mn)) != s.legacyValid { + if MetricNameRE.MatchString(s.mn) != s.legacyValid { t.Errorf("Expected %v for %q using regexp matching", s.legacyValid, s.mn) } if UTF8Validation.IsValidMetricName(s.mn) != s.utf8Valid { diff --git a/model/time.go b/model/time.go index fed9e87b9..59d9b7c2a 100644 --- a/model/time.go +++ b/model/time.go @@ -126,14 +126,14 @@ func (t *Time) UnmarshalJSON(b []byte) error { p := strings.Split(string(b), ".") switch len(p) { case 1: - v, err := strconv.ParseInt(string(p[0]), 10, 64) + v, err := strconv.ParseInt(p[0], 10, 64) if err != nil { return err } *t = Time(v * second) case 2: - v, err := strconv.ParseInt(string(p[0]), 10, 64) + v, err := strconv.ParseInt(p[0], 10, 64) if err != nil { return err } diff --git a/model/value.go b/model/value.go index 8050637d8..09cb84984 100644 --- a/model/value.go +++ b/model/value.go @@ -258,7 +258,7 @@ func (s Scalar) String() string { // MarshalJSON implements json.Marshaler. func (s Scalar) MarshalJSON() ([]byte, error) { v := strconv.FormatFloat(float64(s.Value), 'f', -1, 64) - return json.Marshal([...]interface{}{s.Timestamp, string(v)}) + return json.Marshal([...]interface{}{s.Timestamp, v}) } // UnmarshalJSON implements json.Unmarshaler.