Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
ci: Switch from gometalinter to golangci-lint
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Ian Campbell committed Apr 5, 2019
1 parent 376c15d commit 83e60a2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 62 deletions.
24 changes: 24 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
linters:
enable-all: false
disable-all: true
enable:
- deadcode
- gocyclo
- gofmt
- goimports
- golint
- gosimple
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- unconvert
- unparam
- unused
- vet
linters-settings:
gocyclo:
min-complexity: 16
lll:
line-length: 200
14 changes: 2 additions & 12 deletions Dockerfile.lint
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,8 @@ RUN apk add --no-cache \
make \
coreutils

ENV GOMETALITER_VERSION=2.0.11
ENV NAKEDRECT_SHA=c0e305a4f690fed163d47628bcc06a6d5655bf92

WORKDIR /go/src/github.com/alecthomas/gometalinter
RUN curl -L https://github.com/alecthomas/gometalinter/archive/v${GOMETALITER_VERSION}.tar.gz | tar xz --strip-components=1 \
&& go build -v -o /usr/local/bin/gometalinter . \
&& gometalinter --install \
&& rm -rf /go/src/* /go/pkg/*

WORKDIR /go/src/github.com/alexkohler/nakedret
RUN git clone https://github.com/alexkohler/nakedret.git /go/src/github.com/alexkohler/nakedret \
&& go build -v -o /usr/local/bin/nakedret . \
RUN GO111MODULE=on go get \
github.com/golangci/golangci-lint/cmd/[email protected] \
&& rm -rf /go/src/* /go/pkg/*

WORKDIR /go/src/github.com/docker/app
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test: test-unit test-e2e ## run all tests

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

test-e2e: bin/$(BIN_NAME) ## run end-to-end tests
@echo "Running e2e tests..."
Expand Down
39 changes: 0 additions & 39 deletions gometalinter.json

This file was deleted.

9 changes: 3 additions & 6 deletions pkg/yatee/yatee.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func extract(expr string) (string, error) {
return expr[0:i], nil
}

func tokenize(expr string) ([]string, error) {
func tokenize(expr string) []string {
var tokens []string
p := 0
for p < len(expr) {
Expand All @@ -145,7 +145,7 @@ func tokenize(expr string) ([]string, error) {
p++
}
}
return tokens, nil
return tokens
}

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

// resolves an arithmetic expression
func evalExpr(expr string) (int64, error) {
comps, err := tokenize(expr)
if err != nil {
return 0, err
}
comps := tokenize(expr)
v, _, err := evalSub(comps, 0)
return v, err
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/yatee/yatee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ func TestEval(t *testing.T) {
testEval(t, "${foo?foo:bar}", env, "foo")
}

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

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

res, err := ProcessWithOrder(input, parameters)
Expand All @@ -164,7 +167,7 @@ func TestProcessWithOrder(t *testing.T) {
`, `parent:
bb: true
aa: false
`, "")
`)

// Test ordering is preserved at the top level
testProcessWithOrder(t,
Expand All @@ -176,5 +179,5 @@ aaa:
nested: true
aaa:
nested: false
`, "")
`)
}

0 comments on commit 83e60a2

Please sign in to comment.