-
Notifications
You must be signed in to change notification settings - Fork 620
[Chore] Upgrade golangci-lint to v2.4.0 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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: wei-chenglai <[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.
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
.
Why are these changes needed?
This pull request upgrades golangci-lint from an outdated version (
v1.64.8
) to a recent major version (v2.4.0
). The primary motivations for this upgrade are:Key changes include:
Separation of Linters and Formatters:
gofmt
,goimports
, andgci
have been moved from thelinters.enable
list to the new top-levelformatters.enable
section, reflecting their primary role. Their settings are now underformatters.settings
.Merge of the Linters:
staticcheck
,stylecheck
, andgosimple
are 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
Checks