Skip to content

Commit

Permalink
Revert "Lint fixes (#3526)"
Browse files Browse the repository at this point in the history
This reverts commit facd508.
  • Loading branch information
artursouza committed Dec 18, 2024
1 parent 042151e commit aed64c4
Show file tree
Hide file tree
Showing 140 changed files with 463 additions and 456 deletions.
7 changes: 0 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,6 @@ 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 @@ -322,5 +317,3 @@ 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 --max-same-issues 0 --max-issues-per-linter 0
$(GOLANGCI_LINT) run --timeout=20m

################################################################################
# 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"
"errors"
"fmt"
"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, errors.New("SLS binding error: project property not supplied")
return nil, fmt.Errorf("SLS binding error: project property not supplied")
}
if logstore := req.Metadata["logstore"]; logstore == "" {
return nil, errors.New("SLS binding error: logstore property not supplied")
return nil, fmt.Errorf("SLS binding error: logstore property not supplied")
}
if topic := req.Metadata["topic"]; topic == "" {
return nil, errors.New("SLS binding error: topic property not supplied")
return nil, fmt.Errorf("SLS binding error: topic property not supplied")
}
if source := req.Metadata["source"]; source == "" {
return nil, errors.New("SLS binding error: source property not supplied")
return nil, fmt.Errorf("SLS binding error: source property not supplied")
}

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

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

if err != nil {
return err
}
Expand Down Expand Up @@ -301,6 +302,7 @@ 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: 1 addition & 0 deletions bindings/aws/kinesis/kinesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ 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, errors.New("object not found")
return nil, fmt.Errorf("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, errors.New("object not found")
return nil, fmt.Errorf("object not found")
}
return nil, fmt.Errorf("s3 binding error: delete operation failed: %w", err)
}
Expand Down
7 changes: 3 additions & 4 deletions bindings/aws/ses/ses.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package ses

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

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

body, err := strconv.Unquote(string(req.Data))
Expand Down
5 changes: 3 additions & 2 deletions bindings/azure/blobstorage/blobstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ 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 @@ -191,7 +192,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, errors.New("blob not found")
return nil, fmt.Errorf("blob not found")
}
return nil, fmt.Errorf("error downloading az blob: %w", err)
}
Expand Down Expand Up @@ -260,7 +261,7 @@ func (a *AzureBlobStorage) delete(ctx context.Context, req *bindings.InvokeReque
_, err := blockBlobClient.Delete(ctx, &deleteOptions)

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

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

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

if len(ks) == 0 {
return nil, errors.New("needs at least one key")
return nil, fmt.Errorf("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 errors.New("invalid value for AuthType in the connection string; only 'aad' is supported")
return fmt.Errorf("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 errors.New("the connection string is invalid or malformed")
return fmt.Errorf("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 errors.New("missing AccessKey in the connection string")
return fmt.Errorf("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 errors.New("missing endpoint in the metadata or connection string")
return fmt.Errorf("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 += "&userId=" + url.QueryEscape(user)
u += fmt.Sprintf("&userId=%s", url.QueryEscape(user))
}

body, err := s.sendRequestToSignalR(ctx, u, aadToken, nil)
Expand Down
1 change: 1 addition & 0 deletions bindings/azure/signalr/signalr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ 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 errors.New("could not delete message from queue: message ID or pop receipt is nil")
return fmt.Errorf("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 := "https://api." + baseURLdomain
apiURL := fmt.Sprintf("https://api.%s", 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 errors.New("schedule not set")
return fmt.Errorf("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 range expectedCount {
for i := int32(0); i < expectedCount; i++ {
// 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 range 10 {
for i := 0; i < 10; i++ {
// 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, errors.New("gcp bucket binding error: can't read key value")
return nil, fmt.Errorf("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, errors.New("gcp bucketgcp bucket binding error: can't read key value")
return nil, fmt.Errorf("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, errors.New("gcp bucket binding error: can't read key value")
return nil, fmt.Errorf("gcp bucket binding error: can't read key value")
}

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

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

// Connect to GraphQL Server
Expand Down Expand Up @@ -102,11 +101,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, errors.New("GraphQL Error: Invoke request required")
return nil, fmt.Errorf("GraphQL Error: Invoke request required")
}

if req.Metadata == nil {
return nil, errors.New("GraphQL Error: Metadata required")
return nil, fmt.Errorf("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 { //nolint:usestdlibvars
if errorIfNot2XX && resp.StatusCode/100 != 2 {
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 range 1 << 10 {
for i := 0; i < 1<<10; i++ {
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, errors.New("missing obs bucket name")
return nil, fmt.Errorf("missing obs bucket name")
}
if m.Endpoint == "" {
return nil, errors.New("missing obs endpoint")
return nil, fmt.Errorf("missing obs endpoint")
}
if m.AccessKey == "" {
return nil, errors.New("missing the huawei access key")
return nil, fmt.Errorf("missing the huawei access key")
}
if m.SecretKey == "" {
return nil, errors.New("missing the huawei secret key")
return nil, fmt.Errorf("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, errors.New("obs binding error: can't read key value")
return nil, fmt.Errorf("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, errors.New("obs binding error: can't read key value")
return nil, fmt.Errorf("obs binding error: can't read key value")
}

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

0 comments on commit aed64c4

Please sign in to comment.