Skip to content

feat: add contextcheck and depguard linters#8

Merged
dims merged 2 commits into
NVIDIA:mainfrom
dims:feat/add-context-dep-linters
Feb 1, 2026
Merged

feat: add contextcheck and depguard linters#8
dims merged 2 commits into
NVIDIA:mainfrom
dims:feat/add-context-dep-linters

Conversation

@dims

@dims dims commented Feb 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Enable two additional linters to improve code quality and catch common issues:

  • 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 to prevent new code from using APIs scheduled for removal:

    • io/ioutil (deprecated since Go 1.16, use io and os packages)
    • math/rand (use math/rand/v2 or crypto/rand for security)

Changes

  • .golangci.yaml: Added contextcheck and depguard linters with appropriate settings
  • Fixed existing contextcheck violations:
    • pkg/server: nolint for intentional context.Background() during shutdown
    • pkg/snapshotter: nolint for intentional context.Background() during cleanup
    • pkg/serializer: Removed unnecessary nil context fallback
    • pkg/cli: Added TODO for future context support in LoadCriteriaFromFile

Test plan

  • make lint-go passes (0 issues)
  • make test passes (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

Copilot AI review requested due to automatic review settings February 1, 2026 00:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 contextcheck and depguard linters to improve context propagation and prevent deprecated package usage
  • Fixed context handling in pkg/serializer/http.go by 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) and math/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

Comment thread pkg/serializer/http.go Outdated
@github-actions

github-actions Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

Coverage Report ✅

Metric Value
Coverage 73.7%
Threshold 70%
Status Pass
Coverage Badge
![Coverage](https://img.shields.io/badge/coverage-73.7%25-green)

dims and others added 2 commits January 31, 2026 20:27
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]>
Copilot AI review requested due to automatic review settings February 1, 2026 01:27
@dims dims force-pushed the feat/add-context-dep-linters branch from 4f863e6 to d132e37 Compare February 1, 2026 01:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@dims dims merged commit a3ba46d into NVIDIA:main Feb 1, 2026
9 checks passed
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
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.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants