Skip to content

Commit

Permalink
Merge pull request #130 from attestantio/linting
Browse files Browse the repository at this point in the history
Linting and workflows.
  • Loading branch information
mcdee authored Apr 22, 2024
2 parents 48c181e + b39e780 commit cf3821c
Show file tree
Hide file tree
Showing 157 changed files with 702 additions and 333 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ on:
branches:
- master
pull_request:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: '^1.20'
- uses: actions/checkout@v3
cache: false
go-version: '1.20'
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: latest
args: --timeout=60m
20 changes: 20 additions & 0 deletions .github/workflows/revive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: revive
on:
push:
branches:
- master
pull_request:

permissions:
contents: read

jobs:
revive:
runs-on: ubuntu-22.04
steps:
- uses: actions/setup-go@v5
with:
cache: false
go-version: '1.20'
- uses: actions/checkout@v4
- uses: morphy2k/revive-action@v2
12 changes: 7 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ on:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: '^1.20'
- uses: actions/checkout@v3
- uses: n8maninger/action-golang-test@v1
cache: false
go-version: '1.20'
- uses: actions/checkout@v4
- uses: n8maninger/action-golang-test@v2
with:
args: "-race;-timeout=30m"

50 changes: 50 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,56 @@ linters-settings:
lll:
line-length: 132

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"
- 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
4 changes: 2 additions & 2 deletions api/submitblindedproposalopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package api

import v2 "github.com/attestantio/go-eth2-client/api/v2"
import apiv2 "github.com/attestantio/go-eth2-client/api/v2"

// SubmitBlindedProposalOpts are the options for submitting proposals.
type SubmitBlindedProposalOpts struct {
Expand All @@ -23,5 +23,5 @@ type SubmitBlindedProposalOpts struct {
Proposal *VersionedSignedBlindedProposal

// BroadcastValidation is the validation required of the consensus node before broadcasting the proposal.
BroadcastValidation *v2.BroadcastValidation
BroadcastValidation *apiv2.BroadcastValidation
}
4 changes: 2 additions & 2 deletions api/submitproposalopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package api

import v2 "github.com/attestantio/go-eth2-client/api/v2"
import apiv2 "github.com/attestantio/go-eth2-client/api/v2"

// SubmitProposalOpts are the options for submitting proposals.
type SubmitProposalOpts struct {
Expand All @@ -23,5 +23,5 @@ type SubmitProposalOpts struct {
Proposal *VersionedSignedProposal

// BroadcastValidation is the validation required of the consensus node before broadcasting the proposal.
BroadcastValidation *v2.BroadcastValidation
BroadcastValidation *apiv2.BroadcastValidation
}
1 change: 0 additions & 1 deletion api/v1/capella/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ package capella
// Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work.
//go:generate rm -f blindedbeaconblockbody_ssz.go blindedbeaconblock_ssz.go signedblindedbeaconblock_ssz.go
//go:generate sszgen --include ../../../spec/phase0,../../../spec/altair,../../../spec/bellatrix,../../../spec/capella -path . --suffix ssz -objs BlindedBeaconBlockBody,BlindedBeaconBlock,SignedBlindedBeaconBlock
//nogo:generate sszgen --include ../../../spec/phase0,../../../spec/altair,../../../spec/bellatrix,../../../spec/capella --exclude-objs=blindedBeaconBlockBodyJSON,blindedBeaconBlockBodyYAML,blindedBeaconBlockJSON,blindedBeaconBlockYAML,signedBlindedBeaconBlockJSON,signedBlindedBeaconBlockYAML -path . --suffix ssz -objs BlindedBeaconBlockBody,BlindedBeaconBlock,SignedBlindedBeaconBlock
//go:generate goimports -w blindedbeaconblockbody_ssz.go blindedbeaconblock_ssz.go signedblindedbeaconblock_ssz.go
8 changes: 4 additions & 4 deletions api/v1/deneb/blockcontents_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func (b *BlockContents) MarshalYAML() ([]byte, error) {
// UnmarshalYAML implements yaml.Unmarshaler.
func (b *BlockContents) UnmarshalYAML(input []byte) error {
// We unmarshal to the JSON struct to save on duplicate code.
var data blockContentsJSON
if err := yaml.Unmarshal(input, &data); err != nil {
var unmarshaled blockContentsJSON
if err := yaml.Unmarshal(input, &unmarshaled); err != nil {
return errors.Wrap(err, "failed to unmarshal YAML")
}

bytes, err := json.Marshal(data)
marshaled, err := json.Marshal(unmarshaled)
if err != nil {
return errors.Wrap(err, "failed to marshal JSON")
}

return b.UnmarshalJSON(bytes)
return b.UnmarshalJSON(marshaled)
}
8 changes: 4 additions & 4 deletions api/v1/deneb/signedblockcontents_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func (s *SignedBlockContents) MarshalYAML() ([]byte, error) {
// UnmarshalYAML implements yaml.Unmarshaler.
func (s *SignedBlockContents) UnmarshalYAML(input []byte) error {
// We unmarshal to the JSON struct to save on duplicate code.
var data signedBlockContentsJSON
if err := yaml.Unmarshal(input, &data); err != nil {
var unmarshaled signedBlockContentsJSON
if err := yaml.Unmarshal(input, &unmarshaled); err != nil {
return errors.Wrap(err, "failed to unmarshal YAML")
}

bytes, err := json.Marshal(data)
marshaled, err := json.Marshal(unmarshaled)
if err != nil {
return errors.Wrap(err, "failed to marshal JSON")
}

return s.UnmarshalJSON(bytes)
return s.UnmarshalJSON(marshaled)
}
8 changes: 4 additions & 4 deletions api/v1/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Event struct {
// Topic is the topic of the event.
Topic string
// Data is the data of the event.
Data interface{}
Data any
}

// SupportedEventTopics is a map of supported event topics.
Expand All @@ -45,8 +45,8 @@ var SupportedEventTopics = map[string]bool{

// eventJSON is the spec representation of the struct.
type eventJSON struct {
Topic string `json:"topic"`
Data map[string]interface{} `json:"data"`
Topic string `json:"topic"`
Data map[string]any `json:"data"`
}

// MarshalJSON implements json.Marshaler.
Expand All @@ -56,7 +56,7 @@ func (e *Event) MarshalJSON() ([]byte, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to marshal data")
}
var unmarshalled map[string]interface{}
var unmarshalled map[string]any
if err := json.Unmarshal(data, &unmarshalled); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal data")
}
Expand Down
20 changes: 10 additions & 10 deletions api/v1/forkchoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,20 @@ type ForkChoiceNode struct {
// ExecutiionBlockHash is the execution block hash of the node.
ExecutionBlockHash phase0.Root
// ExtraData is the extra data of the node.
ExtraData map[string]interface{}
ExtraData map[string]any
}

// forkChoiceNodeJSON is the json representation of the struct.
type forkChoiceNodeJSON struct {
Slot string `json:"slot"`
BlockRoot string `json:"block_root"`
ParentRoot string `json:"parent_root"`
JustifiedEpoch string `json:"justified_epoch"`
FinalizedEpoch string `json:"finalized_epoch"`
Weight string `json:"weight"`
Validity string `json:"validity"`
ExecutionBlockHash string `json:"execution_block_hash"`
ExtraData map[string]interface{} `json:"extra_data,omitempty"`
Slot string `json:"slot"`
BlockRoot string `json:"block_root"`
ParentRoot string `json:"parent_root"`
JustifiedEpoch string `json:"justified_epoch"`
FinalizedEpoch string `json:"finalized_epoch"`
Weight string `json:"weight"`
Validity string `json:"validity"`
ExecutionBlockHash string `json:"execution_block_hash"`
ExtraData map[string]any `json:"extra_data,omitempty"`
}

// MarshalJSON implements json.Marshaler.
Expand Down
2 changes: 1 addition & 1 deletion api/versionedsignedproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type VersionedSignedProposal struct {
DenebBlinded *apiv1deneb.SignedBlindedBeaconBlock
}

// AssertPresnet throws an error if the expected proposal
// AssertPresent throws an error if the expected proposal
// given the version and blinded fields is not present.
func (v *VersionedSignedProposal) AssertPresent() error {
switch v.Version {
Expand Down
6 changes: 3 additions & 3 deletions auto/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package auto
import (
"context"

client "github.com/attestantio/go-eth2-client"
consensusclient "github.com/attestantio/go-eth2-client"
"github.com/attestantio/go-eth2-client/http"
"github.com/pkg/errors"
"github.com/rs/zerolog"
Expand All @@ -28,7 +28,7 @@ var log zerolog.Logger

// New creates a new Ethereum 2 client service, trying different implementations at the given address.
// Deprecated. Use the `http` module instead.
func New(ctx context.Context, params ...Parameter) (client.Service, error) {
func New(ctx context.Context, params ...Parameter) (consensusclient.Service, error) {
parameters, err := parseAndCheckParameters(params...)
if err != nil {
return nil, errors.Wrap(err, "problem with parameters")
Expand All @@ -51,7 +51,7 @@ func New(ctx context.Context, params ...Parameter) (client.Service, error) {
return nil, errors.New("failed to connect to Ethereum 2 client with any known method")
}

func tryHTTP(ctx context.Context, parameters *parameters) (client.Service, error) {
func tryHTTP(ctx context.Context, parameters *parameters) (consensusclient.Service, error) {
httpParameters := make([]http.Parameter, 0)
httpParameters = append(httpParameters, http.WithLogLevel(parameters.logLevel))
httpParameters = append(httpParameters, http.WithAddress(parameters.address))
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ go 1.20

require (
github.com/ferranbt/fastssz v0.1.3
github.com/goccy/go-yaml v1.9.2
github.com/goccy/go-yaml v1.11.3
github.com/golang/snappy v0.0.4
github.com/holiman/uint256 v1.2.4
github.com/huandu/go-clone v1.6.0
github.com/huandu/go-clone/generic v1.6.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.16.0
github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7
github.com/prysmaticlabs/go-bitfield v0.0.0-20240328144219-a1caa50c3a1e
github.com/r3labs/sse/v2 v2.10.0
github.com/rs/zerolog v1.32.0
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/otel v1.16.0
golang.org/x/crypto v0.20.0
go.opentelemetry.io/otel/trace v1.16.0
golang.org/x/crypto v0.22.0
golang.org/x/sync v0.2.0
)

Expand All @@ -41,9 +42,8 @@ require (
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
Expand Down
Loading

0 comments on commit cf3821c

Please sign in to comment.