-
Notifications
You must be signed in to change notification settings - Fork 243
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
Add additional checks to golangci-lint (#5567) #5687
Add additional checks to golangci-lint (#5567) #5687
Conversation
- revive is a drop-in replacement for the deprecated golint Linter - revive will allow to check for error strings Note: We are purposely not using the latest golangci-lint (1.45.0) but the minimum version from which revive is available. This is because the latest 1.45.0 reports additional linting issues (from govet and staticcheck for example). And fixing those side errors is outside of the scope of this issue. Also some of those issues are already fixed in redhat-developer#5497 (update to Go 1.17).
More rules can be added later on if needed
Some rules are purposely ignored when the error messages represent top-level errors that are displayed to be displayed as is to end users
For some reason, those were not reported by revive's error-strings rule, but only by GoLand inspection tool.
✅ Deploy Preview for odo-docusaurus-preview canceled.
|
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: kadel The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Also replace "fmt.Errorf" by "errors.New" when the error message is static
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
…t-developer#5687) * Document golangci-lint configuration options * Do not limit the number of issues reported per linter * Add check preventing the use of the deprecated 'github.com/pkg/errors' package * Upgrade golangci-lint to 1.37.0, so we can use 'revive' Linter - revive is a drop-in replacement for the deprecated golint Linter - revive will allow to check for error strings Note: We are purposely not using the latest golangci-lint (1.45.0) but the minimum version from which revive is available. This is because the latest 1.45.0 reports additional linting issues (from govet and staticcheck for example). And fixing those side errors is outside of the scope of this issue. Also some of those issues are already fixed in redhat-developer#5497 (update to Go 1.17). * Configure revive to check for error strings More rules can be added later on if needed * Fix issues reported by revive's error-strings rule Some rules are purposely ignored when the error messages represent top-level errors that are displayed to be displayed as is to end users * Fix more error-strings issues For some reason, those were not reported by revive's error-strings rule, but only by GoLand inspection tool. * Fix missing `revive:disable:error-strings` comment directive Also replace "fmt.Errorf" by "errors.New" when the error message is static
What type of PR is this:
/kind task
What does this PR do / why we need it:
This configures golangci-lint with the following additional checks:
depguard
, to check whether packages imported are allowed or denied. For example, this allows to check that the deprecatedgithub.com/pkg/errors
is not introduced again.revive
(successor of the deprecated golint), configured with the following rules:error-strings
, to check common conventions around error messages. This PR also fixes errors reported by this rule.Additional checks might be added later on as needed.
Which issue(s) this PR fixes:
Fixes #5567
PR acceptance criteria:
Unit test
Integration test
Documentation
How to test changes / Special notes to the reviewer:
make validate
and all tests should pass.