Skip to content

Commit 349456a

Browse files
authored
Merge pull request #238 from bitromortac/2508-linter-updates
linter: enforce some constraints from code guidelines
2 parents 28e5880 + 6e3fbea commit 349456a

9 files changed

+58
-28
lines changed

.golangci.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ run:
44
go: "1.23"
55

66
linters-settings:
7+
lll:
8+
line-length: 80
79
govet:
810
# Don't report about shadowed variables
911
shadow: false
@@ -24,17 +26,21 @@ linters-settings:
2426
- G115 # Integer overflow conversion.
2527
staticcheck:
2628
checks: ["-SA1019"]
29+
revive:
30+
rules:
31+
- name: exported # To enforce conventions around exported comments.
32+
33+
issues:
34+
include:
35+
- EXC0012 # revive: Exported vars should have a docstring.
36+
- EXC0014 # revive: Exported vars's docstring should start with its name.
2737

2838
linters:
2939
enable-all: true
3040
disable:
3141
# Global variables are used in many places throughout the code base.
3242
- gochecknoglobals
3343

34-
# Some lines are over 80 characters on purpose and we don't want to make them
35-
# even longer by marking them as 'nolint'.
36-
- lll
37-
3844
# We want to allow short variable names.
3945
- varnamelen
4046

@@ -94,7 +100,6 @@ linters:
94100
- importas
95101
- interfacebloat
96102
- protogetter
97-
- revive
98103
- depguard
99104
- mnd
100105
- perfsprint

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ ifneq ($(workers),)
2828
LINT_WORKERS = --concurrency=$(workers)
2929
endif
3030

31-
DOCKER_TOOLS = docker run -v $$(pwd):/build lndclient-tools
31+
DOCKER_TOOLS = docker run \
32+
--rm \
33+
-v $(shell bash -c "$(GOCC) env GOCACHE || (mkdir -p /tmp/go-cache; echo /tmp/go-cache)"):/tmp/build/.cache \
34+
-v $(shell bash -c "$(GOCC) env GOMODCACHE || (mkdir -p /tmp/go-modcache; echo /tmp/go-modcache)"):/tmp/build/.modcache \
35+
-v $(shell bash -c "mkdir -p /tmp/go-lint-cache; echo /tmp/go-lint-cache"):/root/.cache/golangci-lint \
36+
-v $$(pwd):/build lndclient-tools
3237

3338
GREEN := "\\033[0;32m"
3439
NC := "\\033[0m"

chainkit_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ func (s *chainKitClient) GetBlockHeader(ctxParent context.Context,
126126

127127
// GetBestBlock returns the block hash and current height from the valid
128128
// most-work chain.
129-
func (s *chainKitClient) GetBestBlock(ctxParent context.Context) (chainhash.Hash,
130-
int32, error) {
129+
func (s *chainKitClient) GetBestBlock(
130+
ctxParent context.Context) (chainhash.Hash, int32, error) {
131131

132132
ctx, cancel := context.WithTimeout(ctxParent, s.timeout)
133133
defer cancel()

chainnotifier_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type NotifierOptions struct {
2929
ReOrgChan chan struct{}
3030
}
3131

32-
// defaultNotifierOptions returns the set of default options for the notifier.
32+
// DefaultNotifierOptions returns the set of default options for the notifier.
3333
func DefaultNotifierOptions() *NotifierOptions {
3434
return &NotifierOptions{}
3535
}

lightning_client.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,21 @@ type ForceCloseAnchorState int32
769769
const (
770770
// ForceCloseAnchorStateLimbo is set if the recovered_balance is zero
771771
// and limbo_balance is non-zero.
772-
ForceCloseAnchorStateLimbo = ForceCloseAnchorState(lnrpc.PendingChannelsResponse_ForceClosedChannel_LIMBO)
772+
ForceCloseAnchorStateLimbo = ForceCloseAnchorState(
773+
lnrpc.PendingChannelsResponse_ForceClosedChannel_LIMBO,
774+
)
773775

774776
// ForceCloseAnchorStateRecovered is set if the recovered_balance is
775777
// non-zero.
776-
ForceCloseAnchorStateRecovered = ForceCloseAnchorState(lnrpc.PendingChannelsResponse_ForceClosedChannel_RECOVERED)
778+
ForceCloseAnchorStateRecovered = ForceCloseAnchorState(
779+
lnrpc.PendingChannelsResponse_ForceClosedChannel_RECOVERED,
780+
)
777781

778782
// ForceCloseAnchorStateLost indicates a state that is neither
779783
// ForceCloseAnchorStateLimbo nor ForceCloseAnchorStateRecovered.
780-
ForceCloseAnchorStateLost = ForceCloseAnchorState(lnrpc.PendingChannelsResponse_ForceClosedChannel_LOST)
784+
ForceCloseAnchorStateLost = ForceCloseAnchorState(
785+
lnrpc.PendingChannelsResponse_ForceClosedChannel_LOST,
786+
)
781787
)
782788

783789
// String provides the string representation of a close initiator.
@@ -2157,7 +2163,8 @@ type WaitingCloseChannel struct {
21572163
RemotePending chainhash.Hash
21582164

21592165
// ChanStatusFlags specifies the current channel state, examples:
2160-
// - ChanStatusBorked|ChanStatusCommitBroadcasted|ChanStatusLocalCloseInitiator
2166+
// - ChanStatusBorked|ChanStatusCommitBroadcasted|
2167+
// ChanStatusLocalCloseInitiator
21612168
// - ChanStatusCoopBroadcasted|ChanStatusLocalCloseInitiator
21622169
// - ChanStatusCoopBroadcasted|ChanStatusRemoteCloseInitiator
21632170
ChanStatusFlags string
@@ -2167,8 +2174,8 @@ type WaitingCloseChannel struct {
21672174
}
21682175

21692176
// PendingChannels returns a list of lnd's pending channels.
2170-
func (s *lightningClient) PendingChannels(ctx context.Context) (*PendingChannels,
2171-
error) {
2177+
func (s *lightningClient) PendingChannels(
2178+
ctx context.Context) (*PendingChannels, error) {
21722179

21732180
rpcCtx, cancel := context.WithTimeout(ctx, s.timeout)
21742181
defer cancel()
@@ -2182,9 +2189,16 @@ func (s *lightningClient) PendingChannels(ctx context.Context) (*PendingChannels
21822189
}
21832190

21842191
pending := &PendingChannels{
2185-
PendingForceClose: make([]ForceCloseChannel, len(resp.PendingForceClosingChannels)),
2186-
PendingOpen: make([]PendingChannel, len(resp.PendingOpenChannels)),
2187-
WaitingClose: make([]WaitingCloseChannel, len(resp.WaitingCloseChannels)),
2192+
PendingForceClose: make(
2193+
[]ForceCloseChannel,
2194+
len(resp.PendingForceClosingChannels),
2195+
),
2196+
PendingOpen: make(
2197+
[]PendingChannel, len(resp.PendingOpenChannels),
2198+
),
2199+
WaitingClose: make(
2200+
[]WaitingCloseChannel, len(resp.WaitingCloseChannels),
2201+
),
21882202
}
21892203

21902204
for i, force := range resp.PendingForceClosingChannels {
@@ -3053,8 +3067,8 @@ func (s *lightningClient) getOpenStatusUpdate(
30533067
// OpenChannelStream opens a channel to the specified peer and with the
30543068
// specified arguments and options. This function returns a stream of
30553069
// updates.
3056-
func (s *lightningClient) OpenChannelStream(ctx context.Context, peer route.Vertex,
3057-
localSat, pushSat btcutil.Amount, private bool,
3070+
func (s *lightningClient) OpenChannelStream(ctx context.Context,
3071+
peer route.Vertex, localSat, pushSat btcutil.Amount, private bool,
30583072
opts ...OpenChannelOption) (<-chan *OpenStatusUpdate, <-chan error,
30593073
error) {
30603074

@@ -3288,6 +3302,7 @@ func (s *lightningClient) CloseChannel(ctx context.Context,
32883302
return updateChan, errChan, nil
32893303
}
32903304

3305+
// InboundFee holds the inbound fee policy for a channel.
32913306
type InboundFee struct {
32923307
// BaseFeeMsat is the inbound base fee charged regardless of the number
32933308
// of milli-satoshis received in the channel. By default, only negative

macaroon_pouch.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
// with a specific lnrpc service.
1414
type LnrpcServiceMac string
1515

16+
//nolint:revive
1617
const (
1718
AdminServiceMac LnrpcServiceMac = "admin.macaroon"
1819
InvoiceServiceMac LnrpcServiceMac = "invoices.macaroon"
@@ -75,7 +76,9 @@ func newSerializedMacaroon(macaroonPath string) (serializedMacaroon, error) {
7576
// WithMacaroonAuth modifies the passed context to include the macaroon KV
7677
// metadata of the target macaroon. This method can be used to add the macaroon
7778
// at call time, rather than when the connection to the gRPC server is created.
78-
func (s serializedMacaroon) WithMacaroonAuth(ctx context.Context) context.Context {
79+
func (s serializedMacaroon) WithMacaroonAuth(
80+
ctx context.Context) context.Context {
81+
7982
return metadata.AppendToOutgoingContext(ctx, "macaroon", string(s))
8083
}
8184

@@ -86,8 +89,8 @@ type macaroonPouch map[LnrpcServiceMac]serializedMacaroon
8689

8790
// newMacaroonPouch returns a new instance of a fully populated macaroonPouch
8891
// given the directory where all the macaroons are stored.
89-
func newMacaroonPouch(macaroonDir, customMacPath, customMacHex string) (macaroonPouch,
90-
error) {
92+
func newMacaroonPouch(macaroonDir, customMacPath, customMacHex string) (
93+
macaroonPouch, error) {
9194

9295
// If a custom macaroon is specified, we assume it contains all
9396
// permissions needed for the different subservers to function and we

macaroon_service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
)
2929

3030
var (
31+
//nolint:lll
3132
// sharedKeyNUMSBytes holds the bytes representing the compressed
3233
// byte encoding of SharedKeyNUMS. It was generated via a
3334
// try-and-increment approach using the phrase "Shared Secret" with

signer_client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ func marshallSignDescriptors(signDescriptors []*SignDescriptor,
249249
return keyDesc
250250
}
251251

252+
//nolint:lll
252253
// fullDescriptor is a helper method that creates a fully populated sign
253254
// descriptor that includes both the public key and the key locator (if
254255
// available). For the locator we explicitly check that both the family

walletkit_client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ func (m *walletKitClient) DeriveNextKey(ctx context.Context, family int32) (
434434
}, nil
435435
}
436436

437-
func (m *walletKitClient) DeriveKey(ctx context.Context, in *keychain.KeyLocator) (
438-
*keychain.KeyDescriptor, error) {
437+
func (m *walletKitClient) DeriveKey(ctx context.Context,
438+
in *keychain.KeyLocator) (*keychain.KeyDescriptor, error) {
439439

440440
rpcCtx, cancel := context.WithTimeout(ctx, m.timeout)
441441
defer cancel()
@@ -550,8 +550,8 @@ func (m *walletKitClient) SendOutputs(ctx context.Context,
550550
return tx, nil
551551
}
552552

553-
func (m *walletKitClient) EstimateFeeRate(ctx context.Context, confTarget int32) (
554-
chainfee.SatPerKWeight, error) {
553+
func (m *walletKitClient) EstimateFeeRate(ctx context.Context,
554+
confTarget int32) (chainfee.SatPerKWeight, error) {
555555

556556
rpcCtx, cancel := context.WithTimeout(ctx, m.timeout)
557557
defer cancel()
@@ -648,7 +648,7 @@ func unmarshallOutputType(o lnrpc.OutputScriptType) txscript.ScriptClass {
648648
}
649649
}
650650

651-
// RPCTransaction returns a rpc transaction.
651+
// UnmarshalTransactionDetail returns a rpc transaction.
652652
func UnmarshalTransactionDetail(tx *lnrpc.Transaction,
653653
chainParams *chaincfg.Params) (*lnwallet.TransactionDetail, error) {
654654

0 commit comments

Comments
 (0)