feat: add contextcheck and depguard linters#8
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enhances code quality by adding two linters to catch common issues in distributed systems: contextcheck for proper context propagation and depguard to prevent usage of deprecated packages. The changes include enabling the linters in .golangci.yaml and addressing existing violations with nolint directives and code improvements.
Changes:
- Added
contextcheckanddepguardlinters to improve context propagation and prevent deprecated package usage - Fixed context handling in
pkg/serializer/http.goby removing unnecessary nil context fallback - Added nolint directives with explanatory comments for intentional context.Background() usage in cleanup/shutdown scenarios
- Configured depguard to ban
io/ioutil(deprecated since Go 1.16) andmath/rand(recommending v2 or crypto/rand)
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
.golangci.yaml |
Added contextcheck and depguard linters with configuration to ban deprecated packages (io/ioutil, math/rand) |
pkg/serializer/http.go |
Removed unnecessary nil context fallback check and updated documentation to require non-nil context |
pkg/server/server.go |
Added nolint directive for intentional context.Background() usage during graceful shutdown |
pkg/snapshotter/agent.go |
Added nolint directive for intentional context.Background() usage during cleanup |
pkg/cli/recipe.go |
Added TODO and nolint directive for LoadCriteriaFromFile which doesn't support context yet |
Contributor
Coverage Report ✅
Coverage Badge |
Enable two additional linters to improve code quality: - contextcheck: Ensures functions that accept context.Context actually propagate it. Critical for distributed systems to handle cancellation, timeouts, and request-scoped values correctly. All NVIDIA Go repos enable this linter. - depguard: Bans deprecated packages (io/ioutil since Go 1.16, math/rand in favor of math/rand/v2 or crypto/rand). Prevents new code from using APIs scheduled for removal. Fixed existing contextcheck violations: - pkg/server: Added nolint for intentional context.Background() during shutdown (parent context is already canceled) - pkg/snapshotter: Added nolint for intentional context.Background() during cleanup (need fresh context for cleanup operations) - pkg/serializer: Removed unnecessary nil context fallback - pkg/cli: Added TODO for future context support in LoadCriteriaFromFile Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: Davanum Srinivas <[email protected]>
Remove the nolint:contextcheck directive from ReadWithContext as it was unnecessary - the context is properly propagated to NewRequestWithContext. Addresses review feedback from Copilot. Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: Davanum Srinivas <[email protected]>
4f863e6 to
d132e37
Compare
Contributor
|
This pull request has been automatically locked since it has been closed for 90 days with no further activity. Please open a new pull request for related changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enable two additional linters to improve code quality and catch common issues:
contextcheck: Ensures functions that accept
context.Contextactually propagate it. Critical for distributed systems to handle cancellation, timeouts, and request-scoped values correctly. All NVIDIA Go repos enable this linter.depguard: Bans deprecated packages to prevent new code from using APIs scheduled for removal:
io/ioutil(deprecated since Go 1.16, useioandospackages)math/rand(usemath/rand/v2orcrypto/randfor security)Changes
.golangci.yaml: Addedcontextcheckanddepguardlinters with appropriate settingspkg/server: nolint for intentionalcontext.Background()during shutdownpkg/snapshotter: nolint for intentionalcontext.Background()during cleanuppkg/serializer: Removed unnecessary nil context fallbackpkg/cli: Added TODO for future context support inLoadCriteriaFromFileTest plan
make lint-gopasses (0 issues)make testpasses (73.5% coverage)Risk Assessment
Low - Adds stricter linting rules; existing code violations addressed with appropriate nolint directives and explanatory comments.
🤖 Generated with Claude Code