-
Notifications
You must be signed in to change notification settings - Fork 680
[Chore] Upgrade golangci-lint to v2.7.2 and adjust linting configurations #4007
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
Conversation
07b155b to
d2a85d9
Compare
seanlaii
left a comment
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.
Provide the details of the change to the golangci.yml.
Migration guide: https://golangci-lint.run/docs/product/migration-guide/
| - unused | ||
| - wastedassign | ||
| - testifylint | ||
| disable-all: true |
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.
Change disable-all to
linters:
default: none
according to https://golangci-lint.run/docs/product/migration-guide/#lintersdisable-all.
| - predeclared | ||
| - revive | ||
| - staticcheck | ||
| - typecheck |
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.
typecheck is now enabled by default and cannot be disabled: https://golangci-lint.run/docs/product/migration-guide/#typecheck
| require-explanation: true | ||
| require-specific: true | ||
| revive: | ||
| ignore-generated-header: true |
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.
According to https://golangci-lint.run/docs/product/migration-guide/#linters-settingsreviveignore-generated-header, change it to:
linters:
exclusions:
generated: strict
| .PHONY: lint | ||
| lint: golangci-lint fmt vet fumpt imports ## Run the linter. | ||
| # exclude the SA1019 check which checks the usage of deprecated fields. | ||
| test -s $(GOLANGCI_LINT) || ($(GOLANGCI_LINT) run --timeout=3m --exclude='SA1019' --no-config --allow-parallel-runners) |
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.
--exclude is removed according to https://golangci-lint.run/docs/product/migration-guide/#command-line-flags; therefore, I add it in the golangci.yml.
| for dir in $dirs_to_lint; do | ||
| pushd "$dir" | ||
| # exclude the SA1019 check which checks the usage of deprecated fields. | ||
| golangci-lint run --fix --exclude-files _generated.go --exclude='SA1019' --timeout 10m0s |
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.
Added it via linters.exclusions.paths in golangci.yml.
|
Hi @seanlaii , I'm wondering if there's any updates on this PR? I think it's required for golang version bump up, thanks! |
Got it. Thanks for the info! Will work on it today. |
Signed-off-by: wei-chenglai <[email protected]>
d2a85d9 to
8d4a650
Compare
|
Hi @Future-Outlier @rueian , please help take a look at this PR when you have a chance to unblock the golang version bump and the lint/format issue fix. Thanks! |
00a5a36 to
b36b08b
Compare
thank you for pinging me, will make this PR this week's priority. |
Future-Outlier
left a comment
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.
Thank you!
Future-Outlier
left a comment
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.
cc @win5923 to help if you have time, thank you!
win5923
left a comment
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.
Thanks for your hard work!
| lint: golangci-lint fmt vet ## Run the linter. | ||
| # exclude the SA1019 check which checks the usage of deprecated fields. | ||
| test -s $(GOLANGCI_LINT) || ($(GOLANGCI_LINT) run --timeout=3m --exclude='SA1019' --no-config --allow-parallel-runners) | ||
| test -s $(GOLANGCI_LINT) || ($(GOLANGCI_LINT) run --timeout=3m --allow-parallel-runners) |
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.
Not sure if there’s a specific reason for using --no-config?
cc @rueian
d1aa29f to
39b8409
Compare
Future-Outlier
left a comment
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.
cc @rueian to merge, thank you!
6db3919 to
177e3a0
Compare
Why are these changes needed?
golangci-lint v1 is no longer maintained and has reached end-of-life. To ensure code robustness and continue following Go best practices, we need to upgrade to golangci-lint v2.
This PR focuses on the configuration migration to unblock the upgrade
Follow-up work - The lint errors surfaced by these disabled linters will be addressed in subsequent PRs. These follow-up tasks are well-scoped and can be picked up by other contributors to parallelize the effort. The tasks are created in #4008.
Key changes include
Separation of Linters and Formatters:
gofmt,goimports, andgcihave been moved from thelinters.enablelist to the new top-levelformatters.enablesection, reflecting their primary role. Their settings are now underformatters.settings.Merge of the Linters:
staticcheck,stylecheck, andgosimpleare merged into one linter,staticcheck.Crucially, all custom configurations (
gocyclo,gci,goimports) and specific path exclusions have been preserved and migrated to the new v2.0 schema. This upgrade ensures we leverage the latest improvements and features of golangci-lint while maintaining our established code quality standards.For more details on the changes in v2.0, please refer to the official migration guide: https://golangci-lint.run/product/migration-guide/
Related issue number
Part of #4008
Checks