.golangci.yml: properly enable revive linter and fix all the warnings it detects

This commit is contained in:
Aliaksandr Valialkin 2023-02-26 12:18:59 -08:00
parent ffa327d6d1
commit f7ef80aaad
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
10 changed files with 30 additions and 22 deletions

View file

@ -1,14 +1,18 @@
run:
timeout: 2m
enable:
linters:
enable:
- revive
issues:
exclude-rules:
- linters:
- staticcheck
text: "SA(4003|1019|5011):"
- linters:
- staticcheck
text: "SA(4003|1019|5011):"
include:
- EXC0012
- EXC0014
linters-settings:
errcheck:

View file

@ -51,27 +51,27 @@ func main() {
if len(*snapshotCreateURL) > 0 {
// create net/url object
createUrl, err := url.Parse(*snapshotCreateURL)
createURL, err := url.Parse(*snapshotCreateURL)
if err != nil {
logger.Fatalf("cannot parse snapshotCreateURL: %s", err)
}
if len(*snapshotName) > 0 {
logger.Fatalf("-snapshotName shouldn't be set if -snapshot.createURL is set, since snapshots are created automatically in this case")
}
logger.Infof("Snapshot create url %s", createUrl.Redacted())
logger.Infof("Snapshot create url %s", createURL.Redacted())
if len(*snapshotDeleteURL) <= 0 {
err := flag.Set("snapshot.deleteURL", strings.Replace(*snapshotCreateURL, "/create", "/delete", 1))
if err != nil {
logger.Fatalf("Failed to set snapshot.deleteURL flag: %v", err)
}
}
deleteUrl, err := url.Parse(*snapshotDeleteURL)
deleteURL, err := url.Parse(*snapshotDeleteURL)
if err != nil {
logger.Fatalf("cannot parse snapshotDeleteURL: %s", err)
}
logger.Infof("Snapshot delete url %s", deleteUrl.Redacted())
logger.Infof("Snapshot delete url %s", deleteURL.Redacted())
name, err := snapshot.Create(createUrl.String())
name, err := snapshot.Create(createURL.String())
if err != nil {
logger.Fatalf("cannot create snapshot: %s", err)
}
@ -81,7 +81,7 @@ func main() {
}
defer func() {
err := snapshot.Delete(deleteUrl.String(), name)
err := snapshot.Delete(deleteURL.String(), name)
if err != nil {
logger.Fatalf("cannot delete snapshot: %s", err)
}

View file

@ -19,6 +19,7 @@ const (
// retryableFunc describes call back which will repeat on errors
type retryableFunc func() error
// ErrBadRequest is an error returned on bad request
var ErrBadRequest = errors.New("bad request")
// Backoff describes object with backoff policy params

View file

@ -783,7 +783,7 @@ func fillNaNsAtIdx(idx int, k float64, tss []*timeseries) {
}
}
func getIntK(k float64, kMax int) int {
func getIntK(k float64, max int) int {
if math.IsNaN(k) {
return 0
}
@ -791,8 +791,8 @@ func getIntK(k float64, kMax int) int {
if kn < 0 {
return 0
}
if kn > kMax {
return kMax
if kn > max {
return max
}
return kn
}

View file

@ -84,10 +84,10 @@ func signRequestWithTime(req *http.Request, service, region, payloadHash string,
}
func getSignatureKey(key, datestamp, region, service string) string {
kDate := hmacBin("AWS4"+key, datestamp)
kRegion := hmacBin(kDate, region)
kService := hmacBin(kRegion, service)
return hmacBin(kService, "aws4_request")
dateKey := hmacBin("AWS4"+key, datestamp)
regionKey := hmacBin(dateKey, region)
serviceKey := hmacBin(regionKey, service)
return hmacBin(serviceKey, "aws4_request")
}
func hashHex(s string) string {

View file

@ -468,6 +468,7 @@ func isHTTPURL(targetURL string) bool {
}
func IsScheduledForRemoval(name string) bool {
return strings.Contains(name, ".must-remove.")
// IsScheduledForRemoval returns true if the filename contains .must-remove. substring
func IsScheduledForRemoval(filename string) bool {
return strings.Contains(filename, ".must-remove.")
}

View file

@ -79,7 +79,7 @@ func concatTwoStrings(x, y string) string {
return s
}
func newClient(sw *ScrapeWork, ctx context.Context) *client {
func newClient(ctx context.Context, sw *ScrapeWork) *client {
var u fasthttp.URI
u.Update(sw.ScrapeURL)
hostPort := string(u.Host())

View file

@ -22,6 +22,8 @@ func getServiceLabels(cfg *apiConfig) []*promutils.Labels {
return ms
}
// ServiceList is a list of Nomad services.
// See https://developer.hashicorp.com/nomad/api-docs/services#list-services
type ServiceList struct {
Namespace string `json:"Namespace"`
Services []struct {

View file

@ -442,7 +442,7 @@ func newScraper(sw *ScrapeWork, group string, pushData func(at *auth.Token, wr *
cancel: cancel,
stoppedCh: make(chan struct{}),
}
c := newClient(sw, ctx)
c := newClient(ctx, sw)
sc.sw.Config = sw
sc.sw.ScrapeGroup = group
sc.sw.ReadData = c.ReadData

View file

@ -7,7 +7,7 @@ import (
"strings"
)
// HandleVMProtoClientHashake returns true if the server at remoteWriteURL supports VictoriaMetrics remote write protocol.
// HandleVMProtoClientHandshake returns true if the server at remoteWriteURL supports VictoriaMetrics remote write protocol.
func HandleVMProtoClientHandshake(remoteWriteURL string, doRequest func(handshakeURL string) (*http.Response, error)) bool {
u := remoteWriteURL
if strings.Contains(u, "?") {