Skip to content

Commit

Permalink
[ci] Replace golint and gofmt by golangci-lint (kubernetes#1860)
Browse files Browse the repository at this point in the history
Because golint is deprecated we need to replace it by something else.
golangci-lint seems like a good fit, because it supports a wide viarity
of lintes/checkers. It is also possible to use golangci-lint in IDEs,
VS Code for example includes it by default (while it needs to be enabled).
  • Loading branch information
chrigl authored May 17, 2022
1 parent 8e56242 commit 4f0b050
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 183 deletions.
14 changes: 14 additions & 0 deletions .golangci-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
run:
timeout: 10m0s
linters:
disable:
- megacheck
- ineffassign
- structcheck
- errcheck
- deadcode
- varcheck
enable:
- gofmt
output:
format: line-number
7 changes: 7 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
run:
timeout: 10m0s
linters:
enable:
- gofmt
output:
format: line-number
28 changes: 13 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export TESTARGS ?= $(TESTARGS_DEFAULT)
PKG := $(shell awk '/^module/ { print $$2 }' go.mod)
DEST := $(GOPATH)/src/$(GIT_HOST)/$(BASE_DIR)
SOURCES := $(shell find $(DEST) -name '*.go' 2>/dev/null)
HAS_LINT := $(shell command -v golint;)
HAS_GOX := $(shell command -v gox;)
GOX_PARALLEL ?= 3

Expand Down Expand Up @@ -155,7 +154,14 @@ build-cmd-%: work $(SOURCES)

test: unit functional

check: work fmt vet lint
check: work
go run github.com/golangci/golangci-lint/cmd/[email protected] run ./... --config .golangci-check.yaml

# NOTE(chrigl): ci actually runs make check. Because golint didn't run on the code for quite some
# time, most linters in make check are disabled. codehygiene serves as a helper to further
# improve the quality of the code base.
codeclimate: work
go run github.com/golangci/golangci-lint/cmd/[email protected] run ./...

unit: work
go test -tags=unit $(shell go list ./... | sed -e '/sanity/ { N; d; }' | sed -e '/tests/ {N; d;}') $(TESTARGS)
Expand All @@ -169,18 +175,10 @@ test-cinder-csi-sanity: work
test-manila-csi-sanity: work
go test $(GIT_HOST)/$(BASE_DIR)/tests/sanity/manila

fmt:
hack/verify-gofmt.sh

lint:
ifndef HAS_LINT
echo "installing lint"
go install golang.org/x/lint/golint@latest
endif
hack/verify-golint.sh

vet:
go vet ./...
# kept for compatibility reasons.
fmt: check
lint: check
vet: check

cover: work
go test -tags=unit $(shell go list ./...) -cover
Expand Down Expand Up @@ -326,4 +324,4 @@ dist: build-cross
)

.PHONY: bindep build clean cover work docs fmt functional lint realclean \
relnotes test translation version build-cross dist
relnotes test translation version build-cross dist codeclimate
Empty file removed hack/.golint_failures
Empty file.
2 changes: 1 addition & 1 deletion hack/update-gofmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ set -o errexit
set -o nounset
set -o pipefail

find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -w
find . -name "*.go" | grep -v "\/vendor\/\|\.\/\.go" | xargs gofmt -s -w
35 changes: 0 additions & 35 deletions hack/verify-gofmt.sh

This file was deleted.

132 changes: 0 additions & 132 deletions hack/verify-golint.sh

This file was deleted.

0 comments on commit 4f0b050

Please sign in to comment.