From 08ac5ff5aee71a58aa397a65e18b53c75b8907c0 Mon Sep 17 00:00:00 2001 From: "Marcelo E. Magallon" Date: Thu, 15 Jul 2021 08:53:59 -0600 Subject: [PATCH] Fix linter errors The linter is correctly flagging this bit: fmt.Fprintf(w, ExpectedMessage) because it's a formatting function that doesn't appear to be formatting anything (since there are not additional arguments after the formatting string). staticcheck has started flagging this import: "github.com/golang/protobuf/proto" because that package has been rewritten and published as google.golang.org/protobuf. The new package is not a drop-in replacement for the old one, even if the staticcheck diagnostic suggests otherwise. Newer versions of the old package are actually implemented in terms of the new one. For this code base in particular, some of the text marshalling functions have disappeared in the new package and they need to be implemented in terms of the new reflection package. Until an adequate solution is found, simply ignore the error. Closes: #281 Signed-off-by: Marcelo E. Magallon --- config/http_config_test.go | 6 +++--- expfmt/decode_test.go | 2 +- expfmt/encode.go | 2 +- expfmt/encode_test.go | 5 +++-- expfmt/openmetrics_create_test.go | 2 +- expfmt/text_create_test.go | 2 +- expfmt/text_parse.go | 2 +- expfmt/text_parse_test.go | 2 +- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/config/http_config_test.go b/config/http_config_test.go index 49b0aa36..5ec32297 100644 --- a/config/http_config_test.go +++ b/config/http_config_test.go @@ -335,11 +335,11 @@ func TestNewClientFromConfig(t *testing.T) { handler: func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { case "/redirected": - fmt.Fprintf(w, ExpectedMessage) + fmt.Fprint(w, ExpectedMessage) default: w.Header().Set("Location", "/redirected") w.WriteHeader(http.StatusFound) - fmt.Fprintf(w, "It should follow the redirect.") + fmt.Fprint(w, "It should follow the redirect.") } }, }, { @@ -359,7 +359,7 @@ func TestNewClientFromConfig(t *testing.T) { default: w.Header().Set("Location", "/redirected") w.WriteHeader(http.StatusFound) - fmt.Fprintf(w, ExpectedMessage) + fmt.Fprint(w, ExpectedMessage) } }, }, diff --git a/expfmt/decode_test.go b/expfmt/decode_test.go index ef1a0ddb..f98be91d 100644 --- a/expfmt/decode_test.go +++ b/expfmt/decode_test.go @@ -21,7 +21,7 @@ import ( "strings" "testing" - "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/proto" //nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility. dto "github.com/prometheus/client_model/go" "github.com/prometheus/common/model" diff --git a/expfmt/encode.go b/expfmt/encode.go index bd4e3474..64dc0eb4 100644 --- a/expfmt/encode.go +++ b/expfmt/encode.go @@ -18,7 +18,7 @@ import ( "io" "net/http" - "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/proto" //nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility. "github.com/matttproud/golang_protobuf_extensions/pbutil" "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg" diff --git a/expfmt/encode_test.go b/expfmt/encode_test.go index 1b228733..63d0bd44 100644 --- a/expfmt/encode_test.go +++ b/expfmt/encode_test.go @@ -15,10 +15,11 @@ package expfmt import ( "bytes" - "github.com/golang/protobuf/proto" - dto "github.com/prometheus/client_model/go" "net/http" "testing" + + "github.com/golang/protobuf/proto" //nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility. + dto "github.com/prometheus/client_model/go" ) func TestNegotiate(t *testing.T) { diff --git a/expfmt/openmetrics_create_test.go b/expfmt/openmetrics_create_test.go index 4a5318b4..88330a5d 100644 --- a/expfmt/openmetrics_create_test.go +++ b/expfmt/openmetrics_create_test.go @@ -20,7 +20,7 @@ import ( "testing" "time" - "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/proto" //nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility. "github.com/golang/protobuf/ptypes" dto "github.com/prometheus/client_model/go" diff --git a/expfmt/text_create_test.go b/expfmt/text_create_test.go index 014351d3..aa370df9 100644 --- a/expfmt/text_create_test.go +++ b/expfmt/text_create_test.go @@ -19,7 +19,7 @@ import ( "strings" "testing" - "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/proto" //nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility. dto "github.com/prometheus/client_model/go" ) diff --git a/expfmt/text_parse.go b/expfmt/text_parse.go index b6079b31..84be0643 100644 --- a/expfmt/text_parse.go +++ b/expfmt/text_parse.go @@ -24,7 +24,7 @@ import ( dto "github.com/prometheus/client_model/go" - "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/proto" //nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility. "github.com/prometheus/common/model" ) diff --git a/expfmt/text_parse_test.go b/expfmt/text_parse_test.go index 949bbd64..782048ef 100644 --- a/expfmt/text_parse_test.go +++ b/expfmt/text_parse_test.go @@ -18,7 +18,7 @@ import ( "strings" "testing" - "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/proto" //nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility. dto "github.com/prometheus/client_model/go" )