Skip to content

Commit

Permalink
build: fix depguard linter configuration (#730)
Browse files Browse the repository at this point in the history
* build: fix depguard linter configuration

* build: lint on golangci-lint changes
  • Loading branch information
lklimek authored Jan 30, 2024
1 parent 2824726 commit 86a79ac
Show file tree
Hide file tree
Showing 118 changed files with 726 additions and 822 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
pull_request:
paths:
- "**.go"
- ".golangci.yml"
- ".github/linters/*"
push:
branches:
- master
Expand All @@ -37,6 +39,7 @@ jobs:
**/**.go
go.mod
go.sum
.golangci.yml
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libpcap-dev
Expand Down
18 changes: 13 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ linters:
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
# - depguard
- dogsled
- dupl
- errcheck
Expand All @@ -30,14 +29,11 @@ linters:
- nakedret
- nolintlint
- prealloc
- staticcheck
- structcheck
- stylecheck
# - typecheck
- unconvert
# - unparam
- unused
- varcheck
# - whitespace
# - wsl

Expand All @@ -53,7 +49,19 @@ linters-settings:
max-blank-identifiers: 3
golint:
min-confidence: 0
goconst:
min-len: 5
min-occurrences: 5
ignore-tests: true
maligned:
suggest-new: true
misspell:
locale: US
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
severity: warning
disabled: false
arguments:
- allowRegex: "^_"
4 changes: 2 additions & 2 deletions abci/client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewGRPCClient(logger log.Logger, addr string, mustConnect bool) Client {
return cli
}

func dialerFunc(ctx context.Context, addr string) (net.Conn, error) {
func dialerFunc(_ctx context.Context, addr string) (net.Conn, error) {
return tmnet.Connect(addr)
}

Expand Down Expand Up @@ -122,7 +122,7 @@ func (cli *grpcClient) Error() error {

//----------------------------------------

func (cli *grpcClient) Flush(ctx context.Context) error { return nil }
func (cli *grpcClient) Flush(_ctx context.Context) error { return nil }

func (cli *grpcClient) Echo(ctx context.Context, msg string) (*types.ResponseEcho, error) {
return cli.client.Echo(ctx, types.ToRequestEcho(msg).GetEcho(), grpc.WaitForReady(true))
Expand Down
6 changes: 3 additions & 3 deletions abci/cmd/abci-cli/abci-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func compose(fs []func() error) error {
return err
}

func cmdTest(cmd *cobra.Command, args []string) error {
func cmdTest(cmd *cobra.Command, _args []string) error {
ctx := cmd.Context()
return compose(
[]func() error{
Expand Down Expand Up @@ -379,7 +379,7 @@ func cmdTest(cmd *cobra.Command, args []string) error {
})
}

func cmdBatch(cmd *cobra.Command, args []string) error {
func cmdBatch(cmd *cobra.Command, _args []string) error {
bufReader := bufio.NewReader(os.Stdin)
LOOP:
for {
Expand All @@ -405,7 +405,7 @@ LOOP:
return nil
}

func cmdConsole(cmd *cobra.Command, args []string) error {
func cmdConsole(cmd *cobra.Command, _args []string) error {
for {
fmt.Printf("> ")
bufReader := bufio.NewReader(os.Stdin)
Expand Down
7 changes: 1 addition & 6 deletions abci/example/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net"
"os"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand All @@ -23,10 +22,6 @@ import (
tmnet "github.com/dashpay/tenderdash/libs/net"
)

func init() {
rand.Seed(time.Now().UnixNano())
}

func TestKVStore(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -98,7 +93,7 @@ func testBulk(ctx context.Context, t *testing.T, logger log.Logger, app types.Ap
//-------------------------
// test grpc

func dialerFunc(ctx context.Context, addr string) (net.Conn, error) {
func dialerFunc(_ctx context.Context, addr string) (net.Conn, error) {
return tmnet.Connect(addr)
}

Expand Down
4 changes: 2 additions & 2 deletions abci/example/kvstore/snapshots.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// nolint: gosec
//nolint:gosec
package kvstore

import (
Expand Down Expand Up @@ -85,7 +85,7 @@ func (s *SnapshotStore) saveMetadata() error {
// save the file to a new file and move it to make saving atomic.
newFile := filepath.Join(s.dir, "metadata.json.new")
file := filepath.Join(s.dir, "metadata.json")
err = os.WriteFile(newFile, bz, 0644) // nolint: gosec
err = os.WriteFile(newFile, bz, 0644) //nolint:gosec
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion abci/example/kvstore/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (state kvState) GetAppHash() tmbytes.HexBytes {
return state.AppHash.Copy()
}

func (state *kvState) UpdateAppHash(lastCommittedState State, txs types1.Txs, txResults []*types.ExecTxResult) error {
func (state *kvState) UpdateAppHash(lastCommittedState State, _txs types1.Txs, txResults []*types.ExecTxResult) error {
// UpdateAppHash updates app hash for the current app state.
txResultsHash, err := types.TxResultsHash(txResults)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion abci/example/kvstore/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func execTx(tx types.Tx, roundState State) (abci.ExecTxResult, error) {

// execPrepareTx is noop. tx data is considered as placeholder
// and is substitute at the PrepareProposal.
func execPrepareTx(tx []byte) (abci.ExecTxResult, error) {
func execPrepareTx(_tx []byte) (abci.ExecTxResult, error) {
// noop
return abci.ExecTxResult{}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion abci/server/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ func (app *gRPCApplication) Echo(_ context.Context, req *types.RequestEcho) (*ty
return &types.ResponseEcho{Message: req.Message}, nil
}

func (app *gRPCApplication) Flush(_ context.Context, req *types.RequestFlush) (*types.ResponseFlush, error) {
func (app *gRPCApplication) Flush(_ context.Context, _req *types.RequestFlush) (*types.ResponseFlush, error) {
return &types.ResponseFlush{}, nil
}
2 changes: 1 addition & 1 deletion abci/tests/server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func FinalizeBlock(ctx context.Context, client abciclient.Client, txBytes [][]by
return nil
}

func PrepareProposal(ctx context.Context, client abciclient.Client, txBytes [][]byte, codeExp []types.TxRecord_TxAction, dataExp []byte) error {
func PrepareProposal(ctx context.Context, client abciclient.Client, txBytes [][]byte, codeExp []types.TxRecord_TxAction, _dataExp []byte) error {
res, _ := client.PrepareProposal(ctx, &types.RequestPrepareProposal{Txs: txBytes})
for i, tx := range res.TxRecords {
if tx.Action != codeExp[i] {
Expand Down
20 changes: 10 additions & 10 deletions abci/types/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,45 +55,45 @@ func NewBaseApplication() *BaseApplication {
return &BaseApplication{}
}

func (BaseApplication) Info(_ context.Context, req *RequestInfo) (*ResponseInfo, error) {
func (BaseApplication) Info(_ context.Context, _req *RequestInfo) (*ResponseInfo, error) {
return &ResponseInfo{}, nil
}

func (BaseApplication) CheckTx(_ context.Context, req *RequestCheckTx) (*ResponseCheckTx, error) {
func (BaseApplication) CheckTx(_ context.Context, _req *RequestCheckTx) (*ResponseCheckTx, error) {
return &ResponseCheckTx{Code: CodeTypeOK}, nil
}

func (BaseApplication) ExtendVote(_ context.Context, req *RequestExtendVote) (*ResponseExtendVote, error) {
func (BaseApplication) ExtendVote(_ context.Context, _req *RequestExtendVote) (*ResponseExtendVote, error) {
return &ResponseExtendVote{}, nil
}

func (BaseApplication) VerifyVoteExtension(_ context.Context, req *RequestVerifyVoteExtension) (*ResponseVerifyVoteExtension, error) {
func (BaseApplication) VerifyVoteExtension(_ context.Context, _req *RequestVerifyVoteExtension) (*ResponseVerifyVoteExtension, error) {
return &ResponseVerifyVoteExtension{
Status: ResponseVerifyVoteExtension_ACCEPT,
}, nil
}

func (BaseApplication) Query(_ context.Context, req *RequestQuery) (*ResponseQuery, error) {
func (BaseApplication) Query(_ context.Context, _req *RequestQuery) (*ResponseQuery, error) {
return &ResponseQuery{Code: CodeTypeOK}, nil
}

func (BaseApplication) InitChain(_ context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
func (BaseApplication) InitChain(_ context.Context, _req *RequestInitChain) (*ResponseInitChain, error) {
return &ResponseInitChain{}, nil
}

func (BaseApplication) ListSnapshots(_ context.Context, req *RequestListSnapshots) (*ResponseListSnapshots, error) {
func (BaseApplication) ListSnapshots(_ context.Context, _req *RequestListSnapshots) (*ResponseListSnapshots, error) {
return &ResponseListSnapshots{}, nil
}

func (BaseApplication) OfferSnapshot(_ context.Context, req *RequestOfferSnapshot) (*ResponseOfferSnapshot, error) {
func (BaseApplication) OfferSnapshot(_ context.Context, _req *RequestOfferSnapshot) (*ResponseOfferSnapshot, error) {
return &ResponseOfferSnapshot{}, nil
}

func (BaseApplication) LoadSnapshotChunk(_ context.Context, _ *RequestLoadSnapshotChunk) (*ResponseLoadSnapshotChunk, error) {
return &ResponseLoadSnapshotChunk{}, nil
}

func (BaseApplication) ApplySnapshotChunk(_ context.Context, req *RequestApplySnapshotChunk) (*ResponseApplySnapshotChunk, error) {
func (BaseApplication) ApplySnapshotChunk(_ context.Context, _req *RequestApplySnapshotChunk) (*ResponseApplySnapshotChunk, error) {
return &ResponseApplySnapshotChunk{}, nil
}

Expand Down Expand Up @@ -132,7 +132,7 @@ func (BaseApplication) ProcessProposal(_ context.Context, req *RequestProcessPro
}, nil
}

func (BaseApplication) FinalizeBlock(_ context.Context, req *RequestFinalizeBlock) (*ResponseFinalizeBlock, error) {
func (BaseApplication) FinalizeBlock(_ context.Context, _req *RequestFinalizeBlock) (*ResponseFinalizeBlock, error) {

return &ResponseFinalizeBlock{}, nil
}
2 changes: 1 addition & 1 deletion cmd/abcidump/cmd/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (captureCmd *CaptureCmd) Command() *cobra.Command {
}

// RunE executes traffic capture
func (captureCmd *CaptureCmd) RunE(cmd *cobra.Command, args []string) error {
func (captureCmd *CaptureCmd) RunE(_cmd *cobra.Command, _args []string) error {
logger.Debug("Starting packet capture", "port", captureCmd.Port)

return captureCmd.capture()
Expand Down
4 changes: 2 additions & 2 deletions cmd/abcidump/cmd/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (cborCmd *CborCmd) Command() *cobra.Command {
}

// PreRunE parses command line arguments
func (cborCmd *CborCmd) PreRunE(_ *cobra.Command, args []string) (err error) {
func (cborCmd *CborCmd) PreRunE(_ *cobra.Command, _args []string) (err error) {
if cborCmd.Input, err = loadInputData(cborCmd.InputData, cborCmd.InputFormat); err != nil {
return err
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func marshalMap(mapToMarshal map[interface{}]interface{}, indent []byte, out io.
}

// RunE executes main logic of this command
func (cborCmd *CborCmd) RunE(_ *cobra.Command, args []string) error {
func (cborCmd *CborCmd) RunE(_ *cobra.Command, _args []string) error {
data, err := io.ReadAll(cborCmd.Input)
if err != nil {
return fmt.Errorf("cannot read data: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/abcidump/cmd/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (parseCmd *ParseCmd) Command() *cobra.Command {
}

// PreRunE parses command line arguments
func (parseCmd *ParseCmd) PreRunE(cmd *cobra.Command, args []string) (err error) {
func (parseCmd *ParseCmd) PreRunE(_cmd *cobra.Command, _args []string) (err error) {
if parseCmd.Input, err = loadInputData(parseCmd.InputData, parseCmd.InputFormat); err != nil {
return err
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func loadInputData(input, format string) (reader io.Reader, err error) {
}

// RunE executes parsing logic
func (parseCmd *ParseCmd) RunE(cmd *cobra.Command, args []string) error {
func (parseCmd *ParseCmd) RunE(cmd *cobra.Command, _args []string) error {
var err error

parser := parser.NewParser(cmd.InOrStdin())
Expand Down
6 changes: 5 additions & 1 deletion cmd/priv_val_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ func registerPrometheus(addr string, s *grpc.Server) *http.Server {
// Initialize all metrics.
grpcMetrics.InitializeMetrics(s)
// create http server to serve prometheus
httpServer := &http.Server{Handler: promhttp.HandlerFor(reg, promhttp.HandlerOpts{}), Addr: addr}
httpServer := &http.Server{
Handler: promhttp.HandlerFor(reg, promhttp.HandlerOpts{}),
Addr: addr,
ReadHeaderTimeout: 10 * time.Second,
}

go func() {
if err := httpServer.ListenAndServe(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tenderdash/commands/debug/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func killProc(pid int, dir string) error {
// pipe STDERR output from tailing the Tendermint process to a file
//
// NOTE: This will only work on UNIX systems.
cmd := exec.Command("tail", "-f", fmt.Sprintf("/proc/%d/fd/2", pid)) // nolint: gosec
cmd := exec.Command("tail", "-f", fmt.Sprintf("/proc/%d/fd/2", pid)) //nolint:gosec

outFile, err := os.Create(filepath.Join(dir, "stacktrace.out"))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tenderdash/commands/debug/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func copyConfig(home, dir string) error {
func dumpProfile(dir, addr, profile string, debug int) error {
endpoint := fmt.Sprintf("%s/debug/pprof/%s?debug=%d", addr, profile, debug)

resp, err := http.Get(endpoint) // nolint: gosec
resp, err := http.Get(endpoint) //nolint:gosec
if err != nil {
return fmt.Errorf("failed to query for %s profile: %w", profile, err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/tenderdash/commands/gen_node_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Seed phrase and optional password is read from standard input.`,
return cmd
}

func genNodeKeyFlagsPreRunE(cmd *cobra.Command, args []string) error {
func genNodeKeyFlagsPreRunE(_cmd *cobra.Command, _args []string) error {
if useSeedPhrase && pemFile != "" {
return fmt.Errorf("--%s cannot be be used with --%s", flagFromMnemonic, flagFromPem)
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func readMnemonic(in io.Reader, out io.Writer) (mnemonic string, password string
}

// nodeKeyFromMnemonic reads BIP39 mnemonic and optional passphrase from stdin, and derives node key from it.
func nodeKeyFromMnemonic(cmd *cobra.Command, args []string) (types.NodeKey, error) {
func nodeKeyFromMnemonic(cmd *cobra.Command, _args []string) (types.NodeKey, error) {
mnemonic, password, err := readMnemonic(cmd.InOrStdin(), cmd.OutOrStdout())
if err != nil {
return types.NodeKey{}, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/tenderdash/commands/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func ResetState(dbDir string, logger log.Logger) error {
// ResetFilePV loads the file private validator and resets the watermark to 0. If used on an existing network,
// this can cause the node to double sign.
// XXX: this is unsafe and should only suitable for testnets.
func ResetFilePV(privValKeyFile, privValStateFile string, logger log.Logger, keyType string) error {
func ResetFilePV(privValKeyFile, privValStateFile string, logger log.Logger, _keyType string) error {
if _, err := os.Stat(privValKeyFile); err == nil {
pv, err := privval.LoadFilePVEmptyState(privValKeyFile, privValStateFile)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions crypto/bls12381/bls12381_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// nolint:lll
//nolint:lll
package bls12381

import (
Expand Down Expand Up @@ -378,7 +378,8 @@ func TestRecoverThresholdSignatureFromSharesCaseStudy(t *testing.T) {
msg: "C4E3500CAEC0AEB79CFA05F10EBE77717BEEF5D51159E2A89D8FE98B696BE4A9",
},
}
for i, tc := range testCases {
for i, testCase := range testCases {
tc := testCase
t.Run(fmt.Sprintf("test-case #%d", i), func(t *testing.T) {
t.Parallel()
var err error
Expand Down
6 changes: 2 additions & 4 deletions crypto/merkle/proof_key_path_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package merkle

import (
// it is ok to use math/rand here: we do not need a cryptographically secure random
// number generator here and we can run the tests a bit faster
"math/rand"
"testing"

"github.com/stretchr/testify/require"
"golang.org/x/exp/rand"
)

func TestKeyPath(t *testing.T) {
Expand All @@ -26,7 +24,7 @@ func TestKeyPath(t *testing.T) {
keys[i][j] = alphanum[rand.Intn(len(alphanum))]
}
case KeyEncodingHex:
rand.Read(keys[i])
_, _ = rand.Read(keys[i])
default:
require.Fail(t, "Unexpected encoding")
}
Expand Down
Loading

0 comments on commit 86a79ac

Please sign in to comment.