Skip to content

Conversation

ziggie1984
Copy link
Collaborator

@ziggie1984 ziggie1984 commented Sep 11, 2025

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:

  1. 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.

  2. 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.

  3. 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

  4. 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.

@ziggie1984 ziggie1984 self-assigned this Sep 11, 2025
@ziggie1984 ziggie1984 force-pushed the use-new-tools-feature branch 2 times, most recently from 1f0fd53 to b348eb9 Compare September 12, 2025 09:09
@ziggie1984 ziggie1984 added the CI continuous integration label Sep 12, 2025
@ziggie1984
Copy link
Collaborator Author

ziggie1984 commented Sep 12, 2025

The new linter now reports quite some things:

159 issues:
* embeddedstructfieldcheck: 6
* funcorder: 50
* mnd: 50
* noinlineerr: 3
* wsl_v5: 50

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:

  - embeddedstructfieldcheck (6 errors): New linter that checks for embedded struct field naming conventions
  - funcorder (50 errors): New linter that enforces function ordering within files
  - mnd (50 errors): New "magic number detector" - replaces the old gomnd linter with enhanced detection
  - noinlineerr (3 errors): New linter that prevents inline error creation (encourages predefined errors)
  - wsl_v5 (50 errors): Updated version of the whitespace linter with stricter rules

the mnd detector seems way more aggressive which is good.

@ziggie1984 ziggie1984 marked this pull request as ready for review September 12, 2025 12:32
@ziggie1984 ziggie1984 force-pushed the use-new-tools-feature branch from d8c31f5 to 2177662 Compare September 12, 2025 12:49
@hieblmi
Copy link
Collaborator

hieblmi commented Sep 12, 2025

The new linter now reports quite some things:

could try using golangci-lint run --fix to fix some of them.

@ziggie1984 ziggie1984 force-pushed the use-new-tools-feature branch from 1317acd to 72286c1 Compare September 12, 2025 14:11
@ziggie1984
Copy link
Collaborator Author

could try using golangci-lint run --fix to fix some of them.

tried that, but it then changes like 800 files ...

@ziggie1984 ziggie1984 force-pushed the use-new-tools-feature branch from 72286c1 to a36d14b Compare September 12, 2025 17:10
@ziggie1984 ziggie1984 requested a review from Roasbeef September 12, 2025 17:12
@ziggie1984 ziggie1984 added this to the v0.20.0 milestone Sep 12, 2025
@ziggie1984 ziggie1984 requested a review from starius September 12, 2025 17:27
Copy link
Collaborator

@starius starius left a 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
Comment on lines 2 to 3
# 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).
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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
Copy link
Member

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

Copy link
Collaborator Author

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
Comment on lines 2 to 3
# 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).
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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.

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.
@ziggie1984
Copy link
Collaborator Author

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)
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI continuous integration no-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants