Skip to content

Commit f0bf930

Browse files
committed
make: dockerize linter
1 parent 1741896 commit f0bf930

File tree

7 files changed

+1615
-16
lines changed

7 files changed

+1615
-16
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: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DEFAULT_GOAL := build
22

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

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

@@ -16,18 +17,20 @@ DEV_TAGS = dev
1617
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
1718
GOLIST := go list $(PKG)/... | grep -v '/vendor/'
1819

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
2520
XARGS := xargs -L 1
2621

2722
TEST_FLAGS = -test.timeout=20m
2823

2924
UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS)
3025

26+
# Linting uses a lot of memory, so keep it under control by limiting the number
27+
# of workers if requested.
28+
ifneq ($(workers),)
29+
LINT_WORKERS = --concurrency=$(workers)
30+
endif
31+
32+
DOCKER_TOOLS = docker run -v $$(pwd):/build loop-tools
33+
3134
GREEN := "\\033[0;32m"
3235
NC := "\\033[0m"
3336
define print
@@ -46,9 +49,13 @@ fmt:
4649
@$(call print, "Formatting source.")
4750
gofmt -l -w -s $(GOFILES_NOVENDOR)
4851

49-
lint: $(LINT_BIN)
52+
lint: docker-tools
5053
@$(call print, "Linting source.")
51-
$(LINT)
54+
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
55+
56+
docker-tools:
57+
@$(call print, "Building tools docker image.")
58+
docker build -q -t loop-tools $(TOOLS_DIR)
5259

5360
mod-tidy:
5461
@$(call print, "Tidying modules.")

loopd/swapclient_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func (s *swapClientServer) Monitor(in *clientrpc.MonitorRequest,
314314
}
315315

316316
// Concatenate both sets.
317-
filteredSwaps := append(pendingSwaps, completedSwaps...)
317+
filteredSwaps := append(pendingSwaps, completedSwaps...) // nolint: gocritic
318318

319319
// Sort again, but this time old to new.
320320
sort.Slice(filteredSwaps, func(i, j int) bool {

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.0-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

tools/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/lightninglabs/loop/tools
2+
3+
go 1.16
4+
5+
require github.com/golangci/golangci-lint v1.46.2 // indirect

0 commit comments

Comments
 (0)