Skip to content

Commit d766677

Browse files
positiveblueguggero
authored andcommitted
multi: make ci/linter happy
- Use dockerized linter - Run ci with Go 1.18.2 - golangci: match the same settings that we have in LND
1 parent 7948c3f commit d766677

File tree

13 files changed

+1801
-39
lines changed

13 files changed

+1801
-39
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ env:
1616
# go needs absolute directories, using the $HOME variable doesn't work here.
1717
GOCACHE: /home/runner/work/go/pkg/build
1818
GOPATH: /home/runner/work/go
19-
GO_VERSION: 1.16.x
19+
GO_VERSION: 1.18.x
2020

2121
jobs:
2222
build:

.golangci.yml

Lines changed: 83 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,94 @@ linters-settings:
99
gofmt:
1010
# simplify code: gofmt with `-s` option, true by default
1111
simplify: true
12+
tagliatelle:
13+
case:
14+
rules:
15+
json: snake
16+
whitespace:
17+
multi-func: true
18+
multi-if: true
19+
gosec:
20+
excludes:
21+
- G402 # Look for bad TLS connection settings.
22+
- G306 # Poor file permissions used when writing to a new file.
23+
staticcheck:
24+
go: "1.18"
25+
checks: ["-SA1019"]
1226

1327
linters:
1428
enable-all: true
1529
disable:
16-
# Init functions are used by loggers throughout the codebase.
17-
- gochecknoinits
30+
# Global variables are used in many places throughout the code base.
31+
- gochecknoglobals
1832

19-
# Global variables are used by loggers.
20-
- gochecknoglobals
33+
# Some lines are over 80 characters on purpose and we don't want to make them
34+
# even longer by marking them as 'nolint'.
35+
- lll
2136

22-
# Some lines are over 80 characters on purpose and we don't want to make
23-
# them even longer by marking them as 'nolint'.
24-
- lll
37+
# We want to allow short variable names.
38+
- varnamelen
2539

26-
# We don't care (enough) about misaligned structs to lint that.
27-
- maligned
40+
# We want to allow TODOs.
41+
- godox
42+
43+
# We have long functions, especially in tests. Moving or renaming those would
44+
# trigger funlen problems that we may not want to solve at that time.
45+
- funlen
46+
47+
# Disable for now as we haven't yet tuned the sensitivity to our codebase
48+
# yet. Enabling by default for example, would also force new contributors to
49+
# potentially extensively refactor code, when they want to smaller change to
50+
# land.
51+
- gocyclo
52+
- gocognit
53+
- cyclop
54+
55+
# Instances of table driven tests that don't pre-allocate shouldn't trigger
56+
# the linter.
57+
- prealloc
58+
59+
# Init functions are used by loggers throughout the codebase.
60+
- gochecknoinits
61+
62+
# Causes stack overflow, see https://github.com/polyfloyd/go-errorlint/issues/19.
63+
- errorlint
64+
65+
# Deprecated linters. See https://golangci-lint.run/usage/linters/.
66+
- interfacer
67+
- golint
68+
- maligned
69+
- scopelint
70+
71+
# New linters that need a code adjustment first.
72+
- wrapcheck
73+
- nolintlint
74+
- paralleltest
75+
- tparallel
76+
- testpackage
77+
- gofumpt
78+
- gomoddirectives
79+
- ireturn
80+
- maintidx
81+
- nlreturn
82+
- dogsled
83+
- gci
84+
- containedctx
85+
- contextcheck
86+
- errname
87+
- exhaustivestruct
88+
- goerr113
89+
- gomnd
90+
- ifshort
91+
- noctx
92+
- nestif
93+
- wsl
94+
- exhaustive
95+
- forcetypeassert
96+
- nilerr
97+
- nilnil
98+
- stylecheck
99+
- thelper
100+
- exhaustruct
101+
- importas
28102

29-
# We have long functions, especially in tests. Moving or renaming those
30-
# would trigger funlen problems that we may not want to solve at that time.
31-
- funlen

Makefile

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
PKG := github.com/lightninglabs/lndclient
22

3-
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
3+
TOOLS_DIR := tools
44

5-
GO_BIN := ${GOPATH}/bin
6-
LINT_BIN := $(GO_BIN)/golangci-lint
5+
GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
76

8-
LINT_COMMIT := v1.18.0
7+
GO_BIN := ${GOPATH}/bin
8+
GOIMPORTS_BIN := $(GO_BIN)/gosimports
99

10-
DEPGET := cd /tmp && go get -v
1110
GOBUILD := go build -v
1211
GOINSTALL := go install -v
1312
GOTEST := go test -v
@@ -29,7 +28,7 @@ ifneq ($(workers),)
2928
LINT_WORKERS = --concurrency=$(workers)
3029
endif
3130

32-
LINT = $(LINT_BIN) run -v $(LINT_WORKERS)
31+
DOCKER_TOOLS = docker run -v $$(pwd):/build lndclient-tools
3332

3433
GREEN := "\\033[0;32m"
3534
NC := "\\033[0m"
@@ -44,9 +43,9 @@ all: build check install
4443
# ============
4544
# DEPENDENCIES
4645
# ============
47-
$(LINT_BIN):
48-
@$(call print, "Fetching linter")
49-
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
46+
$(GOIMPORTS_BIN):
47+
@$(call print, "Installing goimports.")
48+
cd $(TOOLS_DIR); go install -trimpath $(GOIMPORTS_PKG)
5049

5150
# ============
5251
# INSTALLATION
@@ -56,6 +55,10 @@ build:
5655
@$(call print, "Building lndclient.")
5756
$(GOBUILD) -ldflags="$(LDFLAGS)" $(PKG)
5857

58+
docker-tools:
59+
@$(call print, "Building tools docker image.")
60+
docker build -q -t lndclient-tools $(TOOLS_DIR)
61+
5962
# =======
6063
# TESTING
6164
# =======
@@ -73,13 +76,15 @@ unit-race:
7376
# =========
7477
# UTILITIES
7578
# =========
76-
fmt:
79+
fmt: $(GOIMPORTS_BIN)
80+
@$(call print, "Fixing imports.")
81+
gosimports -w $(GOFILES_NOVENDOR)
7782
@$(call print, "Formatting source.")
7883
gofmt -l -w -s $(GOFILES_NOVENDOR)
7984

80-
lint: $(LINT_BIN)
85+
lint: docker-tools
8186
@$(call print, "Linting source.")
82-
$(LINT)
87+
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
8388

8489
.PHONY: default \
8590
build \

basic_client_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
// Tests that NewBasicConn works correctly when macaroon and TLS certificate
1313
// data are passed in directly instead of being supplied as file paths.
1414
func TestParseTLSAndMacaroon(t *testing.T) {
15-
1615
tlsData := `-----BEGIN CERTIFICATE-----
1716
MIIDhzCCAm+gAwIBAgIUEkmdMOVPL92AwgsSYFFBvz4ilmUwDQYJKoZIhvcNAQEL
1817
BQAwUzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAk1OMRQwEgYDVQQHDAtNaW5uZWFw

chainnotifier_client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ func (s *chainNotifierClient) RegisterConfirmationsNtfn(ctx context.Context,
162162
}
163163

164164
switch c := confEvent.Event.(type) {
165-
166165
// Script confirmed
167166
case *chainrpc.ConfEvent_Conf:
168167
tx, err := decodeTx(c.Conf.RawTx)

lightning_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ type ChannelInfo struct {
352352

353353
func (s *lightningClient) newChannelInfo(channel *lnrpc.Channel) (*ChannelInfo,
354354
error) {
355+
355356
remoteVertex, err := route.NewVertexFromStr(channel.RemotePubkey)
356357
if err != nil {
357358
return nil, err
@@ -1339,9 +1340,8 @@ func (s *lightningClient) payInvoice(ctx context.Context, invoice string,
13391340

13401341
if err == nil {
13411342
// TODO: Use structured payment error when available,
1342-
// instead of this britle string matching.
1343+
// instead of this brittle string matching.
13431344
switch payResp.PaymentError {
1344-
13451345
// Paid successfully.
13461346
case PaymentResultSuccess:
13471347
log.Infof(

lightning_client_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ func TestLightningClientAddInvoice(t *testing.T) {
8181

8282
validAddInvoice := func(in *lnrpc.Invoice, opts ...grpc.CallOption) (
8383
*lnrpc.AddInvoiceResponse, error) {
84+
8485
return validResp, nil
8586
}
8687

8788
errorAddInvoice := func(in *lnrpc.Invoice, opts ...grpc.CallOption) (
8889
*lnrpc.AddInvoiceResponse, error) {
90+
8991
return nil, errors.New("error")
9092
}
9193

lnd_services_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import (
55
"errors"
66
"testing"
77

8-
"google.golang.org/grpc"
9-
108
"github.com/lightningnetwork/lnd/lnrpc"
11-
129
"github.com/lightningnetwork/lnd/lnrpc/verrpc"
1310
"github.com/stretchr/testify/require"
11+
"google.golang.org/grpc"
1412
"google.golang.org/grpc/codes"
1513
"google.golang.org/grpc/status"
1614
)

router_client.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ func (r *routerClient) SendPayment(ctx context.Context,
398398

399399
if request.KeySend {
400400
if request.PaymentHash != nil {
401-
return nil, nil, fmt.Errorf(
402-
"keysend payment must not include a preset payment hash")
401+
return nil, nil, fmt.Errorf("keysend payment must not " +
402+
"include a preset payment hash")
403403
}
404404

405405
var preimage lntypes.Preimage
@@ -484,7 +484,6 @@ func (r *routerClient) trackPayment(ctx context.Context,
484484
}
485485

486486
switch status.Convert(err).Code() {
487-
488487
// NotFound is only expected as a response to
489488
// TrackPayment.
490489
case codes.NotFound:
@@ -674,10 +673,10 @@ func (r *routerClient) SubscribeHtlcEvents(ctx context.Context) (
674673
// must be thread-safe.
675674
//
676675
// There are a few ways in which this method can exit:
677-
// - ctx canceled: the calling client cancels
678-
// - r.quit: the router is shut down
679-
// - lnd stream error: lnd has exited
680-
// - handler error: a critical error occurred while handing a htlc
676+
// - ctx canceled: the calling client cancels.
677+
// - r.quit: the router is shut down.
678+
// - lnd stream error: lnd has exited.
679+
// - handler error: a critical error occurred while handing a htlc.
681680
func (r *routerClient) InterceptHtlcs(ctx context.Context,
682681
handler HtlcInterceptHandler) error {
683682

tools/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM golang:1.18.5-buster
2+
3+
RUN apt-get update && apt-get install -y git
4+
ENV GOCACHE=/tmp/build/.cache
5+
ENV GOMODCACHE=/tmp/build/.modcache
6+
7+
COPY . /tmp/tools
8+
9+
RUN cd /tmp \
10+
&& mkdir -p /tmp/build/.cache \
11+
&& mkdir -p /tmp/build/.modcache \
12+
&& cd /tmp/tools \
13+
&& go install -trimpath -tags=tools github.com/golangci/golangci-lint/cmd/golangci-lint \
14+
&& chmod -R 777 /tmp/build/
15+
16+
WORKDIR /build

0 commit comments

Comments
 (0)