Skip to content

Commit b19422c

Browse files
authored
chore: add golangci lint rules (#134)
* add lint rules * ✍️ changelog * fix lint * fix lint * fix lint
1 parent 849a366 commit b19422c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+326
-151
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
uses: babylonlabs-io/.github/.github/workflows/[email protected]
1111
with:
1212
go-version: '1.23'
13-
go-lint-version: 'v1.60.2'
13+
go-lint-version: 'v1.64.8'
1414
run-unit-tests: true
1515
run-integration-tests: true
1616
run-lint: true

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
uses: babylonlabs-io/.github/.github/workflows/[email protected]
1414
with:
1515
go-version: '1.23'
16-
go-lint-version: 'v1.60.2'
16+
go-lint-version: 'v1.64.8'
1717
run-unit-tests: true
1818
run-integration-tests: true
1919
run-lint: true

.golangci.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
run:
2+
timeout: 5m
3+
4+
linters:
5+
disable-all: true
6+
enable:
7+
- asasalint
8+
- asciicheck
9+
- bidichk
10+
- bodyclose
11+
- containedctx
12+
- contextcheck
13+
- decorder
14+
- dogsled
15+
- durationcheck
16+
- errcheck
17+
- errchkjson
18+
- errname
19+
- errorlint
20+
- exhaustive
21+
- forbidigo
22+
- forcetypeassert
23+
- goconst
24+
- gocritic
25+
- gocyclo
26+
- goheader
27+
- gomodguard
28+
- goprintffuncname
29+
- gosimple
30+
- govet
31+
- grouper
32+
- importas
33+
- ineffassign
34+
- loggercheck
35+
- maintidx
36+
- makezero
37+
- misspell
38+
- nakedret
39+
- nilerr
40+
- nlreturn
41+
- noctx
42+
- nonamedreturns
43+
- nosprintfhostport
44+
# - paralleltest
45+
- reassign
46+
- revive
47+
- rowserrcheck
48+
- sqlclosecheck
49+
- staticcheck
50+
- stylecheck
51+
- usetesting
52+
- testableexamples
53+
- tparallel
54+
- typecheck
55+
- unconvert
56+
- unparam
57+
- usestdlibvars
58+
- unused
59+
- wastedassign
60+
- whitespace
61+
# - wrapcheck # we really should be using this, lax for now todo(lazar): unlax at somepoint, good practice
62+
63+
issues:
64+
max-same-issues: 0
65+
# Default: https://golangci-lint.run/usage/false-positives/#default-exclusions
66+
exclude-dirs:
67+
- e2etest
68+
exclude-rules:
69+
# Exclude some linters from running on tests files.
70+
- path: _test\.go
71+
linters:
72+
- gocyclo
73+
- errcheck
74+
- dupl
75+
- gosec
76+
- path-except: _test\.go
77+
linters:
78+
- forbidigo

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3737

3838
## Unreleased
3939

40+
### Improvements
41+
42+
* [#134](https://github.com/babylonlabs-io/covenant-emulator/pull/134) chore: add golangci lint rules
43+
4044
## v0.16.0-rc.1
4145

4246
### Improvements

clientcontroller/babylon.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ func NewBabylonController(
4444
btcParams *chaincfg.Params,
4545
logger *zap.Logger,
4646
) (*BabylonController, error) {
47-
4847
bbnConfig := config.BBNConfigToBabylonConfig(cfg)
4948

5049
if err := bbnConfig.Validate(); err != nil {
@@ -70,6 +69,7 @@ func NewBabylonController(
7069
func (bc *BabylonController) mustGetTxSigner() string {
7170
signer := bc.GetKeyAddress()
7271
prefix := bc.cfg.AccountPrefix
72+
7373
return sdk.MustBech32ifyAddressBytes(prefix, signer)
7474
}
7575

@@ -98,13 +98,13 @@ func (bc *BabylonController) QueryStakingParamsByVersion(version uint32) (*types
9898
// query btc checkpoint params
9999
ckptParamRes, err := bc.bbnClient.QueryClient.BTCCheckpointParams()
100100
if err != nil {
101-
return nil, fmt.Errorf("failed to query params of the btccheckpoint module: %v", err)
101+
return nil, fmt.Errorf("failed to query params of the btccheckpoint module: %w", err)
102102
}
103103

104104
// query btc staking params
105105
stakingParamRes, err := bc.bbnClient.QueryClient.BTCStakingParamsByVersion(version)
106106
if err != nil {
107-
return nil, fmt.Errorf("failed to query staking params with version %d: %v", version, err)
107+
return nil, fmt.Errorf("failed to query staking params with version %d: %w", version, err)
108108
}
109109

110110
covenantPks := make([]*btcec.PublicKey, 0, len(stakingParamRes.Params.CovenantPks))
@@ -210,8 +210,9 @@ func (bc *BabylonController) QueryVerifiedDelegations(limit uint64) ([]*types.De
210210
func (bc *BabylonController) QueryBTCDelegation(stakingTxHashHex string) (*types.Delegation, error) {
211211
resp, err := bc.bbnClient.QueryClient.BTCDelegation(stakingTxHashHex)
212212
if err != nil {
213-
return nil, fmt.Errorf("failed to query BTC delegation %s: %v", stakingTxHashHex, err)
213+
return nil, fmt.Errorf("failed to query BTC delegation %s: %w", stakingTxHashHex, err)
214214
}
215+
215216
return DelegationRespToDelegation(resp.BtcDelegation)
216217
}
217218

@@ -230,7 +231,7 @@ func (bc *BabylonController) queryDelegationsWithStatus(status btcstakingtypes.B
230231
for indexDels < delsLimit {
231232
res, err := bc.bbnClient.QueryClient.BTCDelegations(status, pagination)
232233
if err != nil {
233-
return nil, fmt.Errorf("failed to query BTC delegations: %v", err)
234+
return nil, fmt.Errorf("failed to query BTC delegations: %w", err)
234235
}
235236

236237
for _, delResp := range res.BtcDelegations {
@@ -271,6 +272,7 @@ func (bc *BabylonController) queryDelegationsWithStatus(status btcstakingtypes.B
271272

272273
func getContextWithCancel(timeout time.Duration) (context.Context, context.CancelFunc) {
273274
ctx, cancel := context.WithTimeout(context.Background(), timeout)
275+
274276
return ctx, cancel
275277
}
276278

@@ -557,7 +559,7 @@ func (bc *BabylonController) QueryFinalityProviders() ([]*btcstakingtypes.Finali
557559
}
558560
res, err := queryClient.FinalityProviders(ctx, queryRequest)
559561
if err != nil {
560-
return nil, fmt.Errorf("failed to query finality providers: %v", err)
562+
return nil, fmt.Errorf("failed to query finality providers: %w", err)
561563
}
562564
fps = append(fps, res.FinalityProviders...)
563565
if res.Pagination == nil || res.Pagination.NextKey == nil {
@@ -582,7 +584,7 @@ func (bc *BabylonController) QueryBtcLightClientTip() (*btclctypes.BTCHeaderInfo
582584
queryRequest := &btclctypes.QueryTipRequest{}
583585
res, err := queryClient.Tip(ctx, queryRequest)
584586
if err != nil {
585-
return nil, fmt.Errorf("failed to query BTC tip: %v", err)
587+
return nil, fmt.Errorf("failed to query BTC tip: %w", err)
586588
}
587589

588590
return res.Header, nil

cmd/covd/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const (
88
keyNameFlag = "key-name"
99
passphraseFlag = "passphrase"
1010
hdPathFlag = "hd-path"
11-
chainIdFlag = "chain-id"
11+
chainIDFlag = "chain-id"
1212
keyringBackendFlag = "keyring-backend"
1313

1414
defaultChainID = "chain-test"

cmd/covd/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ func initHome(c *cli.Context) error {
5454
defaultConfig := covcfg.DefaultConfigWithHomePath(homePath)
5555
fileParser := flags.NewParser(&defaultConfig, flags.Default)
5656

57-
return flags.NewIniParser(fileParser).WriteFile(covcfg.ConfigFile(homePath), flags.IniIncludeComments|flags.IniIncludeDefaults)
57+
return flags.NewIniParser(fileParser).WriteFile(covcfg.File(homePath), flags.IniIncludeComments|flags.IniIncludeDefaults)
5858
}

cmd/covd/key.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var createKeyCommand = cli.Command{
2626
Usage: "Create a Covenant account in the keyring.",
2727
Flags: []cli.Flag{
2828
cli.StringFlag{
29-
Name: chainIdFlag,
29+
Name: chainIDFlag,
3030
Usage: "The chainID of the consumer chain",
3131
Value: defaultChainID,
3232
},
@@ -61,7 +61,7 @@ var createKeyCommand = cli.Command{
6161

6262
func createKey(ctx *cli.Context) error {
6363
homePath := ctx.String(homeFlag)
64-
chainID := ctx.String(chainIdFlag)
64+
chainID := ctx.String(chainIDFlag)
6565
keyName := ctx.String(keyNameFlag)
6666
backend := ctx.String(keyringBackendFlag)
6767
passphrase := ctx.String(passphraseFlag)
@@ -71,7 +71,7 @@ func createKey(ctx *cli.Context) error {
7171
// check the config file exists
7272
cfg, err := covcfg.LoadConfig(homePath)
7373
if err != nil {
74-
return fmt.Errorf("failed to load the config from %s: %w", covcfg.ConfigFile(homePath), err)
74+
return fmt.Errorf("failed to load the config from %s: %w", covcfg.File(homePath), err)
7575
}
7676

7777
keyPair, err := keyring.CreateCovenantKey(
@@ -100,7 +100,7 @@ func createKey(ctx *cli.Context) error {
100100
cfg.BabylonConfig.KeyringBackend = keyBackend
101101
fileParser := flags.NewParser(cfg, flags.Default)
102102

103-
return flags.NewIniParser(fileParser).WriteFile(covcfg.ConfigFile(homePath), flags.IniIncludeComments|flags.IniIncludeDefaults)
103+
return flags.NewIniParser(fileParser).WriteFile(covcfg.File(homePath), flags.IniIncludeComments|flags.IniIncludeDefaults)
104104
}
105105

106106
var showKeyCommand = cli.Command{
@@ -109,7 +109,7 @@ var showKeyCommand = cli.Command{
109109
Usage: "Show a Covenant account in the keyring.",
110110
Flags: []cli.Flag{
111111
cli.StringFlag{
112-
Name: chainIdFlag,
112+
Name: chainIDFlag,
113113
Usage: "The chainID of the consumer chain",
114114
Value: defaultChainID,
115115
},
@@ -139,7 +139,7 @@ var showKeyCommand = cli.Command{
139139

140140
func showKey(ctx *cli.Context) error {
141141
homePath := ctx.String(homeFlag)
142-
chainID := ctx.String(chainIdFlag)
142+
chainID := ctx.String(chainIDFlag)
143143
keyName := ctx.String(keyNameFlag)
144144
backend := ctx.String(keyringBackendFlag)
145145
passphrase := ctx.String(passphraseFlag)
@@ -178,13 +178,15 @@ func showKey(ctx *cli.Context) error {
178178
BabylonAddr: babylonAddr.String(),
179179
},
180180
)
181+
181182
return nil
182183
}
183184

184185
func printRespJSON(resp interface{}) {
185186
jsonBytes, err := json.MarshalIndent(resp, "", " ")
186187
if err != nil {
187188
fmt.Println("unable to decode response: ", err)
189+
188190
return
189191
}
190192

cmd/covd/start.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ func start(ctx *cli.Context) error {
5858
return fmt.Errorf("failed to create rpc client for the consumer chain: %w", err)
5959
}
6060

61-
signer, err := newRemoteSignerFromConfig(cfg)
62-
if err != nil {
63-
return fmt.Errorf("failed to create remote signer from config: %w", err)
64-
}
61+
signer := newRemoteSignerFromConfig(cfg)
6562

6663
// Perform health check on the remote signer
6764
logger.Info("Performing health check on remote signer...")
@@ -70,7 +67,7 @@ func start(ctx *cli.Context) error {
7067
}
7168
logger.Info("Remote signer health check passed")
7269

73-
ce, err := covenant.NewCovenantEmulator(cfg, bbnClient, logger, signer)
70+
ce, err := covenant.NewEmulator(cfg, bbnClient, logger, signer)
7471
if err != nil {
7572
return fmt.Errorf("failed to start the covenant emulator: %w", err)
7673
}
@@ -82,13 +79,10 @@ func start(ctx *cli.Context) error {
8279
}
8380

8481
srv := covsrv.NewCovenantServer(logger, ce, shutdownInterceptor)
85-
if err != nil {
86-
return fmt.Errorf("failed to create covenant server: %w", err)
87-
}
8882

8983
return srv.RunUntilShutdown()
9084
}
9185

92-
func newRemoteSignerFromConfig(cfg *covcfg.Config) (covenant.Signer, error) {
93-
return remotesigner.NewRemoteSigner(cfg.RemoteSigner), nil
86+
func newRemoteSignerFromConfig(cfg *covcfg.Config) covenant.Signer {
87+
return remotesigner.NewRemoteSigner(cfg.RemoteSigner)
9488
}

config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type Config struct {
6161
func LoadConfig(homePath string) (*Config, error) {
6262
// The home directory is required to have a configuration file with a specific name
6363
// under it.
64-
cfgFile := ConfigFile(homePath)
64+
cfgFile := File(homePath)
6565
if !util.FileExists(cfgFile) {
6666
return nil, fmt.Errorf("specified config file does "+
6767
"not exist in %s", cfgFile)
@@ -113,7 +113,7 @@ func (cfg *Config) Validate() error {
113113
return nil
114114
}
115115

116-
func ConfigFile(homePath string) string {
116+
func File(homePath string) string {
117117
return filepath.Join(homePath, defaultConfigFileName)
118118
}
119119

0 commit comments

Comments
 (0)