Skip to content

Commit

Permalink
Merge pull request #403 from iotaledger/chore/linter
Browse files Browse the repository at this point in the history
Expands GolangCI linters
  • Loading branch information
luca-moser authored Jul 26, 2022
2 parents 1bdaf80 + f52f333 commit 652becc
Show file tree
Hide file tree
Showing 64 changed files with 200 additions and 129 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: GolangCIlint

on:
pull_request:

jobs:
golangci-lint:
name: GolangCI-Lint
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
golangci_lint_flags: "--timeout=10m"
reporter: github-pr-check
filter_mode: nofilter
fail_on_error: true
20 changes: 0 additions & 20 deletions .github/workflows/reviewdog.yml

This file was deleted.

46 changes: 46 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
run:
tests: true
skip-dirs:
- bech32
- tpkg

linters-settings:
gofmt:
simplify: true
goimports:
local-prefixes: github.com/iotaledger
golint:
min-confidence: 0.9
gocyclo:
min-complexity: 15
govet:
check-shadowing: false
misspell:
locale: US
staticcheck:
checks: ["all"]
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"]

linters:
enable:
- durationcheck
- errcheck
- errname
- goconst
- godot
- gofmt
- goimports
- gosec
- govet
- ifshort
- importas
- misspell
- nilnil
- prealloc
- predeclared
- promlinter
- staticcheck
- unconvert
- unparam
# - gomnd
1 change: 1 addition & 0 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (addrType AddressType) String() string {
if int(addrType) >= len(addressNames) {
return fmt.Sprintf("unknown address type: %d", addrType)
}

return addressNames[addrType]
}

Expand Down
7 changes: 2 additions & 5 deletions address_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"encoding/json"
"fmt"

"github.com/iotaledger/hive.go/serializer/v2"
"golang.org/x/crypto/blake2b"

"github.com/iotaledger/hive.go/serializer/v2"
)

const (
Expand All @@ -15,10 +16,6 @@ const (
AliasAddressSerializedBytesSize = serializer.SmallTypeDenotationByteSize + AliasAddressBytesLength
)

var (
emptyAliasAddress = [AliasAddressBytesLength]byte{}
)

// ParseAliasAddressFromHexString parses the given hex string into an AliasAddress.
func ParseAliasAddressFromHexString(hexAddr string) (*AliasAddress, error) {
addrBytes, err := DecodeHex(hexAddr)
Expand Down
3 changes: 2 additions & 1 deletion address_ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"encoding/json"
"fmt"

"github.com/iotaledger/hive.go/serializer/v2"
"golang.org/x/crypto/blake2b"

"github.com/iotaledger/hive.go/serializer/v2"
)

const (
Expand Down
7 changes: 2 additions & 5 deletions address_nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"encoding/json"
"fmt"

"github.com/iotaledger/hive.go/serializer/v2"
"golang.org/x/crypto/blake2b"

"github.com/iotaledger/hive.go/serializer/v2"
)

const (
Expand All @@ -15,10 +16,6 @@ const (
NFTAddressSerializedBytesSize = serializer.SmallTypeDenotationByteSize + NFTAddressBytesLength
)

var (
emptyNFTAddress = [NFTAddressBytesLength]byte{}
)

// ParseNFTAddressFromHexString parses the given hex string into an NFTAddress.
func ParseNFTAddressFromHexString(hexAddr string) (*NFTAddress, error) {
addrBytes, err := DecodeHex(hexAddr)
Expand Down
5 changes: 3 additions & 2 deletions address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package iotago_test
import (
"testing"

"github.com/iotaledger/iota.go/v3"
"github.com/iotaledger/iota.go/v3/tpkg"
"github.com/stretchr/testify/assert"

iotago "github.com/iotaledger/iota.go/v3"
"github.com/iotaledger/iota.go/v3/tpkg"
)

func TestAddressDeSerialize(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions bech32/internal/base32/base32.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Package base32 implements the conversion for bytes (base256) to base32.
package base32

//lint:gomnd
import (
"errors"
"fmt"
Expand Down
12 changes: 6 additions & 6 deletions benches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/iotaledger/hive.go/serializer/v2"
"github.com/iotaledger/iota.go/v3"
iotago "github.com/iotaledger/iota.go/v3"
iotagoEd25519 "github.com/iotaledger/iota.go/v3/ed25519"
"github.com/iotaledger/iota.go/v3/tpkg"
)
Expand All @@ -24,7 +24,7 @@ func BenchmarkDeserializeWithValidationOneIOTxPayload(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
target.Deserialize(data, serializer.DeSeriModePerformValidation, tpkg.TestProtoParas)
_, _ = target.Deserialize(data, serializer.DeSeriModePerformValidation, tpkg.TestProtoParas)
}
}

Expand Down Expand Up @@ -80,7 +80,7 @@ func BenchmarkDeserializeWithValidationLargeTxPayload(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
target.Deserialize(data, serializer.DeSeriModePerformValidation, tpkg.TestProtoParas)
_, _ = target.Deserialize(data, serializer.DeSeriModePerformValidation, tpkg.TestProtoParas)
}
}

Expand All @@ -98,23 +98,23 @@ func BenchmarkDeserializeWithoutValidationOneIOTxPayload(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
target.Deserialize(data, serializer.DeSeriModeNoValidation, tpkg.TestProtoParas)
_, _ = target.Deserialize(data, serializer.DeSeriModeNoValidation, tpkg.TestProtoParas)
}
}

func BenchmarkSerializeWithValidationOneIOTxPayload(b *testing.B) {
txPayload := tpkg.OneInputOutputTransaction()
b.ResetTimer()
for i := 0; i < b.N; i++ {
txPayload.Serialize(serializer.DeSeriModePerformValidation, tpkg.TestProtoParas)
_, _ = txPayload.Serialize(serializer.DeSeriModePerformValidation, tpkg.TestProtoParas)
}
}

func BenchmarkSerializeWithoutValidationOneIOTxPayload(b *testing.B) {
sigTxPayload := tpkg.OneInputOutputTransaction()
b.ResetTimer()
for i := 0; i < b.N; i++ {
sigTxPayload.Serialize(serializer.DeSeriModeNoValidation, tpkg.TestProtoParas)
_, _ = sigTxPayload.Serialize(serializer.DeSeriModeNoValidation, tpkg.TestProtoParas)
}
}

Expand Down
2 changes: 1 addition & 1 deletion block.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
// ErrBlockExceedsMaxSize gets returned when a serialized block exceeds BlockBinSerializedMaxSize.
ErrBlockExceedsMaxSize = errors.New("block exceeds max size")

// is an empty block ID
// is an empty block ID.
emptyBlockID = BlockID{}

blockPayloadGuard = serializer.SerializableGuard{
Expand Down
5 changes: 3 additions & 2 deletions builder/block_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package builder
import (
"context"
"fmt"

"github.com/iotaledger/hive.go/serializer/v2"
"github.com/iotaledger/iota.go/v3"
iotago "github.com/iotaledger/iota.go/v3"
"github.com/iotaledger/iota.go/v3/nodeclient"
"github.com/iotaledger/iota.go/v3/pow"
)
Expand Down Expand Up @@ -84,7 +85,7 @@ func (mb *BlockBuilder) Parents(parents iotago.BlockIDs) *BlockBuilder {
}

// ProofOfWork does the proof-of-work needed in order to satisfy the given target score.
// It can be cancelled by cancelling the given context.
// It can be canceled by canceling the given context.
// This function should normally appear as the last step before Build.
func (mb *BlockBuilder) ProofOfWork(ctx context.Context, protoParas *iotago.ProtocolParameters, targetScore float64, numWorkers ...int) *BlockBuilder {
if mb.err != nil {
Expand Down
4 changes: 3 additions & 1 deletion builder/block_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package builder_test

import (
"context"
"github.com/stretchr/testify/require"
"math/rand"

"os"
"testing"
"time"

"github.com/stretchr/testify/require"

iotago "github.com/iotaledger/iota.go/v3"
"github.com/iotaledger/iota.go/v3/builder"
"github.com/iotaledger/iota.go/v3/tpkg"
Expand Down
2 changes: 1 addition & 1 deletion chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type StateTransitionValidationFunc func(current ChainConstrainedOutput, next Cha
// This function is a no-op if the chain output does not contain an IssuerFeature.
func IsIssuerOnOutputUnlocked(output ChainConstrainedOutput, unlockedIdents UnlockedIdentities) error {
immFeats := output.ImmutableFeatureSet()
if immFeats == nil || len(immFeats) == 0 {
if len(immFeats) == 0 {
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions ed25519/ed25519_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//#nosec G404

package ed25519_test

import (
Expand Down
3 changes: 2 additions & 1 deletion ed25519/zip215_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"encoding/hex"
"testing"

iotagoEd25519 "github.com/iotaledger/iota.go/v3/ed25519"
"github.com/stretchr/testify/assert"

iotagoEd25519 "github.com/iotaledger/iota.go/v3/ed25519"
)

var message = []byte("Zcash")
Expand Down
3 changes: 2 additions & 1 deletion input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package iotago_test
import (
"testing"

"github.com/iotaledger/iota.go/v3"
"github.com/stretchr/testify/require"

iotago "github.com/iotaledger/iota.go/v3"
)

func TestInputsSyntacticalUnique(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion input_treasury_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/iotaledger/iota.go/v3/tpkg"

"github.com/iotaledger/iota.go/v3"
iotago "github.com/iotaledger/iota.go/v3"
)

func TestTreasuryInput_Deserialize(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion input_utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
// RefUTXOIndexMax is the maximum index of a referenced UTXO.
RefUTXOIndexMax = MaxOutputsCount - 1

// UTXOInputSize is the size of a UTXO input: input type + tx id + index
// UTXOInputSize is the size of a UTXO input: input type + tx id + index.
UTXOInputSize = serializer.SmallTypeDenotationByteSize + TransactionIDLength + serializer.UInt16ByteSize
)

Expand Down
3 changes: 2 additions & 1 deletion input_utxo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (

"github.com/iotaledger/iota.go/v3/tpkg"

"github.com/iotaledger/iota.go/v3"
"github.com/stretchr/testify/require"

iotago "github.com/iotaledger/iota.go/v3"
)

func TestUTXOInput_DeSerialize(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions merklehasher/merkle_hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"crypto"
"math/bits"

"github.com/iotaledger/iota.go/v3"
iotago "github.com/iotaledger/iota.go/v3"
)

// Domain separation prefixes
// Domain separation prefixes.
const (
LeafHashPrefix = 0
NodeHashPrefix = 1
Expand Down
4 changes: 2 additions & 2 deletions merklehasher/merkle_hasher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

"github.com/stretchr/testify/require"

"github.com/iotaledger/iota.go/v3"
iotago "github.com/iotaledger/iota.go/v3"
"github.com/iotaledger/iota.go/v3/merklehasher"

// import implementation
// import implementation.
_ "golang.org/x/crypto/blake2b"
)

Expand Down
Loading

0 comments on commit 652becc

Please sign in to comment.