-
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
Conversation
Signed-off-by: Albert Teoh <[email protected]>
Signed-off-by: Albert Teoh <[email protected]>
Signed-off-by: Albert Teoh <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #3237 +/- ##
==========================================
- Coverage 95.99% 95.95% -0.05%
==========================================
Files 242 242
Lines 14813 14813
==========================================
- Hits 14220 14214 -6
- Misses 514 519 +5
- Partials 79 80 +1
Continue to review full report at Codecov.
|
Signed-off-by: Albert Teoh <[email protected]>
Signed-off-by: Albert Teoh <[email protected]>
healthCheckHTTPPort = "health-check-http-port" | ||
adminHTTPPort = "admin-http-port" |
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.
Unused and deprecated here.
"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 comment
The 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 //nolint
directive. Tests appear to still be passing with this change.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
golint
, go vet
and gosec
should no longer be needed as golangci-lint provides these linters, so I'm removing them from the Makefile to simplify.
- G104 | ||
- G107 |
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.
- G404 | ||
- G601 |
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 not excluded in the Makefile, but were identified, giving the errors:
cmd/collector/app/sanitizer/cache/auto_refresh_cache.go:136:40: G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec)
return (interval / 2) + time.Duration(rand.Int63n(int64(interval/2)))
^
crossdock/services/tracehandler.go:308:27: G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec)
return fmt.Sprintf("%x", rand.Int63())
^
cmd/ingester/app/processor/decorator/retry.go:54:18: G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec)
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
^
model/converter/thrift/jaeger/from_domain.go:106:37: G601: Implicit memory aliasing in for loop. (gosec)
jaegerTags[idx] = d.keyValueToTag(&kv)
^
cmd/anonymizer/main.go:72:22: G601: Implicit memory aliasing in for loop. (gosec)
writer.WriteSpan(&span)
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 comment
The reason will be displayed to describe this comment to others. Learn more.
let's fix them in another PR
.github/workflows/ci-unit-tests.yml
Outdated
@@ -22,9 +22,15 @@ jobs: | |||
- name: Run unit tests | |||
run: make test-ci | |||
|
|||
- name: golangci-lint |
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.
I ended up placing the lint step within the unit-tests, which is similar behaviour to the Makefile. However, I feel it would be nicer as a separate job in order to enable concurrency, but am getting errors relating to undefined types. Oddly, testing on my fork doesn't have this issue.
I believe it's the same config as is with #2602 and does not appear to have encountered this problem. Maybe @daxmc99 has some ideas about this?
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.
It might be worth noting that (I think) those "undefined" errors could be due to not having run go build
on jaeger, which explains why moving this step as part of the unit tests job works.
$(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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, I've added this back into the lint
target. Tested by removing the license from grpc_handler.go
:
$ make lint
golangci-lint run
./scripts/updateLicenses.sh > .fmt.log
License check failures, run 'make fmt'
cmd/collector/app/handler/grpc_handler.go
make: *** [lint] Error 1
Makefile
Outdated
|
||
.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 comment
The 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 comment
The 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 comment
The 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 test-ci
target will run the lint
target. Fewer changes, and cleaner.
Signed-off-by: Albert Teoh <[email protected]>
Signed-off-by: Albert Teoh <[email protected]>
Signed-off-by: Albert Teoh <[email protected]>
Signed-off-by: Albert Teoh <[email protected]>
go install github.com/mjibson/esc | ||
go install github.com/securego/gosec/cmd/gosec | ||
go install honnef.co/go/tools/cmd/staticcheck | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] |
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.
Add this to the tools so CI is able to run golangci-lint, and ensure devs also have the right tools installed to test linting.
- G404 | ||
- G601 | ||
gosimple: | ||
go: "1.17" |
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.
Bumped the go version since we've moved onto 1.17 already.
Please let me know if there are any issues that still need addressing. |
Makefile
Outdated
@echo Running go lint... | ||
@$(GOLINT) $(ALL_PKGS) | grep -v _nolint.go >> $(LINT_LOG) || true; | ||
@[ ! -s "$(LINT_LOG)" ] || (echo "Lint Failures" | cat - $(LINT_LOG) && false) | ||
@[ ! -s "$(FMT_LOG)" -a ! -s "$(IMPORT_LOG)" ] || (echo "License check or import ordering failures, run 'make fmt'" | cat - $(FMT_LOG) && false) |
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.
This does not print import_log
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.
Addressed in 8b3a050
Signed-off-by: Albert Teoh <[email protected]>
cb4e345
to
8b3a050
Compare
- G404 | ||
- G601 |
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.
let's fix them in another PR
thanks for the review Yuri/Pavol! 🙏🏼 |
Which problem is this PR solving?
Short description of the changes