Skip to content

Commit 6d1708d

Browse files
authored
Merge pull request #496 from sputn1ck/dockerize_linter
Dockerize linter, add gosimports
2 parents 1741896 + a34f22c commit 6d1708d

27 files changed

+1676
-64
lines changed

.golangci.yml

Lines changed: 96 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,134 @@ run:
22
# timeout for analysis
33
deadline: 4m
44

5-
# Linting uses a lot of memory. Keep it under control by only running a single
6-
# worker.
7-
concurrency: 1
5+
skip-files:
6+
- "\\.pb\\.go$"
7+
- "\\.pb\\.gw\\.go$"
88

99
linters-settings:
10+
govet:
11+
# Don't report about shadowed variables
12+
check-shadowing: false
13+
1014
gofmt:
1115
# simplify code: gofmt with `-s` option, true by default
1216
simplify: true
1317

18+
tagliatelle:
19+
case:
20+
rules:
21+
json: snake
22+
23+
whitespace:
24+
multi-func: true
25+
multi-if: true
26+
27+
gosec:
28+
excludes:
29+
- G402 # Look for bad TLS connection settings.
30+
- G306 # Poor file permissions used when writing to a new file.
31+
32+
staticcheck:
33+
go: "1.18"
34+
checks: ["-SA1019"]
35+
1436
linters:
1537
enable-all: true
1638
disable:
17-
# Global variables are used in many places throughout the code base.
39+
# Global variables are used in many places throughout the code base.
1840
- gochecknoglobals
1941

2042
# Some lines are over 80 characters on purpose and we don't want to make them
2143
# even longer by marking them as 'nolint'.
2244
- lll
2345

24-
# We don't care (enough) about misaligned structs to lint that.
25-
- maligned
46+
# We want to allow short variable names.
47+
- varnamelen
48+
49+
# We want to allow TODOs.
50+
- godox
2651

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

3156
# Disable for now as we haven't yet tuned the sensitivity to our codebase
32-
# yet. Enabling by default for example, would also force new contributors to
57+
# yet. Enabling by default for example, would also force new contributors to
3358
# potentially extensively refactor code, when they want to smaller change to
3459
# land.
3560
- gocyclo
61+
- gocognit
62+
- cyclop
3663

3764
# Instances of table driven tests that don't pre-allocate shouldn't trigger
3865
# the linter.
3966
- prealloc
4067

4168
# Init functions are used by loggers throughout the codebase.
4269
- gochecknoinits
70+
71+
# Causes stack overflow, see https://github.com/polyfloyd/go-errorlint/issues/19.
72+
- errorlint
73+
74+
# Deprecated linters. See https://golangci-lint.run/usage/linters/.
75+
- interfacer
76+
- golint
77+
- maligned
78+
- scopelint
79+
80+
# New linters that need a code adjustment first.
81+
- wrapcheck
82+
- nolintlint
83+
- paralleltest
84+
- tparallel
85+
- testpackage
86+
- gofumpt
87+
- gomoddirectives
88+
- ireturn
89+
- maintidx
90+
- nlreturn
91+
- dogsled
92+
- gci
93+
- containedctx
94+
- contextcheck
95+
- errname
96+
- exhaustivestruct
97+
- goerr113
98+
- gomnd
99+
- ifshort
100+
- noctx
101+
- nestif
102+
- wsl
103+
- exhaustive
104+
- forcetypeassert
105+
- nilerr
106+
- nilnil
107+
- stylecheck
108+
- thelper
109+
110+
# Additions compared to LND
111+
- exhaustruct
43112

44113
issues:
45114
# Only show newly introduced problems.
46115
new-from-rev: 36838cf7f464cf73b0201798063b2caffeae4250
116+
117+
exclude-rules:
118+
119+
# Allow fmt.Printf() in test files
120+
- path: _test\.go
121+
linters:
122+
- forbidigo
123+
124+
# Allow fmt.Printf() in loopd
125+
- path: cmd/loopd/*
126+
linters:
127+
- forbidigo
128+
- path: loopd/*
129+
linters:
130+
- forbidigo
131+
132+
# Allow fmt.Printf() in loop
133+
- path: cmd/loop/*
134+
linters:
135+
- forbidigo

Makefile

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
.DEFAULT_GOAL := build
22

33
PKG := github.com/lightninglabs/loop
4+
TOOLS_DIR := tools
45

56
GOTEST := GO111MODULE=on go test -v
67

8+
9+
GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
10+
711
GO_BIN := ${GOPATH}/bin
12+
GOIMPORTS_BIN := $(GO_BIN)/gosimports
13+
814
GOBUILD := GO111MODULE=on go build -v
915
GOINSTALL := GO111MODULE=on go install -v
1016
GOMOD := GO111MODULE=on go mod
@@ -13,51 +19,37 @@ COMMIT := $(shell git describe --abbrev=40 --dirty)
1319
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT)"
1420
DEV_TAGS = dev
1521

16-
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
22+
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -name "*pb.go" -not -name "*pb.gw.go" -not -name "*.pb.json.go")
1723
GOLIST := go list $(PKG)/... | grep -v '/vendor/'
1824

19-
LINT_BIN := $(GO_BIN)/golangci-lint
20-
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
21-
LINT_COMMIT := v1.18.0
22-
LINT = $(LINT_BIN) run -v
23-
24-
DEPGET := cd /tmp && GO111MODULE=on go get -v
2525
XARGS := xargs -L 1
2626

2727
TEST_FLAGS = -test.timeout=20m
2828

2929
UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS)
3030

31+
# Linting uses a lot of memory, so keep it under control by limiting the number
32+
# of workers if requested.
33+
ifneq ($(workers),)
34+
LINT_WORKERS = --concurrency=$(workers)
35+
endif
36+
37+
DOCKER_TOOLS = docker run -v $$(pwd):/build loop-tools
38+
3139
GREEN := "\\033[0;32m"
3240
NC := "\\033[0m"
3341
define print
3442
echo $(GREEN)$1$(NC)
3543
endef
3644

37-
$(LINT_BIN):
38-
@$(call print, "Fetching linter")
39-
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
40-
41-
unit:
42-
@$(call print, "Running unit tests.")
43-
$(UNIT)
44-
45-
fmt:
46-
@$(call print, "Formatting source.")
47-
gofmt -l -w -s $(GOFILES_NOVENDOR)
48-
49-
lint: $(LINT_BIN)
50-
@$(call print, "Linting source.")
51-
$(LINT)
45+
# ============
46+
# DEPENDENCIES
47+
# ============
5248

53-
mod-tidy:
54-
@$(call print, "Tidying modules.")
55-
$(GOMOD) tidy
49+
$(GOIMPORTS_BIN):
50+
@$(call print, "Installing goimports.")
51+
cd $(TOOLS_DIR); go install -trimpath $(GOIMPORTS_PKG)
5652

57-
mod-check:
58-
@$(call print, "Checking modules.")
59-
$(GOMOD) tidy
60-
if test -n "$$(git status | grep -e "go.mod\|go.sum")"; then echo "Running go mod tidy changes go.mod/go.sum"; git status; git diff; exit 1; fi
6153

6254
# ============
6355
# INSTALLATION
@@ -94,3 +86,40 @@ clean:
9486
@$(call print, "Cleaning up.")
9587
rm -f ./loop-debug ./loopd-debug
9688
rm -rf ./vendor
89+
90+
# =======
91+
# TESTING
92+
# =======
93+
94+
unit:
95+
@$(call print, "Running unit tests.")
96+
$(UNIT)
97+
98+
# =========
99+
# UTILITIES
100+
# =========
101+
102+
fmt: $(GOIMPORTS_BIN)
103+
@$(call print, "Fixing imports.")
104+
gosimports -w $(GOFILES_NOVENDOR)
105+
@$(call print, "Formatting source.")
106+
gofmt -l -w -s $(GOFILES_NOVENDOR)
107+
108+
lint: docker-tools
109+
@$(call print, "Linting source.")
110+
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
111+
112+
docker-tools:
113+
@$(call print, "Building tools docker image.")
114+
docker build -q -t loop-tools $(TOOLS_DIR)
115+
116+
mod-tidy:
117+
@$(call print, "Tidying modules.")
118+
$(GOMOD) tidy
119+
120+
mod-check:
121+
@$(call print, "Checking modules.")
122+
$(GOMOD) tidy
123+
if test -n "$$(git status | grep -e "go.mod\|go.sum")"; then echo "Running go mod tidy changes go.mod/go.sum"; git status; git diff; exit 1; fi
124+
125+

cmd/loop/liquidity.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,6 @@ func setParams(ctx *cli.Context) error {
476476
// so that it does not need to be manually updated.
477477
case categoriesSet:
478478
params.FeePpm = 0
479-
480479
}
481480
// Update our parameters to our mutated values.
482481
_, err = client.SetLiquidityParams(

cmd/loop/loopout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func loopOut(ctx *cli.Context) error {
161161
}
162162

163163
// Show a warning if a slow swap was requested.
164-
warning := ""
164+
var warning string
165165
if fast {
166166
warning = "Fast swap requested."
167167
} else {

cmd/loop/lsat.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func listAuth(ctx *cli.Context) error {
4949

5050
tokens := make([]*printableToken, len(resp.Tokens))
5151
for i, t := range resp.Tokens {
52-
5352
mac := &macaroon.Macaroon{}
5453
err := mac.UnmarshalBinary(t.BaseMacaroon)
5554
if err != nil {

cmd/loop/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"time"
1313

14+
"github.com/btcsuite/btcd/btcutil"
1415
"github.com/lightninglabs/lndclient"
1516
"github.com/lightninglabs/loop"
1617
"github.com/lightninglabs/loop/loopd"
@@ -21,9 +22,6 @@ import (
2122
"github.com/lightninglabs/protobuf-hex-display/proto"
2223
"github.com/lightningnetwork/lnd/lncfg"
2324
"github.com/lightningnetwork/lnd/macaroons"
24-
25-
"github.com/btcsuite/btcd/btcutil"
26-
2725
"github.com/urfave/cli"
2826
"google.golang.org/grpc"
2927
"google.golang.org/grpc/credentials"

cmd/loop/swaps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func swapInfo(ctx *cli.Context) error {
6060
id = ctx.String("id")
6161
case ctx.NArg() > 0:
6262
id = args[0]
63-
args = args.Tail()
63+
args = args.Tail() // nolint:wastedassign
6464
default:
6565
// Show command help if no arguments and flags were provided.
6666
return cli.ShowCommandHelp(ctx, "swapinfo")

interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ type LoopInSwapInfo struct { // nolint
305305

306306
// LoopOutSwapInfo contains essential information of a loop-out swap after the
307307
// swap is initiated.
308-
type LoopOutSwapInfo struct { // nolint:golint
308+
type LoopOutSwapInfo struct { // nolint:revive
309309
// SwapHash contains the sha256 hash of the swap preimage.
310310
SwapHash lntypes.Hash
311311

liquidity/liquidity.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ func (p Parameters) String() string {
262262
ruleList = append(
263263
ruleList, fmt.Sprintf("Peer: %v: %v", peer, rule),
264264
)
265-
266265
}
267266

268267
return fmt.Sprintf("rules: %v, failure backoff: %v, sweep "+

liquidity/liquidity_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,6 @@ func TestSizeRestrictions(t *testing.T) {
14091409
Maximum: 6000,
14101410
}, nil,
14111411
).Once()
1412-
14131412
},
14141413
suggestions: nil,
14151414
expectedError: ErrMaxExceedsServer,
@@ -1582,7 +1581,6 @@ func TestFeePercentage(t *testing.T) {
15821581
error) {
15831582

15841583
return testCase.quote, nil
1585-
15861584
}
15871585

15881586
lnd.Channels = []lndclient.ChannelInfo{

0 commit comments

Comments
 (0)