Add errcheck and gosimple linters (#9729)

* Add errcheck linter

* Check unchecked error

* Add gosimple linter

* Remove type assertion to same type

* Omit nil check

len() for nil slices is defined as zero

* Revert "Remove type assertion to same type"

This reverts commit af69ca1ac8a4f0243a5ccaf5042dbebad6d2cf1c.

* Revert "Revert "Remove type assertion to same type""

This reverts commit 5fe8931504fa22347d04d3d06558e5f478f5bf50.

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
Håvard Anda Estensen 2021-10-23 00:40:03 +02:00 committed by GitHub
parent 5b3375638a
commit 7f3ec4221f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 7 deletions

View File

@ -39,7 +39,7 @@ jobs:
- name: Golangci-lint - name: Golangci-lint
uses: golangci/golangci-lint-action@v2 uses: golangci/golangci-lint-action@v2
with: with:
args: --print-issued-lines --sort-results --no-config --timeout=10m --disable-all -E deadcode --skip-files=validator/web/site_data.go args: --print-issued-lines --sort-results --no-config --timeout=10m --disable-all -E deadcode -E errcheck -E gosimple --skip-files=validator/web/site_data.go
build: build:
name: Build name: Build

View File

@ -9,7 +9,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/time"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
stateAltair "github.com/prysmaticlabs/prysm/beacon-chain/state/v2" stateAltair "github.com/prysmaticlabs/prysm/beacon-chain/state/v2"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@ -79,8 +78,6 @@ func TestUpgradeToAltair(t *testing.T) {
preForkState := st.Copy() preForkState := st.Copy()
aState, err := altair.UpgradeToAltair(context.Background(), st) aState, err := altair.UpgradeToAltair(context.Background(), st)
require.NoError(t, err) require.NoError(t, err)
_, ok := aState.(state.BeaconStateAltair)
require.Equal(t, true, ok)
require.Equal(t, preForkState.GenesisTime(), aState.GenesisTime()) require.Equal(t, preForkState.GenesisTime(), aState.GenesisTime())
require.DeepSSZEqual(t, preForkState.GenesisValidatorRoot(), aState.GenesisValidatorRoot()) require.DeepSSZEqual(t, preForkState.GenesisValidatorRoot(), aState.GenesisValidatorRoot())

View File

@ -9,6 +9,7 @@ import (
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
aggtesting "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/attestation/aggregation/testing" aggtesting "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/attestation/aggregation/testing"
"github.com/prysmaticlabs/prysm/testing/require"
) )
func BenchmarkProposerAtts_sortByProfitability(b *testing.B) { func BenchmarkProposerAtts_sortByProfitability(b *testing.B) {
@ -49,7 +50,8 @@ func BenchmarkProposerAtts_sortByProfitability(b *testing.B) {
for i, att := range atts { for i, att := range atts {
attsCopy[i] = ethpb.CopyAttestation(att) attsCopy[i] = ethpb.CopyAttestation(att)
} }
attsCopy.sortByProfitability() _, err := attsCopy.sortByProfitability()
require.NoError(b, err, "Could not sort attestations by profitability")
} }
for _, tt := range tests { for _, tt := range tests {

View File

@ -79,7 +79,7 @@ func (s *Service) validateWithBatchVerifier(ctx context.Context, message string,
} }
func verifyBatch(verifierBatch []*signatureVerifier) { func verifyBatch(verifierBatch []*signatureVerifier) {
if verifierBatch == nil || len(verifierBatch) == 0 { if len(verifierBatch) == 0 {
return return
} }
aggSet := verifierBatch[0].set aggSet := verifierBatch[0].set

View File

@ -57,7 +57,7 @@ func AggregatePublicKeys(pubs [][]byte) (common.PublicKey, error) {
if features.Get().SkipBLSVerify { if features.Get().SkipBLSVerify {
return &PublicKey{}, nil return &PublicKey{}, nil
} }
if pubs == nil || len(pubs) == 0 { if len(pubs) == 0 {
return nil, errors.New("nil or empty public keys") return nil, errors.New("nil or empty public keys")
} }
agg := new(blstAggregatePublicKey) agg := new(blstAggregatePublicKey)