-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace old linters with golangci-lint #3237
Changes from 4 commits
1e67b6d
f591546
ceda4be
c5b8e2d
5fb5d53
7b1ab1c
39a4051
3c23f85
979b30b
1ba1aa3
4b102ba
8b3a050
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Run golangci-lint | ||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v2 | ||
with: | ||
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version | ||
version: v1.42 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
run: | ||
timeout: 10m | ||
skip-dirs: | ||
- swagger-gen | ||
- pkg/cassandra/mocks | ||
- storage/mocks | ||
- cmd/ingester/app/consumer/mocks | ||
|
||
linters-settings: | ||
gosec: | ||
# To specify a set of rules to explicitly exclude. | ||
# Available rules: https://github.com/securego/gosec#available-rules | ||
excludes: | ||
- G104 | ||
- G107 | ||
- G404 | ||
- G601 | ||
Comment on lines
+16
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These gosec rules were not excluded in the Makefile, but were identified, giving the errors:
I've excluded them for now, but if there is a preference to address these rules in this PR, I can do so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's fix them in another PR |
||
gosimple: | ||
go: "1.16" | ||
|
||
linters: | ||
enable: | ||
- gofmt | ||
- goimports | ||
- gosec | ||
- govet | ||
disable: | ||
- errcheck | ||
|
||
issues: | ||
# Excluding configuration per-path, per-linter, per-text and per-source | ||
exclude-rules: | ||
# Exclude some linters from running on tests files. | ||
- path: _test\.go | ||
linters: | ||
- gosec |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ ALL_SRC := $(shell find . -name '*.go' \ | |
-type f | \ | ||
sort) | ||
|
||
# ALL_PKGS is used with 'golint' | ||
# ALL_PKGS is used with 'nocover' | ||
ALL_PKGS := $(shell echo $(dir $(ALL_SRC)) | tr ' ' '\n' | sort -u) | ||
|
||
UNAME := $(shell uname -m) | ||
|
@@ -35,12 +35,7 @@ GOOS ?= $(shell go env GOOS) | |
GOARCH ?= $(shell go env GOARCH) | ||
GOBUILD=CGO_ENABLED=0 installsuffix=cgo go build -trimpath | ||
GOTEST=go test -v $(RACE) | ||
GOLINT=golint | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
GOVET=go vet | ||
GOFMT=gofmt | ||
FMT_LOG=.fmt.log | ||
LINT_LOG=.lint.log | ||
IMPORT_LOG=.import.log | ||
|
||
GIT_SHA=$(shell git rev-parse HEAD) | ||
GIT_CLOSEST_TAG=$(shell git describe --abbrev=0 --tags) | ||
|
@@ -82,7 +77,7 @@ go-gen: | |
|
||
.PHONY: clean | ||
clean: | ||
rm -rf cover.out .cover/ cover.html lint.log fmt.log \ | ||
rm -rf cover.out .cover/ cover.html \ | ||
jaeger-ui/packages/jaeger-ui/build | ||
|
||
.PHONY: test | ||
|
@@ -130,7 +125,6 @@ index-rollover-integration-test: docker-images-elastic | |
go clean -testcache | ||
bash -c "set -e; set -o pipefail; $(GOTEST) -tags index_rollover $(STORAGE_PKGS) | $(COLORIZE)" | ||
|
||
|
||
.PHONY: token-propagation-integration-test | ||
token-propagation-integration-test: | ||
go clean -testcache | ||
|
@@ -161,39 +155,9 @@ fmt: | |
@$(GOFMT) -e -s -l -w $(ALL_SRC) | ||
./scripts/updateLicenses.sh | ||
|
||
.PHONY: lint-gosec | ||
lint-gosec: | ||
time gosec -quiet -exclude=G104,G107 ./... | ||
|
||
.PHONY: lint-staticcheck | ||
lint-staticcheck: | ||
@cat /dev/null > $(LINT_LOG) | ||
time staticcheck ./... \ | ||
| grep -v \ | ||
-e model/model.pb.go \ | ||
-e proto-gen \ | ||
-e _test.pb.go \ | ||
-e thrift-gen/ \ | ||
-e swagger-gen/ \ | ||
>> $(LINT_LOG) || true | ||
@[ ! -s "$(LINT_LOG)" ] || (echo "Detected staticcheck failures:" | cat - $(LINT_LOG) && false) | ||
|
||
.PHONY: lint | ||
lint: lint-staticcheck lint-gosec | ||
$(GOVET) ./... | ||
$(MAKE) go-lint | ||
@echo Running go fmt on ALL_SRC ... | ||
@$(GOFMT) -e -s -l $(ALL_SRC) > $(FMT_LOG) | ||
./scripts/updateLicenses.sh >> $(FMT_LOG) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This must remain There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch, I've added this back into the
|
||
./scripts/import-order-cleanup.sh stdout > $(IMPORT_LOG) | ||
yurishkuro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@[ ! -s "$(FMT_LOG)" -a ! -s "$(IMPORT_LOG)" ] || (echo "Go fmt, license check, or import ordering failures, run 'make fmt'" | cat - $(FMT_LOG) && false) | ||
|
||
.PHONY: go-lint | ||
go-lint: | ||
@cat /dev/null > $(LINT_LOG) | ||
@echo Running go lint... | ||
@$(GOLINT) $(ALL_PKGS) | grep -v _nolint.go >> $(LINT_LOG) || true; | ||
@[ ! -s "$(LINT_LOG)" ] || (echo "Lint Failures" | cat - $(LINT_LOG) && false) | ||
lint: | ||
golangci-lint run | ||
|
||
.PHONY: build-examples | ||
build-examples: | ||
|
@@ -400,16 +364,13 @@ changelog: | |
.PHONY: install-tools | ||
install-tools: | ||
go install github.com/wadey/gocovmerge | ||
go install golang.org/x/lint/golint | ||
go install github.com/mjibson/esc | ||
go install github.com/securego/gosec/cmd/gosec | ||
go install honnef.co/go/tools/cmd/staticcheck | ||
|
||
.PHONY: install-ci | ||
install-ci: install-tools | ||
|
||
.PHONY: test-ci | ||
test-ci: build-examples lint cover | ||
test-ci: build-examples cover | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would consider killing this target and invoking directly in GA There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like a minimal CI configuration. I want to be able to easily replicate locally what CI is doing - e.g. run the same make target. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, I agree that it's a better developer experience if the CI scripts can be traced down to the make target then "replayed" locally, which a GA step doesn't afford. As such, I've removed the GA step to run golangci-lint and kept the original setup where the |
||
|
||
.PHONY: thrift | ||
thrift: idl/thrift/jaeger.thrift thrift-image | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,9 +32,7 @@ import ( | |
) | ||
|
||
const ( | ||
healthCheckHTTPPort = "health-check-http-port" | ||
adminHTTPPort = "admin-http-port" | ||
Comment on lines
-35
to
-36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused and deprecated here. |
||
adminHTTPHostPort = "admin.http.host-port" | ||
adminHTTPHostPort = "admin.http.host-port" | ||
) | ||
|
||
// AdminServer runs an HTTP server with admin endpoints, such as healthcheck at /, /metrics, etc. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,9 @@ package gogocodec | |
import ( | ||
"testing" | ||
|
||
"github.com/golang/protobuf/proto" //lint:ignore SA1019 deprecated package | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/protobuf/proto" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please let me know if there are issues with moving to "google.golang.org/protobuf/proto", and I can revert back and add a |
||
"google.golang.org/protobuf/types/known/emptypb" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These gosec rules were excluded in the Makefile, so I did the same.