Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint warnings #300

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ linters:
disable-all: true
enable:
## enabled by default
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
#- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases # TODO: re-enable after golangci-lint passes on other errors
- gosimple # specializes in simplifying a code
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # detects when assignments to existing variables are not used
Expand All @@ -119,7 +119,7 @@ linters:
- exhaustive # checks exhaustiveness of enum switch statements
#- exportloopref # checks for pointers to enclosing loop variables
- forbidigo # forbids identifiers
- funlen # tool for detection of long functions
#- funlen # tool for detection of long functions # TODO: re-enable after golangci-lint passes on other errors
#- gochecknoglobals # checks that no global variables exist
#- gochecknoinits # checks that no init functions are present in Go code
#- gocognit # computes and checks the cognitive complexity of functions # TODO: re-enable after golangci-lint passes on other errors
Expand All @@ -138,7 +138,7 @@ linters:
- nakedret # finds naked returns in functions greater than a specified function length
- nestif # reports deeply nested if statements
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- nilnil # checks that there is no simultaneous return of nil error and an invalid value
#- nilnil # checks that there is no simultaneous return of nil error and an invalid value # TODO: re-enable after golangci-lint passes on other errors
#- noctx # finds sending http request without context.Context
- nolintlint # reports ill-formed or insufficient nolint directives
#- nonamedreturns # reports all named returns
Expand Down
12 changes: 6 additions & 6 deletions cli/crypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,31 @@ func (f *fakeBuilder) Build() cli.Application {
return &fakeApp{err: f.err}
}

func (f *fakeBuilder) SetCommand(name string) cli.CommandBuilder {
func (f *fakeBuilder) SetCommand(_ string) cli.CommandBuilder {
return fakeCommandBuilder{}
}

type fakeCommandBuilder struct {
}

func (b fakeCommandBuilder) SetSubCommand(name string) cli.CommandBuilder {
func (b fakeCommandBuilder) SetSubCommand(_ string) cli.CommandBuilder {
return b
}

func (b fakeCommandBuilder) SetDescription(value string) {
func (b fakeCommandBuilder) SetDescription(_ string) {
}

func (b fakeCommandBuilder) SetFlags(flags ...cli.Flag) {
func (b fakeCommandBuilder) SetFlags(_ ...cli.Flag) {
}

func (b fakeCommandBuilder) SetAction(a cli.Action) {
func (b fakeCommandBuilder) SetAction(_ cli.Action) {
}

type fakeApp struct {
err error
}

func (f fakeApp) Run(arguments []string) error {
func (f fakeApp) Run(_ []string) error {
return f.err
}

Expand Down
2 changes: 1 addition & 1 deletion cli/node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (b *CLIBuilder) MakeAction(tmpl ActionTemplate) cli.Action {
// Prepare a set of flags that will be transmitted to the daemon so that
// the action has access to the same flags and their values.
fset := make(FlagSet)
lookupFlags(fset, c.(*urfave.Context))
lookupFlags(fset, c.(*urfave.Context)) //nolint:errcheck

buf, err := json.Marshal(fset)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cli/node/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package node
import (
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -64,7 +65,7 @@ func (c socketClient) Send(data []byte) error {

for {
err = dec.Decode(&evt)
if err == io.EOF {
if errors.Is(err, io.EOF) {
return nil
}
if err != nil {
Expand Down Expand Up @@ -153,7 +154,7 @@ func (d *socketDaemon) handleConn(conn net.Conn) {
conn.SetReadDeadline(time.Now().Add(d.readTimeout))

_, err := conn.Read(buffer)
if err == io.EOF {
if errors.Is(err, io.EOF) {
// Connection closed upfront so it does not need further handling. This
// happens for instance when testing the connectivity of the daemon.
return
Expand Down
12 changes: 6 additions & 6 deletions cli/node/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
func TestSocketClient_FailDial_Send(t *testing.T) {
client := socketClient{
socketpath: "",
dialFn: func(network, addr string, timeout time.Duration) (net.Conn, error) {
dialFn: func(_, _ string, _ time.Duration) (net.Conn, error) {
return nil, fake.GetError()
},
}
Expand All @@ -50,7 +50,7 @@

func TestSocketClient_BadOutConn_Send(t *testing.T) {
client := socketClient{
dialFn: func(network, addr string, timeout time.Duration) (net.Conn, error) {
dialFn: func(_, _ string, timeout time.Duration) (net.Conn, error) {

Check failure on line 53 in cli/node/daemon_test.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'timeout' seems to be unused, consider removing or renaming it as _ (revive)
return badConn{}, nil
},
}
Expand All @@ -61,7 +61,7 @@

func TestSocketClient_BadInConn_Send(t *testing.T) {
client := socketClient{
dialFn: func(network, addr string, timeout time.Duration) (net.Conn, error) {
dialFn: func(_, _ string, timeout time.Duration) (net.Conn, error) {

Check failure on line 64 in cli/node/daemon_test.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'timeout' seems to be unused, consider removing or renaming it as _ (revive)
return badConn{counter: fake.NewCounter(1)}, nil
},
}
Expand Down Expand Up @@ -154,7 +154,7 @@

func TestSocketDaemon_FailBindSocket_Listen(t *testing.T) {
daemon := &socketDaemon{
listenFn: func(network, addr string) (net.Listener, error) {
listenFn: func(_, _ string) (net.Listener, error) {
return nil, fake.GetError()
},
}
Expand Down Expand Up @@ -307,7 +307,7 @@
path string
}

func (ctx fakeContext) Path(name string) string {
func (ctx fakeContext) Path(_ string) string {
return ctx.path
}

Expand Down Expand Up @@ -335,7 +335,7 @@
return 0, fake.GetError()
}

func (badConn) SetReadDeadline(t time.Time) error {
func (badConn) SetReadDeadline(_ time.Time) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cli/node/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (exampleController) SetCommands(builder Builder) {
}

// OnStart implements node.Initializer. It injects the hello component.
func (exampleController) OnStart(flags cli.Flags, inj Injector) error {
func (exampleController) OnStart(_ cli.Flags, inj Injector) error {
inj.Inject(simpleHello{})

return nil
Expand Down
2 changes: 1 addition & 1 deletion cli/node/memcoin/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func setupChain(t *testing.T, nodes []string, ports []uint16) {
require.NoError(t, err)
}

func waitDaemon(t *testing.T, daemons []string) bool {
func waitDaemon(_ *testing.T, daemons []string) bool {
num := 50

for _, daemon := range daemons {
Expand Down
8 changes: 4 additions & 4 deletions cli/ucli/ucli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestBuild(t *testing.T) {
builder := NewBuilder("test", nil)
app := builder.Build().(*urfave.App)
app := builder.Build().(*urfave.App) //nolint:errcheck

app.Writer = io.Discard

Expand All @@ -28,7 +28,7 @@ func TestSetCommand(t *testing.T) {
builder.SetCommand("first")
builder.SetCommand("second")

app := builder.Build().(*urfave.App)
app := builder.Build().(*urfave.App) //nolint:errcheck

require.Len(t, app.Commands, 3)

Expand All @@ -39,10 +39,10 @@ func TestSetCommand(t *testing.T) {
}

func TestCommandBuilder(t *testing.T) {
builder := NewBuilder("test", nil).(*Builder)
builder := NewBuilder("test", nil).(*Builder) //nolint:errcheck
cmd := builder.SetCommand("first")

fakeAction := func(flags cli.Flags) error {
fakeAction := func(_ cli.Flags) error {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/access/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestGrant(t *testing.T) {
require.EqualError(t, err, fake.Err("failed to grant"))
}

func TestRegisterContract(t *testing.T) {
func TestRegisterContract(_ *testing.T) {
RegisterContract(native.NewExecution(), Contract{})
}

Expand Down Expand Up @@ -135,10 +135,10 @@ type fakeStore struct {
store.Snapshot
}

func (s fakeStore) Get(key []byte) ([]byte, error) {
func (s fakeStore) Get(_ []byte) ([]byte, error) {
return nil, nil
}

func (s fakeStore) Set(key, value []byte) error {
func (s fakeStore) Set(_, _ []byte) error {
return nil
}
2 changes: 1 addition & 1 deletion contracts/access/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ func (m miniController) OnStart(flags cli.Flags, inj node.Injector) error {
}

// OnStop implements node.Initializer.
func (miniController) OnStop(inj node.Injector) error {
func (miniController) OnStop(_ node.Injector) error {
return nil
}
8 changes: 4 additions & 4 deletions contracts/access/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestOnStart(t *testing.T) {
injector.Inject(native)

oldStore := newStore
newStore = func(path string) (accessStore, error) {
newStore = func(_ string) (accessStore, error) {
return nil, fake.GetError()
}

Expand Down Expand Up @@ -109,9 +109,9 @@ type fakeAccess struct {
}

func (a fakeAccess) Grant(
store store.Snapshot,
creds access.Credential,
idents ...access.Identity,
_ store.Snapshot,
_ access.Credential,
_ ...access.Identity,
) error {
return a.err
}
6 changes: 3 additions & 3 deletions contracts/value/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func NewController() node.Initializer {
}

// SetCommands implements node.Initializer.
func (miniController) SetCommands(builder node.Builder) {
func (miniController) SetCommands(_ node.Builder) {
}

// OnStart implements node.Initializer. It registers the value contract.
func (m miniController) OnStart(flags cli.Flags, inj node.Injector) error {
func (m miniController) OnStart(_ cli.Flags, inj node.Injector) error {
var access access.Service
err := inj.Resolve(&access)
if err != nil {
Expand All @@ -46,6 +46,6 @@ func (m miniController) OnStart(flags cli.Flags, inj node.Injector) error {
}

// OnStop implements node.Initializer.
func (miniController) OnStop(inj node.Injector) error {
func (miniController) OnStop(_ node.Injector) error {
return nil
}
8 changes: 5 additions & 3 deletions contracts/value/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"go.dedis.ch/dela/core/store"
)

func TestSetCommands(t *testing.T) {
func TestSetCommands(_ *testing.T) {
ctrl := NewController()
ctrl.SetCommands(nil)
}
Expand All @@ -20,13 +20,15 @@ func TestOnStart(t *testing.T) {

injector := node.NewInjector()
err := ctrl.OnStart(node.FlagSet{}, injector)
require.EqualError(t, err, "failed to resolve access service: couldn't find dependency for 'access.Service'")
require.EqualError(t, err,
"failed to resolve access service: couldn't find dependency for 'access.Service'")

access := fakeAccess{}
injector.Inject(&access)

err = ctrl.OnStart(node.FlagSet{}, injector)
require.EqualError(t, err, "failed to resolve native service: couldn't find dependency for '*native.Service'")
require.EqualError(t, err,
"failed to resolve native service: couldn't find dependency for '*native.Service'")

native := native.NewExecution()
injector.Inject(native)
Expand Down
2 changes: 1 addition & 1 deletion contracts/value/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestInfoLog(t *testing.T) {
require.Equal(t, 2, n)
}

func TestRegisterContract(t *testing.T) {
func TestRegisterContract(_ *testing.T) {
RegisterContract(native.NewExecution(), Contract{})
}

Expand Down
8 changes: 4 additions & 4 deletions core/access/darc/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ func ExampleService_Grant_alone() {
err = srvc.Match(store, credential, alice.GetPublicKey())
if err != nil {
panic("alice has no access: " + err.Error())
} else {
fmt.Println("Alice has the access")
}

fmt.Println("Alice has the access")

err = srvc.Match(store, credential, bob.GetPublicKey())
if err != nil {
fmt.Println("Bob has no access")
Expand Down Expand Up @@ -58,10 +58,10 @@ func ExampleService_Grant_group() {
err = srvc.Match(store, credential, alice.GetPublicKey(), bob.GetPublicKey())
if err != nil {
panic("alice and bob have no access: " + err.Error())
} else {
fmt.Println("[Alice, Bob] have the access")
}

fmt.Println("[Alice, Bob] have the access")

err = srvc.Match(store, credential, alice.GetPublicKey())
if err != nil {
fmt.Println("Alice alone has no access")
Expand Down
2 changes: 1 addition & 1 deletion core/execution/native/native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ type fakeTx struct {
contract string
}

func (tx fakeTx) GetArg(key string) []byte {
func (tx fakeTx) GetArg(_ string) []byte {
return []byte(tx.contract)
}
12 changes: 7 additions & 5 deletions core/ordering/cosipbft/blockstore/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *InDisk) Load() error {
return nil
}

err := bucket.Scan([]byte{}, func(key, value []byte) error {
err := bucket.Scan([]byte{}, func(_, value []byte) error {
link, err := s.fac.BlockLinkOf(s.context, value)
if err != nil {
return xerrors.Errorf("malformed block: %v", err)
Expand Down Expand Up @@ -166,10 +166,12 @@ func (s *InDisk) Get(id types.Digest) (types.BlockLink, error) {

// GetByIndex implements blockstore.BlockStore. It returns the block associated
// to the index if it exists, otherwise it returns an error.
func (s *InDisk) GetByIndex(index uint64) (link types.BlockLink, err error) {
func (s *InDisk) GetByIndex(index uint64) (types.BlockLink, error) {
var link types.BlockLink

key := s.makeKey(index)

err = s.doView(func(tx kv.ReadableTx) error {
err := s.doView(func(tx kv.ReadableTx) error {
bucket := tx.GetBucket(s.bucket)

value := bucket.Get(key)
Expand All @@ -187,7 +189,7 @@ func (s *InDisk) GetByIndex(index uint64) (link types.BlockLink, err error) {
return nil
})

return
return link, err
}

// GetChain implements blockstore.Blockstore. It returns a chain to the latest
Expand All @@ -209,7 +211,7 @@ func (s *InDisk) GetChain() (types.Chain, error) {
bucket := tx.GetBucket(s.bucket)

i := uint64(0)
err := bucket.Scan([]byte{}, func(key, value []byte) error {
err := bucket.Scan([]byte{}, func(_, value []byte) error {
if i >= length-1 {
link, err := s.fac.BlockLinkOf(s.context, value)
if err != nil {
Expand Down
Loading
Loading