Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional linting rules. #62

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 66 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
# This file is not a configuration example,
# it contains the exhaustive configuration with explanations of the options.

issues:
# Which files to exclude: they will be analyzed, but issues from them won't be reported.
# There is no need to include all autogenerated files,
# we confidently recognize autogenerated files.
# If it's not, please let us know.
# "/" will be replaced by current OS file path separator to properly work on Windows.
# Default: []
exclude-files:
- ".*_ssz\\.go$"

# Options for analysis running.
run:
# The default concurrency value is the number of available CPU.
Expand Down Expand Up @@ -39,15 +49,6 @@ run:
# Default: true
# skip-dirs-use-default: false

# Which files to skip: they will be analyzed, but issues from them won't be reported.
# Default value is empty list,
# but there is no need to include all autogenerated files,
# we confidently recognize autogenerated files.
# If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work on Windows.
skip-files:
- ".*_ssz\\.go$"

# If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
Expand All @@ -68,7 +69,7 @@ run:
# Define the Go version limit.
# Mainly related to generics support since go1.18.
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.18
go: '1.19'
# go: '1.19'


# output configuration options
Expand Down Expand Up @@ -108,6 +109,61 @@ linters-settings:
lll:
line-length: 132

nlreturn:
# Allow three-line blocks without requiring a newline.
block-size: 3

revive:
ignore-generated-header: true
severity: error
confidence: 0.1
errorCode: 0
warningCode: 0
rules:
- name: atomic
- name: blank-imports
- name: comment-spacings
- name: confusing-results
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: datarace
- name: defer
- name: dot-imports
- name: duplicated-imports
- name: early-return
- name: error-strings
- name: errorf
- name: exported
- name: file-header
- name: identical-branches
- name: import-alias-naming
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: modifies-value-receiver
- name: range-val-address
- name: range-val-in-closure
- name: range
- name: receiver-naming
- name: string-of-int
- name: superfluous-else
- name: time-equal
- name: time-naming
- name: unchecked-type-assertion
- name: unhandled-error
arguments:
- "fmt.Fprint"
- "fmt.Fprintf"
- "fmt.Fprintln"
- name: unnecessary-stmt
- name: unused-parameter
- name: unused-receiver
- name: use-any
- name: useless-break
- name: var-naming
- name: waitgroup-by-value

stylecheck:
checks: [ "all", "-ST1000" ]

Expand Down Expand Up @@ -135,7 +191,6 @@ linters:
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocognit
- goerr113
- golint
Expand All @@ -146,8 +201,6 @@ linters:
- lll
- maintidx
- maligned
- nilnil
- nlreturn
- nosnakecase
- perfsprint
- scopelint
Expand Down
20 changes: 14 additions & 6 deletions core/stores.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020, 2022 Attestant Limited.
// Copyright © 2020 - 2024 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -60,6 +60,7 @@ type S3StoreCredentials struct {
func InitStores(ctx context.Context, majordomo majordomo.Service, storeDefinitions []*Store) ([]e2wtypes.Store, error) {
if len(storeDefinitions) == 0 {
log.Warn().Msg("No stores configured; using default")

return initDefaultStores(), nil
}
res := make([]e2wtypes.Store, 0, len(storeDefinitions))
Expand Down Expand Up @@ -89,6 +90,7 @@ func InitStores(ctx context.Context, majordomo majordomo.Service, storeDefinitio

res = append(res, store)
}

return res, nil
}

Expand All @@ -113,6 +115,7 @@ func initFilesystemStore(ctx context.Context,
opts = append(opts, filesystem.WithLocation(storeDefinition.Location))
}
store := filesystem.New(opts...)

return store, nil
}

Expand All @@ -134,11 +137,13 @@ func initS3Store(ctx context.Context,
opts = append(opts, s3.WithPassphrase(passphrase))
}
if storeDefinition.S3 != nil {
opts = append(opts, s3.WithRegion(storeDefinition.S3.Region))
opts = append(opts, s3.WithID([]byte(storeDefinition.S3.ID)))
opts = append(opts, s3.WithBucket(storeDefinition.S3.Bucket))
opts = append(opts, s3.WithPath(storeDefinition.S3.Path))
opts = append(opts, s3.WithEndpoint(storeDefinition.S3.Endpoint))
opts = append(opts,
s3.WithRegion(storeDefinition.S3.Region),
s3.WithID([]byte(storeDefinition.S3.ID)),
s3.WithBucket(storeDefinition.S3.Bucket),
s3.WithPath(storeDefinition.S3.Path),
s3.WithEndpoint(storeDefinition.S3.Endpoint),
)
}
if storeDefinition.S3 != nil && storeDefinition.S3.Credentials != nil {
id, err := majordomo.Fetch(ctx, storeDefinition.S3.Credentials.ID)
Expand All @@ -156,6 +161,7 @@ func initS3Store(ctx context.Context,
if err != nil {
return nil, err
}

return store, nil
}

Expand All @@ -166,12 +172,14 @@ func initScratchStore(_ context.Context,
log.Trace().Str("name", storeDefinition.Name).Msg("Adding scratch store")

store := scratch.New()

return store
}

// initDefaultStores initialises the default stores.
func initDefaultStores() []e2wtypes.Store {
res := make([]e2wtypes.Store, 1)
res[0] = filesystem.New()

return res
}
66 changes: 33 additions & 33 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ go 1.21
toolchain go1.21.6

require (
github.com/attestantio/go-eth2-client v0.21.1
github.com/aws/aws-sdk-go v1.51.12
github.com/attestantio/go-eth2-client v0.21.3
github.com/aws/aws-sdk-go v1.51.29
github.com/dgraph-io/badger/v2 v2.2007.4
github.com/ferranbt/fastssz v0.1.3
github.com/google/uuid v1.6.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/herumi/bls-eth-go-binary v1.34.2
github.com/herumi/bls-eth-go-binary v1.35.0
github.com/jackc/puddle v1.3.0
github.com/mitchellh/go-homedir v1.1.0
github.com/opentracing/opentracing-go v1.2.0
Expand All @@ -34,25 +34,26 @@ require (
github.com/wealdtech/go-eth2-wallet-store-scratch v1.7.2
github.com/wealdtech/go-eth2-wallet-types/v2 v2.11.0
github.com/wealdtech/go-majordomo v1.1.1
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
go.opentelemetry.io/otel/sdk v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
google.golang.org/grpc v1.62.1
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0
go.opentelemetry.io/otel v1.26.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.26.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.26.0
go.opentelemetry.io/otel/sdk v1.26.0
go.opentelemetry.io/otel/trace v1.26.0
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.33.0
)

require (
cloud.google.com/go/compute v1.25.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/auth v0.3.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.7 // indirect
cloud.google.com/go/secretmanager v1.12.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
Expand All @@ -63,7 +64,7 @@ require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-yaml v1.11.3 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/glog v1.2.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand All @@ -73,18 +74,18 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.51.1 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.14.0 // indirect
github.com/prysmaticlabs/go-bitfield v0.0.0-20240328144219-a1caa50c3a1e // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -97,24 +98,23 @@ require (
github.com/wealdtech/go-eth2-util v1.8.2 // indirect
github.com/wealdtech/go-indexer v1.1.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.19.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.172.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/api v0.176.1 // indirect
google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading
Loading