Skip to content

Commit

Permalink
Lint fixes (#3526)
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Troshin <anton@diagrid.io>
Co-authored-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>
  • Loading branch information
antontroshin and berndverst authored Sep 5, 2024
1 parent 75dcdef commit facd508
Show file tree
Hide file tree
Showing 140 changed files with 456 additions and 463 deletions.
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ linters-settings:
allow-case-traling-whitespace: true
# Allow declarations (var) to be cuddled.
allow-cuddle-declarations: false
testifylint:
disable:
- float-compare
- negative-positive
- go-require

linters:
fast: false
Expand Down Expand Up @@ -317,3 +322,5 @@ linters:
- goconst
- tagalign
- inamedparam
- canonicalheader
- fatcontext
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ test:
################################################################################
.PHONY: lint
lint: verify-linter-installed verify-linter-version
$(GOLANGCI_LINT) run --timeout=20m
$(GOLANGCI_LINT) run --timeout=20m --max-same-issues 0 --max-issues-per-linter 0

################################################################################
# Target: modtidy-all #
Expand Down
10 changes: 5 additions & 5 deletions bindings/alicloud/sls/sls.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package sls
import (
"context"
"encoding/json"
"fmt"
"errors"
"reflect"
"time"

Expand Down Expand Up @@ -61,16 +61,16 @@ func NewAliCloudSlsLogstorage(logger logger.Logger) bindings.OutputBinding {
func (s *AliCloudSlsLogstorage) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) {
// verify the metadata property
if logProject := req.Metadata["project"]; logProject == "" {
return nil, fmt.Errorf("SLS binding error: project property not supplied")
return nil, errors.New("SLS binding error: project property not supplied")
}
if logstore := req.Metadata["logstore"]; logstore == "" {
return nil, fmt.Errorf("SLS binding error: logstore property not supplied")
return nil, errors.New("SLS binding error: logstore property not supplied")
}
if topic := req.Metadata["topic"]; topic == "" {
return nil, fmt.Errorf("SLS binding error: topic property not supplied")
return nil, errors.New("SLS binding error: topic property not supplied")
}
if source := req.Metadata["source"]; source == "" {
return nil, fmt.Errorf("SLS binding error: source property not supplied")
return nil, errors.New("SLS binding error: source property not supplied")
}

log, err := s.parseLog(req)
Expand Down
2 changes: 0 additions & 2 deletions bindings/alicloud/tablestore/tablestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ func (s *AliCloudTableStore) create(req *bindings.InvokeRequest, resp *bindings.
}

_, err = s.client.PutRow(putRequest)

if err != nil {
return err
}
Expand Down Expand Up @@ -302,7 +301,6 @@ func (s *AliCloudTableStore) delete(req *bindings.InvokeRequest, resp *bindings.
change.SetCondition(tablestore.RowExistenceExpectation_IGNORE) //nolint:nosnakecase
deleteReq := &tablestore.DeleteRowRequest{DeleteRowChange: change}
_, err = s.client.DeleteRow(deleteReq)

if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion bindings/aws/kinesis/kinesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ func (a *AWSKinesis) registerConsumer(ctx context.Context, streamARN *string) (*
ConsumerName: &a.metadata.ConsumerName,
StreamARN: streamARN,
})

if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions bindings/aws/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (s *AWSS3) get(ctx context.Context, req *bindings.InvokeRequest) (*bindings
if err != nil {
var awsErr awserr.Error
if errors.As(err, &awsErr) && awsErr.Code() == s3.ErrCodeNoSuchKey {
return nil, fmt.Errorf("object not found")
return nil, errors.New("object not found")
}
return nil, fmt.Errorf("s3 binding error: error downloading S3 object: %w", err)
}
Expand Down Expand Up @@ -348,7 +348,7 @@ func (s *AWSS3) delete(ctx context.Context, req *bindings.InvokeRequest) (*bindi
if err != nil {
var awsErr awserr.Error
if errors.As(err, &awsErr) && awsErr.Code() == s3.ErrCodeNoSuchKey {
return nil, fmt.Errorf("object not found")
return nil, errors.New("object not found")
}
return nil, fmt.Errorf("s3 binding error: delete operation failed: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions bindings/aws/ses/ses.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package ses

import (
"context"
"errors"
"fmt"
"reflect"
"strconv"
Expand Down Expand Up @@ -92,13 +93,13 @@ func (a *AWSSES) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bind
metadata := a.metadata.mergeWithRequestMetadata(req)

if metadata.EmailFrom == "" {
return nil, fmt.Errorf("SES binding error: emailFrom property not supplied in configuration- or request-metadata")
return nil, errors.New("SES binding error: emailFrom property not supplied in configuration- or request-metadata")
}
if metadata.EmailTo == "" {
return nil, fmt.Errorf("SES binding error: emailTo property not supplied in configuration- or request-metadata")
return nil, errors.New("SES binding error: emailTo property not supplied in configuration- or request-metadata")
}
if metadata.Subject == "" {
return nil, fmt.Errorf("SES binding error: subject property not supplied in configuration- or request-metadata")
return nil, errors.New("SES binding error: subject property not supplied in configuration- or request-metadata")
}

body, err := strconv.Unquote(string(req.Data))
Expand Down
5 changes: 2 additions & 3 deletions bindings/azure/blobstorage/blobstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ func (a *AzureBlobStorage) create(ctx context.Context, req *bindings.InvokeReque

blockBlobClient := a.containerClient.NewBlockBlobClient(blobName)
_, err = blockBlobClient.UploadBuffer(ctx, req.Data, &uploadOptions)

if err != nil {
return nil, fmt.Errorf("error uploading az blob: %w", err)
}
Expand Down Expand Up @@ -192,7 +191,7 @@ func (a *AzureBlobStorage) get(ctx context.Context, req *bindings.InvokeRequest)
blobDownloadResponse, err := blockBlobClient.DownloadStream(ctx, &downloadOptions)
if err != nil {
if bloberror.HasCode(err, bloberror.BlobNotFound) {
return nil, fmt.Errorf("blob not found")
return nil, errors.New("blob not found")
}
return nil, fmt.Errorf("error downloading az blob: %w", err)
}
Expand Down Expand Up @@ -261,7 +260,7 @@ func (a *AzureBlobStorage) delete(ctx context.Context, req *bindings.InvokeReque
_, err := blockBlobClient.Delete(ctx, &deleteOptions)

if bloberror.HasCode(err, bloberror.BlobNotFound) {
return nil, fmt.Errorf("blob not found")
return nil, errors.New("blob not found")
}

return nil, err
Expand Down
5 changes: 3 additions & 2 deletions bindings/azure/cosmosdb/cosmosdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cosmosdb
import (
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -158,7 +159,7 @@ func (c *CosmosDB) getPartitionKeyValue(key string, obj interface{}) (string, er
}
val, ok := valI.(string)
if !ok {
return "", fmt.Errorf("partition key is not a string")
return "", errors.New("partition key is not a string")
}

if val == "" {
Expand All @@ -172,7 +173,7 @@ func (c *CosmosDB) lookup(m map[string]interface{}, ks []string) (val interface{
var ok bool

if len(ks) == 0 {
return nil, fmt.Errorf("needs at least one key")
return nil, errors.New("needs at least one key")
}

if val, ok = m[ks[0]]; !ok {
Expand Down
10 changes: 5 additions & 5 deletions bindings/azure/signalr/signalr.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (s *SignalR) parseMetadata(md map[string]string) (err error) {
s.accessKey = connectionValue[i+1:]
case "AuthType":
if connectionValue[i+1:] != "aad" {
return fmt.Errorf("invalid value for AuthType in the connection string; only 'aad' is supported")
return errors.New("invalid value for AuthType in the connection string; only 'aad' is supported")
}
useAAD = true
case "ClientId", "ClientSecret", "TenantId":
Expand All @@ -171,14 +171,14 @@ func (s *SignalR) parseMetadata(md map[string]string) (err error) {
}
}
} else if len(connectionValue) != 0 {
return fmt.Errorf("the connection string is invalid or malformed")
return errors.New("the connection string is invalid or malformed")
}
}

// Check here because if we use a connection string, we'd have an explicit "AuthType=aad" option
// We would otherwise catch this issue later, but here we can be more explicit with the error
if s.accessKey == "" && !useAAD {
return fmt.Errorf("missing AccessKey in the connection string")
return errors.New("missing AccessKey in the connection string")
}
}

Expand All @@ -198,7 +198,7 @@ func (s *SignalR) parseMetadata(md map[string]string) (err error) {

// Check for required values
if s.endpoint == "" {
return fmt.Errorf("missing endpoint in the metadata or connection string")
return errors.New("missing endpoint in the metadata or connection string")
}

return nil
Expand Down Expand Up @@ -333,7 +333,7 @@ func (s *SignalR) GetAadClientAccessToken(ctx context.Context, hub string, user

u := fmt.Sprintf("%s/api/hubs/%s/:generateToken?api-version=%s", s.endpoint, hub, apiVersion)
if user != "" {
u += fmt.Sprintf("&userId=%s", url.QueryEscape(user))
u += "&userId=" + url.QueryEscape(user)
}

body, err := s.sendRequestToSignalR(ctx, u, aadToken, nil)
Expand Down
1 change: 0 additions & 1 deletion bindings/azure/signalr/signalr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ func TestWriteShouldSucceed(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
httpTransport.reset()
s.hub = tt.hubInMetadata
Expand Down
2 changes: 1 addition & 1 deletion bindings/azure/storagequeues/storagequeues.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (d *AzureQueueHelper) Read(ctx context.Context, consumer *consumer) error {
}
return nil
} else {
return fmt.Errorf("could not delete message from queue: message ID or pop receipt is nil")
return errors.New("could not delete message from queue: message ID or pop receipt is nil")
}
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/commercetools/commercetools.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (ct *Binding) Init(_ context.Context, metadata bindings.Metadata) error {

baseURLdomain := fmt.Sprintf("%s.%s.commercetools.com", commercetoolsM.Region, commercetoolsM.Provider)
authURL := fmt.Sprintf("https://auth.%s/oauth/token", baseURLdomain)
apiURL := fmt.Sprintf("https://api.%s", baseURLdomain)
apiURL := "https://api." + baseURLdomain

// Create the new client. When an empty value is passed it will use the CTP_*
// environment variables to get the value. The HTTPClient arg is optional,
Expand Down
2 changes: 1 addition & 1 deletion bindings/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (b *Binding) Init(ctx context.Context, meta bindings.Metadata) error {
return err
}
if m.Schedule == "" {
return fmt.Errorf("schedule not set")
return errors.New("schedule not set")
}
_, err = b.parser.Parse(m.Schedule)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions bindings/cron/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestCronRead(t *testing.T) {
return nil, nil
})
// Check if cron triggers 5 times in 5 seconds
for i := int32(0); i < expectedCount; i++ {
for range expectedCount {
// Add time to mock clock in 1 second intervals using loop to allow cron go routine to run
clk.Step(time.Second)
runtime.Gosched()
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestCronReadWithContextCancellation(t *testing.T) {
return nil, nil
})
// Check if cron triggers only 5 times in 10 seconds since context should be cancelled after 5 triggers
for i := 0; i < 10; i++ {
for range 10 {
// Add time to mock clock in 1 second intervals using loop to allow cron go routine to run
clk.Step(time.Second)
runtime.Gosched()
Expand Down
6 changes: 3 additions & 3 deletions bindings/gcp/bucket/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (g *GCPStorage) get(ctx context.Context, req *bindings.InvokeRequest) (*bin
if val, ok := req.Metadata[metadataKey]; ok && val != "" {
key = val
} else {
return nil, fmt.Errorf("gcp bucket binding error: can't read key value")
return nil, errors.New("gcp bucket binding error: can't read key value")
}

var rc io.ReadCloser
Expand Down Expand Up @@ -256,7 +256,7 @@ func (g *GCPStorage) delete(ctx context.Context, req *bindings.InvokeRequest) (*
if val, ok := req.Metadata[metadataKey]; ok && val != "" {
key = val
} else {
return nil, fmt.Errorf("gcp bucketgcp bucket binding error: can't read key value")
return nil, errors.New("gcp bucketgcp bucket binding error: can't read key value")
}

object := g.client.Bucket(g.metadata.Bucket).Object(key)
Expand Down Expand Up @@ -355,7 +355,7 @@ func (g *GCPStorage) sign(ctx context.Context, req *bindings.InvokeRequest) (*bi
if val, ok := req.Metadata[metadataKey]; ok && val != "" {
key = val
} else {
return nil, fmt.Errorf("gcp bucket binding error: can't read key value")
return nil, errors.New("gcp bucket binding error: can't read key value")
}

if metadata.SignTTL == "" {
Expand Down
7 changes: 4 additions & 3 deletions bindings/graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package graphql
import (
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
"regexp"
Expand Down Expand Up @@ -73,7 +74,7 @@ func (gql *GraphQL) Init(_ context.Context, meta bindings.Metadata) error {
}

if m.Endpoint == "" {
return fmt.Errorf("GraphQL Error: Missing GraphQL URL")
return errors.New("GraphQL Error: Missing GraphQL URL")
}

// Connect to GraphQL Server
Expand Down Expand Up @@ -101,11 +102,11 @@ func (gql *GraphQL) Operations() []bindings.OperationKind {
// Invoke handles all invoke operations.
func (gql *GraphQL) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) {
if req == nil {
return nil, fmt.Errorf("GraphQL Error: Invoke request required")
return nil, errors.New("GraphQL Error: Invoke request required")
}

if req.Metadata == nil {
return nil, fmt.Errorf("GraphQL Error: Metadata required")
return nil, errors.New("GraphQL Error: Metadata required")
}
gql.logger.Debugf("operation: %v", req.Operation)

Expand Down
2 changes: 1 addition & 1 deletion bindings/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (h *HTTPSource) Invoke(parentCtx context.Context, req *bindings.InvokeReque
}

// Create an error for non-200 status codes unless suppressed.
if errorIfNot2XX && resp.StatusCode/100 != 2 {
if errorIfNot2XX && resp.StatusCode/100 != 2 { //nolint:usestdlibvars
err = fmt.Errorf("received status code %d", resp.StatusCode)
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (h *HTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
h.Path = req.URL.Path
if strings.TrimPrefix(h.Path, "/") == "large" {
// Write 5KB
for i := 0; i < 1<<10; i++ {
for range 1 << 10 {
fmt.Fprint(w, "12345")
}
return
Expand Down
12 changes: 6 additions & 6 deletions bindings/huawei/obs/obs.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ func (o *HuaweiOBS) parseMetadata(meta bindings.Metadata) (*obsMetadata, error)
}

if m.Bucket == "" {
return nil, fmt.Errorf("missing obs bucket name")
return nil, errors.New("missing obs bucket name")
}
if m.Endpoint == "" {
return nil, fmt.Errorf("missing obs endpoint")
return nil, errors.New("missing obs endpoint")
}
if m.AccessKey == "" {
return nil, fmt.Errorf("missing the huawei access key")
return nil, errors.New("missing the huawei access key")
}
if m.SecretKey == "" {
return nil, fmt.Errorf("missing the huawei secret key")
return nil, errors.New("missing the huawei secret key")
}

o.logger.Debugf("Huawei OBS metadata=[%s]", m)
Expand Down Expand Up @@ -212,7 +212,7 @@ func (o *HuaweiOBS) get(ctx context.Context, req *bindings.InvokeRequest) (*bind
if val, ok := req.Metadata[metadataKey]; ok && val != "" {
key = val
} else {
return nil, fmt.Errorf("obs binding error: can't read key value")
return nil, errors.New("obs binding error: can't read key value")
}

input := &obs.GetObjectInput{}
Expand Down Expand Up @@ -252,7 +252,7 @@ func (o *HuaweiOBS) delete(ctx context.Context, req *bindings.InvokeRequest) (*b
if val, ok := req.Metadata[metadataKey]; ok && val != "" {
key = val
} else {
return nil, fmt.Errorf("obs binding error: can't read key value")
return nil, errors.New("obs binding error: can't read key value")
}

input := &obs.DeleteObjectInput{}
Expand Down
Loading

0 comments on commit facd508

Please sign in to comment.