From e57695e2500762d0e3d78548825bbf30cd0c095e Mon Sep 17 00:00:00 2001 From: muXxer Date: Wed, 20 Mar 2024 18:17:00 +0100 Subject: [PATCH] Adapt .golangci.yml to latest version and fix linter issues --- .golangci.yml | 72 ++++++++++++++++++-------- address_capabilities_bitmask.go | 1 + address_signer.go | 2 +- address_test.go | 2 +- api/endpoints.go | 4 +- api_protocol_parameters.go | 2 +- api_provider.go | 8 +-- api_test.go | 1 - api_v3.go | 1 - bech32/bech32_test.go | 1 - bech32/chars.go | 4 +- block_issuer_key_ed25519_pubkeyhash.go | 2 + blockissuer/pow/pow.go | 2 +- blockissuer/pow/worker.go | 2 +- builder/output_builder_account.go | 3 +- builder/output_builder_anchor.go | 4 -- builder/output_builder_delegation.go | 1 - builder/transaction_builder_test.go | 2 +- commitment_roots.go | 6 --- feat.go | 2 +- feat_native_token_test.go | 2 +- feat_test.go | 1 - input_test.go | 1 - mana_decay_provider_test.go | 2 +- merklehasher/merkle_hasher.go | 1 - merklehasher/merkle_hasher_test.go | 2 - merklehasher/merkle_proof.go | 4 +- nodeclient/http.go | 1 - nodeclient/http_api_client.go | 2 - output.go | 2 +- output_id.go | 1 + output_id_proof.go | 2 - output_test.go | 1 - signature.go | 2 +- signature_test.go | 1 - tpkg/frameworks/deserialize.go | 2 +- tpkg/rand.go | 16 +++--- tpkg/rand_address.go | 2 +- tpkg/rand_ed25519.go | 4 +- tpkg/rand_output.go | 9 +--- tpkg/rand_unlock.go | 2 +- tpkg/util.go | 1 - transaction.go | 1 - transaction_capabilities_bitmask.go | 1 + transaction_test.go | 1 - unlock_test.go | 1 - vm/nova/stvf_test.go | 2 +- vm/nova/vm.go | 1 - vm/nova/vm_test.go | 2 +- vm/vm.go | 3 -- 50 files changed, 95 insertions(+), 100 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ed9ef595d..845c3d868 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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: @@ -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 @@ -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 diff --git a/address_capabilities_bitmask.go b/address_capabilities_bitmask.go index a247c514f..2cdd24420 100644 --- a/address_capabilities_bitmask.go +++ b/address_capabilities_bitmask.go @@ -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 } diff --git a/address_signer.go b/address_signer.go index 46a493898..6dbcb7e19 100644 --- a/address_signer.go +++ b/address_signer.go @@ -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: diff --git a/address_test.go b/address_test.go index 1509fdcf6..89db898fa 100644 --- a/address_test.go +++ b/address_test.go @@ -1,4 +1,4 @@ -//nolint:scopelint,dupl,revive +//nolint:dupl,revive package iotago_test import ( diff --git a/api/endpoints.go b/api/endpoints.go index 2ca2a6e3d..f8dd46765 100644 --- a/api/endpoints.go +++ b/api/endpoints.go @@ -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. @@ -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. diff --git a/api_protocol_parameters.go b/api_protocol_parameters.go index d5206b9a3..fb44f98ff 100644 --- a/api_protocol_parameters.go +++ b/api_protocol_parameters.go @@ -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:""` diff --git a/api_provider.go b/api_provider.go index 6e8c01fef..a2a0266d2 100644 --- a/api_provider.go +++ b/api_provider.go @@ -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 diff --git a/api_test.go b/api_test.go index dac048d46..26e517f73 100644 --- a/api_test.go +++ b/api_test.go @@ -1,4 +1,3 @@ -//nolint:scopelint package iotago_test import ( diff --git a/api_v3.go b/api_v3.go index b7d780bc5..0393caed0 100644 --- a/api_v3.go +++ b/api_v3.go @@ -1,4 +1,3 @@ -//nolint:dupl package iotago import ( diff --git a/bech32/bech32_test.go b/bech32/bech32_test.go index a085049f5..a1e38b93a 100644 --- a/bech32/bech32_test.go +++ b/bech32/bech32_test.go @@ -1,4 +1,3 @@ -//nolint:scopelint package bech32_test import ( diff --git a/bech32/chars.go b/bech32/chars.go index 35c66d4ec..533d9d351 100644 --- a/bech32/chars.go +++ b/bech32/chars.go @@ -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) } diff --git a/block_issuer_key_ed25519_pubkeyhash.go b/block_issuer_key_ed25519_pubkeyhash.go index 2559e1e58..764697880 100644 --- a/block_issuer_key_ed25519_pubkeyhash.go +++ b/block_issuer_key_ed25519_pubkeyhash.go @@ -27,6 +27,7 @@ type Ed25519PublicKeyHashBlockIssuerKey struct { func Ed25519PublicKeyHashBlockIssuerKeyFromImplicitAccountCreationAddress(address *ImplicitAccountCreationAddress) *Ed25519PublicKeyHashBlockIssuerKey { cpy := [Ed25519PublicKeyHashBytesLength]byte{} copy(cpy[:], address[:]) + return &Ed25519PublicKeyHashBlockIssuerKey{PublicKeyHash: cpy} } @@ -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, } diff --git a/blockissuer/pow/pow.go b/blockissuer/pow/pow.go index 1812fb939..ec147136e 100644 --- a/blockissuer/pow/pow.go +++ b/blockissuer/pow/pow.go @@ -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 diff --git a/blockissuer/pow/worker.go b/blockissuer/pow/worker.go index 6bd5fb44c..a2af40a6e 100644 --- a/blockissuer/pow/worker.go +++ b/blockissuer/pow/worker.go @@ -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() { diff --git a/builder/output_builder_account.go b/builder/output_builder_account.go index 11d956f1e..37a659e58 100644 --- a/builder/output_builder_account.go +++ b/builder/output_builder_account.go @@ -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) } diff --git a/builder/output_builder_anchor.go b/builder/output_builder_anchor.go index 38edb1acf..d875d2485 100644 --- a/builder/output_builder_anchor.go +++ b/builder/output_builder_anchor.go @@ -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} } @@ -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} } diff --git a/builder/output_builder_delegation.go b/builder/output_builder_delegation.go index 489d8d14d..d1d156251 100644 --- a/builder/output_builder_delegation.go +++ b/builder/output_builder_delegation.go @@ -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 diff --git a/builder/transaction_builder_test.go b/builder/transaction_builder_test.go index bd9c94243..b00f41d51 100644 --- a/builder/transaction_builder_test.go +++ b/builder/transaction_builder_test.go @@ -1,4 +1,4 @@ -//nolint:scopelint,forcetypeassert +//nolint:forcetypeassert package builder_test import ( diff --git a/commitment_roots.go b/commitment_roots.go index 65a502022..e981d164e 100644 --- a/commitment_roots.go +++ b/commitment_roots.go @@ -49,7 +49,6 @@ 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()), ), ) @@ -57,30 +56,25 @@ func (r *Roots) ID() (id Identifier) { 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))) } diff --git a/feat.go b/feat.go index d62e4012a..0cc573e5d 100644 --- a/feat.go +++ b/feat.go @@ -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, diff --git a/feat_native_token_test.go b/feat_native_token_test.go index 02fa292ee..cc691506a 100644 --- a/feat_native_token_test.go +++ b/feat_native_token_test.go @@ -1,4 +1,4 @@ -//nolint:dupl,scopelint +//nolint:dupl package iotago_test import ( diff --git a/feat_test.go b/feat_test.go index 4a192c30e..32fa2e40e 100644 --- a/feat_test.go +++ b/feat_test.go @@ -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() diff --git a/input_test.go b/input_test.go index c9548ad1d..ef0be35aa 100644 --- a/input_test.go +++ b/input_test.go @@ -1,4 +1,3 @@ -//nolint:scopelint package iotago_test import ( diff --git a/mana_decay_provider_test.go b/mana_decay_provider_test.go index 6f3cc2c8d..91df127c0 100644 --- a/mana_decay_provider_test.go +++ b/mana_decay_provider_test.go @@ -1,4 +1,4 @@ -//nolint:scopelint,golint,revive,nosnakecase,stylecheck +//nolint:golint,revive,stylecheck package iotago_test import ( diff --git a/merklehasher/merkle_hasher.go b/merklehasher/merkle_hasher.go index 22dbad91c..8347d94d6 100644 --- a/merklehasher/merkle_hasher.go +++ b/merklehasher/merkle_hasher.go @@ -19,7 +19,6 @@ type Value interface { // Hasher implements the hashing algorithm described in the IOTA protocol RFC-12. type Hasher[V Value] struct { - //nolint:structcheck // false positive hash crypto.Hash } diff --git a/merklehasher/merkle_hasher_test.go b/merklehasher/merkle_hasher_test.go index fceb9f9df..f07ccaa6e 100644 --- a/merklehasher/merkle_hasher_test.go +++ b/merklehasher/merkle_hasher_test.go @@ -1,4 +1,3 @@ -//nolint:nosnakecase package merklehasher_test import ( @@ -29,7 +28,6 @@ func TestMerkleHasher(t *testing.T) { includedBlocks = append(includedBlocks, iotago.MustBlockIDFromHexString("0x0bf5059875921e668a5bdf2c7fc4844592d2572bcd0668d2d6c52f5054e2d08300000000")) includedBlocks = append(includedBlocks, iotago.MustBlockIDFromHexString("0x6bf84c7174cb7476364cc3dbd968b0f7172ed85794bb358b0c3b525da1786f9f00000000")) - //nolint:nosnakecase // false positive hasher := merklehasher.NewHasher[iotago.BlockID](crypto.BLAKE2b_256) hash, err := hasher.HashValues(includedBlocks) require.NoError(t, err) diff --git a/merklehasher/merkle_proof.go b/merklehasher/merkle_proof.go index f082de5f7..07019c933 100644 --- a/merklehasher/merkle_proof.go +++ b/merklehasher/merkle_proof.go @@ -43,7 +43,7 @@ type Node[V Value] struct { Right MerkleHashable[V] `serix:"r"` } -// nolint: tagliatelle // Does not understand generics +//nolint:tagliatelle // Does not understand generics type Proof[V Value] struct { MerkleHashable[V] `serix:",inlined"` } @@ -123,7 +123,6 @@ func (t *Hasher[V]) computeProof(data [][]byte, index int) (MerkleHashable[V], e Left: &LeafHash[V]{t.hashLeaf(left)}, Right: &ValueHash[V]{t.hashLeaf(right)}, }, nil - } k := largestPowerOfTwo(len(data)) @@ -222,6 +221,7 @@ func RegisterSerixRules[V Value](api *serix.API) { func serixAPI[V Value]() *serix.API { api := serix.NewAPI() RegisterSerixRules[V](api) + return api } diff --git a/nodeclient/http.go b/nodeclient/http.go index c14a880c2..c1d5ea87c 100644 --- a/nodeclient/http.go +++ b/nodeclient/http.go @@ -108,7 +108,6 @@ func do( requestHeaderHook RequestHeaderHook, reqObj interface{}, resObj interface{}) (*http.Response, error) { - // marshal request object var data []byte var raw bool diff --git a/nodeclient/http_api_client.go b/nodeclient/http_api_client.go index 09fad318f..7635e0f8e 100644 --- a/nodeclient/http_api_client.go +++ b/nodeclient/http_api_client.go @@ -93,7 +93,6 @@ const initInfoEndpointCallTimeout = 5 * time.Second // This constructor will automatically call Client.Info() in order to initialize the Client // with the appropriate protocol parameters and latest iotago.API version (use WithIOTAGoAPI() to override this behavior). func New(baseURL string, opts ...ClientOption) (*Client, error) { - options := &ClientOptions{} options.apply(defaultNodeAPIOptions...) options.apply(opts...) @@ -231,7 +230,6 @@ func (client *Client) Health(ctx context.Context) (bool, error) { // Routes gets the routes the node supports. func (client *Client) Routes(ctx context.Context) (*api.RoutesResponse, error) { - //nolint:bodyclose res := new(api.RoutesResponse) //nolint:bodyclose if _, err := client.DoWithRequestHeaderHook(ctx, http.MethodGet, api.RouteRoutes, RequestHeaderHookAcceptJSON, nil, res); err != nil { diff --git a/output.go b/output.go index a276e5f8c..3da15436e 100644 --- a/output.go +++ b/output.go @@ -287,7 +287,7 @@ func PotentialMana(manaDecayProvider *ManaDecayProvider, storageScoreStructure * excessBaseTokens, err := safemath.SafeSub(output.BaseTokenAmount(), minDeposit) if err != nil { - // nolint:nilerr // An underflow means no potential mana is generated and hence no error is returned. + //nolint:nilerr // An underflow means no potential mana is generated and hence no error is returned. return 0, nil } diff --git a/output_id.go b/output_id.go index 11c42b5e9..2677f9d0a 100644 --- a/output_id.go +++ b/output_id.go @@ -10,6 +10,7 @@ import ( func EmptyOutputIDWithCreationSlot(slot SlotIndex) OutputID { var outputID OutputID binary.LittleEndian.PutUint32(outputID[IdentifierLength:OutputIDLength], uint32(slot)) + return outputID } diff --git a/output_id_proof.go b/output_id_proof.go index a917035dc..afb90c1ea 100644 --- a/output_id_proof.go +++ b/output_id_proof.go @@ -35,7 +35,6 @@ func NewOutputIDProof(api API, txCommitment Identifier, txCreationSlot SlotIndex return nil, ierrors.Errorf("index %d out of bounds for outputs slice of len %d", outputIndex, len(outputs)) } - //nolint:nosnakecase // false positive outputHasher := merklehasher.NewHasher[*APIByter[TxEssenceOutput]](crypto.BLAKE2b_256) wrappedOutputs := lo.Map(outputs, APIByterFactory[TxEssenceOutput](api)) @@ -75,7 +74,6 @@ func (p *OutputIDProof) OutputID(output Output) (OutputID, error) { panic("API on OutputIDProof not set") } - //nolint:nosnakecase // false positive outputHasher := merklehasher.NewHasher[*APIByter[TxEssenceOutput]](crypto.BLAKE2b_256) contains, err := p.OutputCommitmentProof.ContainsValue(APIByterFactory[TxEssenceOutput](p.API)(output), outputHasher) diff --git a/output_test.go b/output_test.go index d81842800..8eb98375c 100644 --- a/output_test.go +++ b/output_test.go @@ -1,4 +1,3 @@ -//nolint:scopelint package iotago_test import ( diff --git a/signature.go b/signature.go index 202f151cf..a21b70ad8 100644 --- a/signature.go +++ b/signature.go @@ -16,7 +16,7 @@ type Signature interface { constraints.Cloneable[Signature] // MatchesAddress returns true if the Signature matches the given Address. - MatchesAddress(Address) bool + MatchesAddress(addr Address) bool // SignerUID returns the unique identifier of the signature's signer. // This can be used to identify the uniqueness of the signer in the unlocks (e.g. unique public key). diff --git a/signature_test.go b/signature_test.go index b0821b5dc..ec83ee86e 100644 --- a/signature_test.go +++ b/signature_test.go @@ -1,4 +1,3 @@ -//nolint:scopelint package iotago_test import ( diff --git a/tpkg/frameworks/deserialize.go b/tpkg/frameworks/deserialize.go index 23a43e2cb..2998f3032 100644 --- a/tpkg/frameworks/deserialize.go +++ b/tpkg/frameworks/deserialize.go @@ -34,7 +34,7 @@ func (test *DeSerializeTest) assertBinaryEncodeDecode(t *testing.T) { } if src, ok := test.Source.(iotago.Sizer); ok { - require.Equal(t, src.Size(), len(serixData), "binary encoding") + require.Len(t, serixData, src.Size(), "binary encoding") } serixTarget := reflect.New(reflect.TypeOf(test.Target).Elem()).Interface() diff --git a/tpkg/rand.go b/tpkg/rand.go index 838675604..f2bbbac1f 100644 --- a/tpkg/rand.go +++ b/tpkg/rand.go @@ -24,8 +24,8 @@ func RandByte() byte { // RandBytes returns length amount random bytes. func RandBytes(length int) []byte { - var b []byte - for i := 0; i < length; i++ { + b := make([]byte, 0, length) + for range length { b = append(b, RandByte()) } @@ -33,8 +33,8 @@ func RandBytes(length int) []byte { } func RandString(length int) string { - var b []byte - for i := 0; i < length; i++ { + b := make([]byte, 0, length) + for range length { // Generate random printable ASCII values between 32 and 126 (inclusive) b = append(b, byte(RandInt(95)+32)) // 95 printable ASCII characters (126 - 32 + 1) } @@ -189,7 +189,7 @@ func Rand64ByteArray() [64]byte { // SortedRand32ByteArray returns a count length slice of sorted 32 byte arrays. func SortedRand32ByteArray(count int) [][32]byte { hashes := make(serializer.LexicalOrdered32ByteArrays, count) - for i := 0; i < count; i++ { + for i := range count { hashes[i] = Rand32ByteArray() } sort.Sort(hashes) @@ -200,7 +200,7 @@ func SortedRand32ByteArray(count int) [][32]byte { // SortedRand36ByteArray returns a count length slice of sorted 36 byte arrays. func SortedRand36ByteArray(count int) [][36]byte { hashes := make(serializer.LexicalOrdered36ByteArrays, count) - for i := 0; i < count; i++ { + for i := range count { hashes[i] = Rand36ByteArray() } sort.Sort(hashes) @@ -211,7 +211,7 @@ func SortedRand36ByteArray(count int) [][36]byte { // SortedRand40ByteArray returns a count length slice of sorted 32 byte arrays. func SortedRand40ByteArray(count int) [][40]byte { hashes := make(serializer.LexicalOrdered40ByteArrays, count) - for i := 0; i < count; i++ { + for i := range count { hashes[i] = Rand40ByteArray() } sort.Sort(hashes) @@ -306,7 +306,7 @@ func RandAllotment() *iotago.Allotment { // RandSortAllotment returns count sorted Allotments. func RandSortAllotment(count int) iotago.Allotments { var allotments iotago.Allotments - for i := 0; i < count; i++ { + for range count { allotments = append(allotments, RandAllotment()) } allotments.Sort() diff --git a/tpkg/rand_address.go b/tpkg/rand_address.go index 40874600f..5bfe7cf12 100644 --- a/tpkg/rand_address.go +++ b/tpkg/rand_address.go @@ -59,7 +59,7 @@ func RandMultiAddress() *iotago.MultiAddress { cumulativeWeight := 0 addresses := make([]*iotago.AddressWithWeight, 0, addrCnt) - for i := 0; i < addrCnt; i++ { + for range addrCnt { weight := RandInt(8) + 1 cumulativeWeight += weight addresses = append(addresses, &iotago.AddressWithWeight{ diff --git a/tpkg/rand_ed25519.go b/tpkg/rand_ed25519.go index fa3b833a8..e7d00ed91 100644 --- a/tpkg/rand_ed25519.go +++ b/tpkg/rand_ed25519.go @@ -62,7 +62,7 @@ func RandEd25519Identity() (ed25519.PrivateKey, *iotago.Ed25519Address, iotago.A func RandEd25519IdentitiesSortedByAddress(count int) ([]iotago.Address, []iotago.AddressKeys) { addresses := make([]iotago.Address, count) addressKeys := make([]iotago.AddressKeys, count) - for i := 0; i < count; i++ { + for i := range count { _, addresses[i], addressKeys[i] = RandEd25519Identity() } @@ -102,7 +102,7 @@ func RandBlockIssuerKeys(count ...int) iotago.BlockIssuerKeys { } blockIssuerKeys := iotago.NewBlockIssuerKeys() - for i := 0; i < length; i++ { + for range length { blockIssuerKeys.Add(RandBlockIssuerKey()) } blockIssuerKeys.Sort() diff --git a/tpkg/rand_output.go b/tpkg/rand_output.go index 2019389b8..9704e9a3e 100644 --- a/tpkg/rand_output.go +++ b/tpkg/rand_output.go @@ -31,7 +31,7 @@ func RandOutputID(index ...uint16) iotago.OutputID { func RandOutputIDsWithCreationSlot(slot iotago.SlotIndex, count uint16) iotago.OutputIDs { outputIDs := make(iotago.OutputIDs, int(count)) - for i := 0; i < int(count); i++ { + for i := range int(count) { outputIDs[i] = RandOutputIDWithCreationSlot(slot, count) } @@ -40,7 +40,7 @@ func RandOutputIDsWithCreationSlot(slot iotago.SlotIndex, count uint16) iotago.O func RandOutputIDs(count uint16) iotago.OutputIDs { outputIDs := make(iotago.OutputIDs, int(count)) - for i := 0; i < int(count); i++ { + for i := range count { outputIDs[i] = RandOutputID(count) } @@ -102,7 +102,6 @@ func RandOutputOnAddressWithAmount(outputType iotago.OutputType, address iotago. switch outputType { case iotago.OutputBasic: - //nolint:forcetypeassert // we already checked the type iotaOutput = &iotago.BasicOutput{ Amount: amount, UnlockConditions: iotago.BasicOutputUnlockConditions{ @@ -114,7 +113,6 @@ func RandOutputOnAddressWithAmount(outputType iotago.OutputType, address iotago. } case iotago.OutputAccount: - //nolint:forcetypeassert // we already checked the type iotaOutput = &iotago.AccountOutput{ Amount: amount, AccountID: RandAccountID(), @@ -128,7 +126,6 @@ func RandOutputOnAddressWithAmount(outputType iotago.OutputType, address iotago. } case iotago.OutputAnchor: - //nolint:forcetypeassert // we already checked the type iotaOutput = &iotago.AnchorOutput{ Amount: amount, AnchorID: RandAnchorID(), @@ -169,7 +166,6 @@ func RandOutputOnAddressWithAmount(outputType iotago.OutputType, address iotago. } case iotago.OutputNFT: - //nolint:forcetypeassert // we already checked the type iotaOutput = &iotago.NFTOutput{ Amount: amount, NFTID: RandNFTID(), @@ -183,7 +179,6 @@ func RandOutputOnAddressWithAmount(outputType iotago.OutputType, address iotago. } case iotago.OutputDelegation: - //nolint:forcetypeassert // we already checked the type iotaOutput = &iotago.DelegationOutput{ Amount: amount, DelegatedAmount: amount, diff --git a/tpkg/rand_unlock.go b/tpkg/rand_unlock.go index 8e5100662..41467f223 100644 --- a/tpkg/rand_unlock.go +++ b/tpkg/rand_unlock.go @@ -64,7 +64,7 @@ func RandMultiUnlock() *iotago.MultiUnlock { unlockCnt := RandInt(9) + 2 unlocks := make([]iotago.Unlock, 0, unlockCnt) - for i := 0; i < unlockCnt; i++ { + for range unlockCnt { unlocks = append(unlocks, RandUnlock(true)) } diff --git a/tpkg/util.go b/tpkg/util.go index de8ee622a..170fc8f8a 100644 --- a/tpkg/util.go +++ b/tpkg/util.go @@ -1,4 +1,3 @@ -//nolint:gosec package tpkg import ( diff --git a/transaction.go b/transaction.go index 544f55f0a..70d69939a 100644 --- a/transaction.go +++ b/transaction.go @@ -109,7 +109,6 @@ func (t *Transaction) TransactionCommitment() (Identifier, error) { // OutputCommitment returns the output commitment which is the root of the merkle tree of the outputs. func (t *Transaction) OutputCommitment() (Identifier, error) { - //nolint:nosnakecase // false positive outputHasher := merklehasher.NewHasher[*APIByter[TxEssenceOutput]](crypto.BLAKE2b_256) wrappedOutputs := lo.Map(t.Outputs, APIByterFactory[TxEssenceOutput](t.API)) diff --git a/transaction_capabilities_bitmask.go b/transaction_capabilities_bitmask.go index 7aa2b3bba..d96360930 100644 --- a/transaction_capabilities_bitmask.go +++ b/transaction_capabilities_bitmask.go @@ -95,6 +95,7 @@ type TransactionCapabilitiesBitMask []byte func TransactionCapabilitiesBitMaskFromBytes(bytes []byte) (TransactionCapabilitiesBitMask, int, error) { var result TransactionCapabilitiesBitMask consumed, err := CommonSerixAPI().Decode(context.TODO(), bytes, &result) + return result, consumed, err } diff --git a/transaction_test.go b/transaction_test.go index 020500803..280b89afe 100644 --- a/transaction_test.go +++ b/transaction_test.go @@ -1,4 +1,3 @@ -//nolint:scopelint package iotago_test import ( diff --git a/unlock_test.go b/unlock_test.go index fa789659b..712b7406b 100644 --- a/unlock_test.go +++ b/unlock_test.go @@ -1,4 +1,3 @@ -//nolint:scopelint package iotago_test import ( diff --git a/vm/nova/stvf_test.go b/vm/nova/stvf_test.go index 3ea647230..4070c1bc6 100644 --- a/vm/nova/stvf_test.go +++ b/vm/nova/stvf_test.go @@ -1,4 +1,4 @@ -//nolint:forcetypeassert,dupl,nlreturn,scopelint +//nolint:forcetypeassert,dupl,nlreturn package nova_test import ( diff --git a/vm/nova/vm.go b/vm/nova/vm.go index 5c05aec72..9f41510a2 100644 --- a/vm/nova/vm.go +++ b/vm/nova/vm.go @@ -435,7 +435,6 @@ func accountStakingSTVF(vmParams *vm.Params, current *iotago.AccountOutput, next nextStakingFeat := next.FeatureSet().Staking() if currentStakingFeat != nil { - commitment := vmParams.WorkingSet.Commitment if commitment == nil { return iotago.ErrStakingCommitmentInputMissing diff --git a/vm/nova/vm_test.go b/vm/nova/vm_test.go index bde570aeb..40df42be4 100644 --- a/vm/nova/vm_test.go +++ b/vm/nova/vm_test.go @@ -1,4 +1,4 @@ -//nolint:forcetypeassert,dupl,nlreturn,scopelint,revive +//nolint:forcetypeassert,dupl,nlreturn,revive package nova_test import ( diff --git a/vm/vm.go b/vm/vm.go index 28631bc05..47fa9acd5 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -417,8 +417,6 @@ func IsIssuerOnOutputUnlocked(output iotago.ChainOutputImmutable, unlockedAddrs // ExecFunc is a function which given the context, input, outputs and // unlocks runs a specific execution/validation. The function might also modify the Params // in order to supply information to subsequent ExecFunc(s). -// -//nolint:revive type ExecFunc func(vm VirtualMachine, svCtx *Params) error // ValidateUnlocks produces the UnlockedAddresses which will be set into the given Params and verifies that inputs are @@ -484,7 +482,6 @@ func ValidateUnlocks(signedTransaction *iotago.SignedTransaction, resolvedInputs func addressToUnlock(transaction *iotago.Transaction, input iotago.Output, inputIndex uint16, outChains iotago.ChainOutputSet) (iotago.Address, error) { switch in := input.(type) { - case iotago.OwnerTransitionIndependentOutput: return in.Owner(), nil