Skip to content

Commit

Permalink
Adapt .golangci.yml to latest version and fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Mar 20, 2024
1 parent 0b5258b commit 24bb64d
Show file tree
Hide file tree
Showing 50 changed files with 94 additions and 99 deletions.
72 changes: 51 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ linters-settings:
simplify: true
goimports:
local-prefixes: github.com/iotaledger
golint:
min-confidence: 0.9
gocyclo:
min-complexity: 15
govet:
check-shadowing: false
disable:
- shadow
misspell:
locale: US
staticcheck:
checks: ["all"]
nlreturn:
block-size: 2
stylecheck:
initialisms: ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS"]
nlreturn:
block-size: 3
depguard:
rules:
main:
Expand All @@ -36,74 +35,99 @@ linters:
disable-all: true
# Enable specific linter
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- varcheck
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
#- containedctx
#- contextcheck # this linter is buggy and renders all nolint rules useless
- copyloopvar
#- cyclop
- decorder
- depguard
- dogsled
- dupl
- dupword
- durationcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
#- exhaustive
#- exhaustruct
- exportloopref
#- forbidigo
- forcetypeassert
#- funlen
#- gci
- ginkgolinter
- gocheckcompilerdirectives
#- gochecknoglobals
#- gochecknoinits
#- gochecksumtype
#- gocognit
- goconst
- gocritic
#- gocyclo
- godot
#- godox # we should reenable that to fix all TODOs
#- goerr113
#- godox
- goerr113
- gofmt
#- gofumpt
- goheader
- goimports
- golint
#- gomnd
- gomoddirectives
#- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosmopolitan
- grouper
- ifshort
- importas
#- interfacer
- inamedparam
#- interfacebloat
- intrange
#- ireturn
#- lll
- loggercheck
#- maintidx
- makezero
#- maligned
- mirror
- misspell
- musttag
- nakedret
#- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nolintlint
#- nonamedreturns
- nosnakecase
- nosprintfhostport
- paralleltest
#- perfsprint
- prealloc
- predeclared
- promlinter
- protogetter
- reassign
- revive
- rowserrcheck
- scopelint
- sloglint
- spancheck
- sqlclosecheck
- structcheck
- stylecheck
#- tagalign
- tagliatelle
- tenv
- testableexamples
- testifylint
- testpackage
- thelper
- tparallel
Expand All @@ -112,8 +136,14 @@ linters:
- usestdlibvars
#- varnamelen
- wastedassign
- whitespace
#- wrapcheck
#- wsl
- zerologlint

issues:
exclude-files:
- ".*_test.go$"
# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
Expand Down
1 change: 1 addition & 0 deletions address_capabilities_bitmask.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type AddressCapabilitiesBitMask []byte
func AddressCapabilitiesBitMaskFromBytes(bytes []byte) (AddressCapabilitiesBitMask, int, error) {
var result AddressCapabilitiesBitMask
consumed, err := CommonSerixAPI().Decode(context.TODO(), bytes, &result)

return result, consumed, err
}

Expand Down
2 changes: 1 addition & 1 deletion address_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (s *InMemoryAddressSigner) privateKeyForAddress(addr Address) (crypto.Priva
case *Ed25519Address:
return privateKeyForEd25519Address(underlyingAddr)
default:
panic(fmt.Sprintf("underlying address type %T in restricted address is not supported in the the address signer since it only handles addresses backed by keypairs", addr))
panic(fmt.Sprintf("underlying address type %T in restricted address is not supported in the address signer since it only handles addresses backed by keypairs", addr))
}

case *ImplicitAccountCreationAddress:
Expand Down
2 changes: 1 addition & 1 deletion address_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//nolint:scopelint,dupl,revive
//nolint:dupl,revive
package iotago_test

import (
Expand Down
4 changes: 2 additions & 2 deletions api/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
// ParameterPageSize is used to specify the page size.
ParameterPageSize = "pageSize"

// ParameterCursor is used to specify the the point from which the response should continue for paginated results.
// ParameterCursor is used to specify the point from which the response should continue for paginated results.
ParameterCursor = "cursor"

// ParameterSlot is used to identify a slot.
Expand Down Expand Up @@ -60,7 +60,7 @@ const (
// ParameterPeerID is used to identify a peer.
ParameterPeerID = "peerId"

// ParameterBech32Address is used to to represent bech32 address.
// ParameterBech32Address is used to represent bech32 address.
ParameterBech32Address = "bech32Address"

// ParameterAddress is used to identify an address.
Expand Down
2 changes: 1 addition & 1 deletion api_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type basicProtocolParameters struct {

// StorageScoreParameters defines the Storage Score Parameters used by the given network.
StorageScoreParameters StorageScoreParameters `serix:""`
// WorkScoreParameters defines the work score parameters used by by the given network.
// WorkScoreParameters defines the work score parameters used by the given network.
WorkScoreParameters WorkScoreParameters `serix:""`
// ManaParameters defines the mana parameters used by the given network.
ManaParameters ManaParameters `serix:""`
Expand Down
8 changes: 4 additions & 4 deletions api_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import "time"

type APIProvider interface {
// APIForVersion returns the API for the given version.
APIForVersion(Version) (API, error)
APIForVersion(version Version) (API, error)

// APIForTime returns the API for the given time.
APIForTime(time.Time) API
APIForTime(ts time.Time) API

// APIForSlot returns the API for the given slot.
APIForSlot(SlotIndex) API
APIForSlot(slot SlotIndex) API

// APIForEpoch returns the API for the given epoch.
APIForEpoch(EpochIndex) API
APIForEpoch(epoch EpochIndex) API

// CommittedAPI returns the API for the last committed slot.
CommittedAPI() API
Expand Down
1 change: 0 additions & 1 deletion api_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:scopelint
package iotago_test

import (
Expand Down
1 change: 0 additions & 1 deletion api_v3.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:dupl
package iotago

import (
Expand Down
1 change: 0 additions & 1 deletion bech32/bech32_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:scopelint
package bech32_test

import (
Expand Down
4 changes: 2 additions & 2 deletions bech32/chars.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ func newEncoding(charset string) *encoding {
e := new(encoding)
copy(e.enc[:], charset)

for i := 0; i < len(e.decMap); i++ {
for i := range len(e.decMap) {
e.decMap[i] = 0xFF
}
for i := 0; i < len(charset); i++ {
for i := range len(charset) {
e.decMap[charset[i]] = uint8(i)
}

Expand Down
2 changes: 2 additions & 0 deletions block_issuer_key_ed25519_pubkeyhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Ed25519PublicKeyHashBlockIssuerKey struct {
func Ed25519PublicKeyHashBlockIssuerKeyFromImplicitAccountCreationAddress(address *ImplicitAccountCreationAddress) *Ed25519PublicKeyHashBlockIssuerKey {
cpy := [Ed25519PublicKeyHashBytesLength]byte{}
copy(cpy[:], address[:])

return &Ed25519PublicKeyHashBlockIssuerKey{PublicKeyHash: cpy}
}

Expand All @@ -41,6 +42,7 @@ func Ed25519PublicKeyHashBlockIssuerKeyFromPublicKey(pubKey hiveEd25519.PublicKe
func (key *Ed25519PublicKeyHashBlockIssuerKey) Clone() BlockIssuerKey {
cpy := [Ed25519PublicKeyHashBytesLength]byte{}
copy(cpy[:], key.PublicKeyHash[:])

return &Ed25519PublicKeyHashBlockIssuerKey{
PublicKeyHash: cpy,
}
Expand Down
2 changes: 1 addition & 1 deletion blockissuer/pow/pow.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

const (
// Hash defines the hash function that is used to compute the PoW digest.
Hash = crypto.BLAKE2b_256 //nolint:nosnakecase
Hash = crypto.BLAKE2b_256

// HashLength defines the length of the hash function in bytes.
HashLength = blake2b.Size256
Expand Down
2 changes: 1 addition & 1 deletion blockissuer/pow/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (w *Worker) Mine(ctx context.Context, data []byte, targetTrailingZeros int)
}()

workerWidth := math.MaxUint64 / uint64(w.numWorkers)
for i := 0; i < w.numWorkers; i++ {
for i := range w.numWorkers {
startNonce := uint64(i) * workerWidth
wg.Add(1)
go func() {
Expand Down
3 changes: 1 addition & 2 deletions builder/output_builder_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ type BlockIssuerTransition struct {

// AddKeys adds the keys of the BlockIssuerFeature.
func (trans *BlockIssuerTransition) AddKeys(keys ...iotago.BlockIssuerKey) *BlockIssuerTransition {
for _, key := range keys {
blockIssuerKey := key
for _, blockIssuerKey := range keys {
trans.feature.BlockIssuerKeys.Add(blockIssuerKey)
}

Expand Down
4 changes: 0 additions & 4 deletions builder/output_builder_anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ type AnchorStateTransition struct {
}

// StateTransition narrows the builder functions to the ones available for an anchor state transition.
//
//nolint:revive
func (builder *AnchorOutputBuilder) StateTransition() *AnchorStateTransition {
return &AnchorStateTransition{builder: builder}
}
Expand Down Expand Up @@ -177,8 +175,6 @@ type AnchorGovernanceTransition struct {
}

// GovernanceTransition narrows the builder functions to the ones available for an anchor governance transition.
//
//nolint:revive
func (builder *AnchorOutputBuilder) GovernanceTransition() *AnchorGovernanceTransition {
return &AnchorGovernanceTransition{builder: builder}
}
Expand Down
1 change: 0 additions & 1 deletion builder/output_builder_delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (builder *DelegationOutputBuilder) Address(addr iotago.Address) *Delegation

// Build builds the iotago.DelegationOutput.
func (builder *DelegationOutputBuilder) Build() (*iotago.DelegationOutput, error) {

builder.output.UnlockConditions.Sort()

return builder.output, nil
Expand Down
2 changes: 1 addition & 1 deletion builder/transaction_builder_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//nolint:scopelint,forcetypeassert
//nolint:forcetypeassert
package builder_test

import (
Expand Down
6 changes: 0 additions & 6 deletions commitment_roots.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,32 @@ func (r *Roots) ID() (id Identifier) {
// We can ignore the error because Identifier.Bytes() will never return an error
return Identifier(
lo.PanicOnErr(
//nolint:nosnakecase // false positive
merklehasher.NewHasher[Identifier](crypto.BLAKE2b_256).HashValues(r.values()),
),
)
}

func (r *Roots) AttestationsProof() *merklehasher.Proof[Identifier] {
// We can ignore the error because Identifier.Bytes() will never return an error
//nolint:nosnakecase // false positive
return lo.PanicOnErr(merklehasher.NewHasher[Identifier](crypto.BLAKE2b_256).ComputeProofForIndex(r.values(), 4))
}

func (r *Roots) TangleProof() *merklehasher.Proof[Identifier] {
// We can ignore the error because Identifier.Bytes() will never return an error
//nolint:nosnakecase // false positive
return lo.PanicOnErr(merklehasher.NewHasher[Identifier](crypto.BLAKE2b_256).ComputeProofForIndex(r.values(), 0))
}

func (r *Roots) MutationProof() *merklehasher.Proof[Identifier] {
// We can ignore the error because Identifier.Bytes() will never return an error
//nolint:nosnakecase // false positive
return lo.PanicOnErr(merklehasher.NewHasher[Identifier](crypto.BLAKE2b_256).ComputeProofForIndex(r.values(), 1))
}

func VerifyProof(proof *merklehasher.Proof[Identifier], proofedRoot Identifier, treeRoot Identifier) bool {
// We can ignore the error because Identifier.Bytes() will never return an error
//nolint:nosnakecase // false positive
if !lo.PanicOnErr(proof.ContainsValue(proofedRoot, merklehasher.NewHasher[Identifier](crypto.BLAKE2b_256))) {
return false
}

//nolint:nosnakecase // false positive
return treeRoot == Identifier(proof.Hash(merklehasher.NewHasher[Identifier](crypto.BLAKE2b_256)))
}

Expand Down
2 changes: 1 addition & 1 deletion feat.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func FeatureUnchanged(featType FeatureType, inFeatSet FeatureSet, outFeatSet Fea

// checkPrintableASCIIString returns an error if the given string contains non-printable ASCII characters (including space).
func checkPrintableASCIIString(s string) error {
for i := 0; i < len(s); i++ {
for i := range len(s) {
if s[i] < 33 || s[i] > 126 {
return ierrors.Errorf(
"string contains non-printable ASCII character %d at index %d (allowed range 33 <= character <= 126)", s[i], i,
Expand Down
2 changes: 1 addition & 1 deletion feat_native_token_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//nolint:dupl,scopelint
//nolint:dupl
package iotago_test

import (
Expand Down
1 change: 0 additions & 1 deletion feat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ func TestFeaturesMetadataLexicalOrdering(t *testing.T) {
}

for _, test := range tests {
// Required to avoid triggering the scopelint.
source := test.source
target := test.target
featType := test.source.Type()
Expand Down
1 change: 0 additions & 1 deletion input_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:scopelint
package iotago_test

import (
Expand Down
Loading

0 comments on commit 24bb64d

Please sign in to comment.