Skip to content

Conversation

seanlaii
Copy link
Contributor

@seanlaii seanlaii commented Aug 29, 2025

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:

  • Enhanced Code Quality: Access to newer, more intelligent linters and security checks.
  • Improved Go Compatibility: Ensures full compatibility with the latest Go versions (e.g., Go 1.24) and language features.
  • Bug Fixes & Performance: Leverages numerous bug fixes and performance improvements from the golangci-lint team.
  • Dependency Hygiene: Keeps our developer toolchain modern and secure.
  • Configuration Alignment: As part of the major version upgrade, the linting configurations (.golangci.yml) have been reviewed and adjusted to account for deprecated linters and enable new, valuable checks by using golangci-lint migrate.

Key changes include:

Separation of Linters and Formatters: gofmt, goimports, and gci have been moved from the linters.enable list to the new top-level formatters.enable section, reflecting their primary role. Their settings are now under formatters.settings.
Merge of the Linters: staticcheck, stylecheck, and gosimple 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

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • This PR is not tested :(

@seanlaii seanlaii changed the title Upgrade golangci-lint to v2.4.0 and adjust linting configurations [Chore] Upgrade golangci-lint to v2.4.0 and adjust linting configurations Aug 29, 2025
Copy link
Contributor Author

@seanlaii seanlaii left a 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
Copy link
Contributor Author

@seanlaii seanlaii Aug 29, 2025

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
Copy link
Contributor Author

@seanlaii seanlaii Aug 29, 2025

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
Copy link
Contributor Author

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)
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant