Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 83e60a2

Browse files
author
Ian Campbell
committed
ci: Switch from gometalinter to golangci-lint
The former is deprecated in favour of the later, which is faster and less memory hungry. The `.golangci.yml` is a straight translation of the enabled linters and exclusions from `gometalinter.json`, except: - The exclusions of `specification/bindata.go` and `templateloader` no longer seem relevant (nothing hits, the latter no longer exists) so those are dropped. - I didn't copy over the various tweaks to output formats (the `sort` key) nor the deadline setting. - There is currently no equivalent to the `WarnUnmatchedDirective` key, see golangci/golangci-lint#404 - The `unparam` linter now catches a few things which it didn't before, these are fixed here: pkg/yatee/yatee.go:131:39: tokenize - result 1 (error) is always nil (unparam) func tokenize(expr string) ([]string, error) { ^ pkg/yatee/yatee_test.go:31:47: `testProcess` - `parameters` always receives `parameters` (`"\nfoo: bar\nloop: $loop\napp:\n mode: debug\n release: false\n co...`) (unparam) func testProcess(t *testing.T, input, output, parameters, error string) { ^ pkg/yatee/yatee_test.go:147:56: `testProcessWithOrder` - `error` is unused (unparam) func testProcessWithOrder(t *testing.T, input, output, error string) { ^ The first and third by dropping the unused return value and parameter respectively. For the middle one I marked as `nolint` since it makes sense to keep `parameters` defined in the caller since they are combined with `input` to produce `output` and it is useful to have them in the same context. The `nakedret` linter is part of `golangci-lint` already so there is no need to add it separately. Signed-off-by: Ian Campbell <ijc@docker.com>
1 parent 376c15d commit 83e60a2

6 files changed

Lines changed: 37 additions & 62 deletions

File tree

.golangci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
linters:
2+
enable-all: false
3+
disable-all: true
4+
enable:
5+
- deadcode
6+
- gocyclo
7+
- gofmt
8+
- goimports
9+
- golint
10+
- gosimple
11+
- ineffassign
12+
- interfacer
13+
- lll
14+
- misspell
15+
- nakedret
16+
- unconvert
17+
- unparam
18+
- unused
19+
- vet
20+
linters-settings:
21+
gocyclo:
22+
min-complexity: 16
23+
lll:
24+
line-length: 200

Dockerfile.lint

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,8 @@ RUN apk add --no-cache \
88
make \
99
coreutils
1010

11-
ENV GOMETALITER_VERSION=2.0.11
12-
ENV NAKEDRECT_SHA=c0e305a4f690fed163d47628bcc06a6d5655bf92
13-
14-
WORKDIR /go/src/github.com/alecthomas/gometalinter
15-
RUN curl -L https://github.com/alecthomas/gometalinter/archive/v${GOMETALITER_VERSION}.tar.gz | tar xz --strip-components=1 \
16-
&& go build -v -o /usr/local/bin/gometalinter . \
17-
&& gometalinter --install \
18-
&& rm -rf /go/src/* /go/pkg/*
19-
20-
WORKDIR /go/src/github.com/alexkohler/nakedret
21-
RUN git clone https://github.com/alexkohler/nakedret.git /go/src/github.com/alexkohler/nakedret \
22-
&& go build -v -o /usr/local/bin/nakedret . \
11+
RUN GO111MODULE=on go get \
12+
github.com/golangci/golangci-lint/cmd/golangci-lint@v1.16.0 \
2313
&& rm -rf /go/src/* /go/pkg/*
2414

2515
WORKDIR /go/src/github.com/docker/app

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ test: test-unit test-e2e ## run all tests
7373

7474
lint: ## run linter(s)
7575
@echo "Linting..."
76-
@gometalinter --config=gometalinter.json ./...
76+
@golangci-lint run ./...
7777

7878
test-e2e: bin/$(BIN_NAME) ## run end-to-end tests
7979
@echo "Running e2e tests..."

gometalinter.json

Lines changed: 0 additions & 39 deletions
This file was deleted.

pkg/yatee/yatee.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func extract(expr string) (string, error) {
128128
return expr[0:i], nil
129129
}
130130

131-
func tokenize(expr string) ([]string, error) {
131+
func tokenize(expr string) []string {
132132
var tokens []string
133133
p := 0
134134
for p < len(expr) {
@@ -145,7 +145,7 @@ func tokenize(expr string) ([]string, error) {
145145
p++
146146
}
147147
}
148-
return tokens, nil
148+
return tokens
149149
}
150150

151151
func evalValue(comps []string, i int) (int64, int, error) {
@@ -199,10 +199,7 @@ func evalSub(comps []string, i int) (int64, int, error) {
199199

200200
// resolves an arithmetic expression
201201
func evalExpr(expr string) (int64, error) {
202-
comps, err := tokenize(expr)
203-
if err != nil {
204-
return 0, err
205-
}
202+
comps := tokenize(expr)
206203
v, _, err := evalSub(comps, 0)
207204
return v, err
208205
}

pkg/yatee/yatee_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ func TestEval(t *testing.T) {
2828
testEval(t, "${foo?foo:bar}", env, "foo")
2929
}
3030

31-
func testProcess(t *testing.T, input, output, parameters, error string) {
31+
// The nolint is because `parameters` is always the same, but it is
32+
// preferable to keep the definition in the caller since it
33+
// corresponds to `input` and `output`.
34+
func testProcess(t *testing.T, input, output, parameters, error string) { //nolint:unparam
3235
ps := make(map[interface{}]interface{})
3336
err := yaml.Unmarshal([]byte(parameters), ps)
3437
assert.NilError(t, err)
@@ -144,7 +147,7 @@ ab:
144147
"eval loop detected")
145148
}
146149

147-
func testProcessWithOrder(t *testing.T, input, output, error string) {
150+
func testProcessWithOrder(t *testing.T, input, output string) {
148151
parameters := make(map[string]interface{})
149152

150153
res, err := ProcessWithOrder(input, parameters)
@@ -164,7 +167,7 @@ func TestProcessWithOrder(t *testing.T) {
164167
`, `parent:
165168
bb: true
166169
aa: false
167-
`, "")
170+
`)
168171

169172
// Test ordering is preserved at the top level
170173
testProcessWithOrder(t,
@@ -176,5 +179,5 @@ aaa:
176179
nested: true
177180
aaa:
178181
nested: false
179-
`, "")
182+
`)
180183
}

0 commit comments

Comments
 (0)