Skip to content

style: enable modernize analyzer#5231

Open
chuanshanjida wants to merge 7 commits intoava-labs:masterfrom
chuanshanjida:master
Open

style: enable modernize analyzer#5231
chuanshanjida wants to merge 7 commits intoava-labs:masterfrom
chuanshanjida:master

Conversation

@chuanshanjida
Copy link
Copy Markdown

Why this should be merged

Enables the modernize linter in .golangci.yml to enforce idiomatic modern. Go patterns, such as using built-in min/max, the slices/maps packages, and. other improvements introduced in recent Go versions.

How this works

How this was tested

Need to be documented in RELEASES.md?

Signed-off-by: chuanshanjida <chuanshanjida@outlook.com>
@JonathanOppenheimer
Copy link
Copy Markdown
Contributor

JonathanOppenheimer commented Apr 13, 2026

@chuanshanjida CI does not pass here.

Signed-off-by: chuanshanjida <chuanshanjida@outlook.com>
@chuanshanjida
Copy link
Copy Markdown
Author

@chuanshanjida CI does not pass here.

Modified.
Hi @JonathanOppenheimer Please approve the CI.

@JonathanOppenheimer
Copy link
Copy Markdown
Contributor

@chuanshanjida CI does not pass here.

Modified.

Hi @JonathanOppenheimer Please approve the CI.

Hi @chuanshanjida. It appears that CI still does not pass. You can use task to run the tests locally before pushing.

@chuanshanjida chuanshanjida requested a review from a team as a code owner April 14, 2026 11:39
@chuanshanjida
Copy link
Copy Markdown
Author

@chuanshanjida CI does not pass here.

Modified.
Hi @JonathanOppenheimer Please approve the CI.

Hi @chuanshanjida. It appears that CI still does not pass. You can use task to run the tests locally before pushing.

I’ve already made the changes and tested locally. The reason the lint failed is that for a few third-party projects under the graft directory, the modernize operation wasn’t executed.

I’ve already run it now (but I’m thinking about whether we should exclude the graft directory from modernize, since these are third-party projects—should we modify their code?).

@chuanshanjida
Copy link
Copy Markdown
Author

image image image

@JonathanOppenheimer
Copy link
Copy Markdown
Contributor

@chuanshanjida CI does not pass here.

Modified.

Hi @JonathanOppenheimer Please approve the CI.

Hi @chuanshanjida. It appears that CI still does not pass. You can use task to run the tests locally before pushing.

I’ve already made the changes and tested locally. The reason the lint failed is that for a few third-party projects under the graft directory, the modernize operation wasn’t executed.

I’ve already run it now (but I’m thinking about whether we should exclude the graft directory from modernize, since these are third-party projects—should we modify their code?).

You have good intuitions! There's a lot of geth code inside of graft that should not be linted, and in fact we have a specific linter and separate .golangci.yml for those projects.

So yeah, we should not be applying the modernize linter to the graft subdirectory.

If you want to be more specific we should not be applying it to upstream files, as listed in the text document. There is some code in graft/ that is our own. Does this make sense?

Signed-off-by: chuanshanjida <chuanshanjida@outlook.com>
@chuanshanjida
Copy link
Copy Markdown
Author

You have good intuitions! There's a lot of geth code inside of graft that should not be linted, and in fact we have a specific linter and separate .golangci.yml for those projects.

So yeah, we should not be applying the modernize linter to the graft subdirectory.

If you want to be more specific we should not be applying it to upstream files, as listed in the text document. There is some code in graft/ that is our own. Does this make sense?

I think it’s like that~ I’ve already updated my .golangci.yml to exclude the graft directory. Also, do I need to squash several commits into one?

@JonathanOppenheimer
Copy link
Copy Markdown
Contributor

You have good intuitions! There's a lot of geth code inside of graft that should not be linted, and in fact we have a specific linter and separate .golangci.yml for those projects.
So yeah, we should not be applying the modernize linter to the graft subdirectory.
If you want to be more specific we should not be applying it to upstream files, as listed in the text document. There is some code in graft/ that is our own. Does this make sense?

I think it’s like that~ I’ve already updated my .golangci.yml to exclude the graft directory. Also, do I need to squash several commits into one?

The PR will be auto-squashed when merged so no. Regarding the CI, it still does not pass CI, so I don't believe you've configured it correctly.

Signed-off-by: chuanshanjida <chuanshanjida@outlook.com>
@chuanshanjida
Copy link
Copy Markdown
Author

chuanshanjida commented Apr 14, 2026

You have good intuitions! There's a lot of geth code inside of graft that should not be linted, and in fact we have a specific linter and separate .golangci.yml for those projects.
So yeah, we should not be applying the modernize linter to the graft subdirectory.
If you want to be more specific we should not be applying it to upstream files, as listed in the text document. There is some code in graft/ that is our own. Does this make sense?

I think it’s like that~ I’ve already updated my .golangci.yml to exclude the graft directory. Also, do I need to squash several commits into one?

The PR will be auto-squashed when merged so no. Regarding the CI, it still does not pass CI, so I don't believe you've configured it correctly.

Thanks for the guidance! Here's what I did:

The avalanche_golangci_lint task runs golangci-lint with the root .golangci.yml config from within each graft module directory, but only against Avalanche-authored files (those excluded from upstream_files.txt via ! prefixes). So enabling modernize in the root config only affects those files — upstream geth code is untouched.

I ran modernize -fix on the Avalanche-authored files across graft/coreth, graft/subnet-evm, and graft/evm, and only staged those changes. The upstream files that were also touched by the auto-fix tool have been reverted, since they're not our code to modify and aren't checked by avalanche_golangci_lint anyway.

Also fixed a test regression in node/beacon_manager_test.go where the auto-fix incorrectly compared an atomic.Int64 struct directly instead of calling .Load().

@JonathanOppenheimer
Copy link
Copy Markdown
Contributor

This is getting a lot closer! Can you resolve the conflict?

@chuanshanjida
Copy link
Copy Markdown
Author

This is getting a lot closer! Can you resolve the conflict?

Sure—please wait a minute. It looks like the changes are a bit too big. I’m doing git fetch upstream, but it’s running quite slowly.

image

@JonathanOppenheimer
Copy link
Copy Markdown
Contributor

This is getting a lot closer! Can you resolve the conflict?

Sure—please wait a minute. It looks like the changes are a bit too big. I’m doing git fetch upstream, but it’s running quite slowly.

image

sorry about that, we just added a lot of code to the codebase.

@chuanshanjida
Copy link
Copy Markdown
Author

This is getting a lot closer! Can you resolve the conflict?

Finally fetched successfully—haha😄. The conflicts are resolved. Please approve the CI again. @JonathanOppenheimer

@JonathanOppenheimer
Copy link
Copy Markdown
Contributor

This is getting a lot closer! Can you resolve the conflict?

Finally fetched successfully—haha😄. The conflicts are resolved. Please approve the CI again. @JonathanOppenheimer

Still not passing :(. Let me know if you're having any trouble.

@chuanshanjida
Copy link
Copy Markdown
Author

chuanshanjida commented Apr 20, 2026

This is getting a lot closer! Can you resolve the conflict?

Finally fetched successfully—haha😄. The conflicts are resolved. Please approve the CI again. @JonathanOppenheimer

Still not passing :(. Let me know if you're having any trouble.

Haha. We’re only one step away from success. This is a very easy error to fix.

Error: evm/utils/bounded_workers.go:34:34: unnecessary leading newline (whitespace)
	b.outstandingWorkers.Go(func() {
	                                ^
1 issues:
* whitespace: 1
FAIL: 'golangci_lint' failed at Wed Apr 15 09:02:44 UTC 2026
task: Failed to run task "lint-all-ci": exit status 255
Error: Process completed with exit code 201.

Please approve the CI run again. I think there’s a good chance it will pass. @JonathanOppenheimer

@JonathanOppenheimer
Copy link
Copy Markdown
Contributor

Error: evm/utils/bounded_workers.go:34:34: unnecessary leading newline (whitespace)

Can you include the PR description how you generated this PR? How much was automatically generated by the --fix lint flag? What did you have to change manually?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants