-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Use golangs new tool feature #10209
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
base: master
Are you sure you want to change the base?
Use golangs new tool feature #10209
Conversation
1f0fd53
to
b348eb9
Compare
The new linter now reports quite some things:
will update the hash so that we will start using the new linter rules form now on. Acutally all the new issues are new linters:
the mnd detector seems way more aggressive which is good. |
d8c31f5
to
2177662
Compare
could try using |
1317acd
to
72286c1
Compare
tried that, but it then changes like 800 files ... |
72286c1
to
a36d14b
Compare
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.
LGTM! 🔗
Great update! I have some comments.
.golangci.yml
Outdated
# If you change this please also update GO_VERSION in Makefile (then run | ||
# `make lint` to see where else it needs to be updated as well). |
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.
The comments were removed by the migration. I propose to restore them in new version.
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.
When doing the migration in other repos i asked AI to copy over the comments from the old config to the appropriate places in the new config. That worked well.
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.
Agrew we should re-add these.
The general spacing/room also make the old file easier to parse.
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.
updated
.github/workflows/main.yml
Outdated
@@ -546,7 +546,7 @@ jobs: | |||
fail-fast: false | |||
matrix: | |||
pinned_dep: | |||
- google.golang.org/grpc v1.70.0 | |||
- google.golang.org/grpc v1.75.0 |
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.
Could it be upgraded to v1.75.0 in "CI: udpate pinned grpc check to 1.70.0"? Then we could skip this commit.
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.
no updates required now.
.golangci.yml
Outdated
@@ -159,7 +159,7 @@ linters: | |||
- builtin$ | |||
- examples$ | |||
issues: | |||
new-from-rev: 03eab4db64540aa5f789c617793e4459f4ba9e78 | |||
new-from-rev: 5082566ed7193215d0a7620e5faf3a37323bce92 |
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 add a TODO to inspect later what is there? Maybe it found some bugs. Or maybe we can disable some noisy useless linters and majority of findings go away.
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.
+1
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.
After we land this, we can make a new PR that remove this, to see what all the flagged violations are.
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.
kept the normal hash and instead inspected the problems, I put the new linters in disable mode because they were not really helpful:
# Disable function order linter because we structure exported and unexported
# functions differently.
- funcorder
# Disable noinlineerr linter because we use it to inline errors.
- noinlineerr
# Disable embeddedstructfieldcheck linter because we use it to align
# structs. Because sometimes we have atomic fields that need to be aligned
# with means we need to assure that the field is at the beginning of the
# struct.
- embeddedstructfieldcheck
go.mod
Outdated
@@ -22,7 +22,7 @@ require ( | |||
github.com/gorilla/websocket v1.5.0 | |||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 | |||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 | |||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 | |||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 |
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.
Shouldn't this commit be squashed? IIUC, cross-compilation fails without it.
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.
no relevant anymore
kvdb/go.mod
Outdated
go.etcd.io/etcd/client/v3 v3.5.12 | ||
go.etcd.io/etcd/server/v3 v3.5.12 | ||
github.com/stretchr/testify v1.11.1 | ||
go.etcd.io/bbolt v1.4.2 |
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 is notable as we're updating bbolt, looks like they've fixed a series of bugs and are starting to release more regularly: https://github.com/etcd-io/bbolt/blob/main/CHANGELOG/CHANGELOG-1.4.md
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.
will update in a separate PR.
.golangci.yml
Outdated
# If you change this please also update GO_VERSION in Makefile (then run | ||
# `make lint` to see where else it needs to be updated as well). |
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.
Agrew we should re-add these.
The general spacing/room also make the old file easier to parse.
.golangci.yml
Outdated
@@ -159,7 +159,7 @@ linters: | |||
- builtin$ | |||
- examples$ | |||
issues: | |||
new-from-rev: 03eab4db64540aa5f789c617793e4459f4ba9e78 | |||
new-from-rev: 5082566ed7193215d0a7620e5faf3a37323bce92 |
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.
After we land this, we can make a new PR that remove this, to see what all the flagged violations are.
kvdb/go.mod
Outdated
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect | ||
modernc.org/libc v1.49.3 // indirect | ||
modernc.org/mathutil v1.6.0 // indirect | ||
modernc.org/memory v1.8.0 // indirect | ||
modernc.org/strutil v1.2.0 // indirect | ||
modernc.org/token v1.1.0 // indirect | ||
sigs.k8s.io/yaml v1.2.0 // indirect | ||
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect | ||
sigs.k8s.io/yaml v1.4.0 // indirect |
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.
For this to build properly in the PR, we'll need to add a top level replace. That'll ensure that the check commits pass also works properly.
a36d14b
to
a6afcc0
Compare
The config file format changed. The tool golangci-lint migrate was used to migrate the old config. However old comments and also the structure of the disabled linters was preserved.
3a8d25f
to
6891ded
Compare
changed the approach to keep the tools separation. |
@$(call print, "Fixing imports.") | ||
gosimports -w $(GOFILES_NOVENDOR) | ||
$(GOCC) tool --modfile $(TOOLS_MOD) $(GOIMPORTS_PKG) -w $(GOFILES_NOVENDOR) |
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 line will break the go.work
,
> make lint
Linting source.
go tool --modfile ./tools/go.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint run -v
go: -modfile cannot be used in workspace mode
make: *** [lint] Error 1
We can now handle tool dependencies directly with the go tool
directive rather than using the extra tools.go pattern.
To update the golint version it becomes as easy as:
go get -tool github.com/golangci/golangci-lint/cmd/[email protected]
in the main LND dir.This PR does the following things:
It updates the tooling for our linter so that we use the go tool available in the new golang 1.24 toolchain. This updated also the GRPC library which meant that I need to first bump the grpc source files via
make rpc
to the newest version.The second step of this PR is that it updates the linter to the new golangci-lint v2. The config file was migrated using the tool they offer with the new linter (
./custom-gcl migrate
, I built the linter via :go tool github.com/golangci/golangci-lint/v2/cmd/golangci-lint custom
a) I had to change some linters because they are not really supported anymore as a consequence
b) I also had to update the kvdb libary because it was somehow not able to lint and pull the sources of the nested module because the modul was not compiling => the reason was that importing the tools into the main go.mod cause some dependencies which made the etcd kvdb module not compile anymore so needed to update the etcd version.
Based on the linter v2 change the GRPC dependecy changed again to 1.73 so I built the gprc golang files again and updated the dependency
Finally the linter succeeded but there are now new 159 issues (posted above) which need to be resolved. To avoid changing them I updated the hash in the linter config so that legacy issues are not caught.