Skip to content

feat: add golangci-lint configuration with additional linters - #1936

Merged
TerryHowe merged 5 commits into
oras-project:mainfrom
bupd:goci
Dec 26, 2025
Merged

TerryHowe merged 5 commits into
oras-project:mainfrom
bupd:goci

Conversation

@bupd

@bupd bupd commented Dec 10, 2025

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

  • Add comprehensive golangci-lint configuration with additional linters
  • Add goheader linter to enforce license headers in source files
  • Fix lint issues across the codebase

Which issue(s) this PR fixes
Fixes #1935

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

@codecov

codecov Bot commented Dec 10, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.26087% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.14%. Comparing base (a72bcf9) to head (f88cc1b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/oras/internal/errors/errors.go 66.66% 1 Missing and 1 partial ⚠️
cmd/oras/internal/option/remote.go 33.33% 2 Missing ⚠️
internal/tree/printer.go 0.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (78.26%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1936      +/-   ##
==========================================
- Coverage   87.29%   87.14%   -0.16%     
==========================================
  Files         143      143              
  Lines        5535     5540       +5     
==========================================
- Hits         4832     4828       -4     
- Misses        417      425       +8     
- Partials      286      287       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would have been better to enable a few related linters at a time

@TerryHowe

Copy link
Copy Markdown
Member

Conflict here needs to be resolved. I think we could ignore codecov for this type of work.

@bupd

bupd commented Dec 17, 2025

Copy link
Copy Markdown
Contributor Author

@TerryHowe fixed conflicts. since there are some go antipatterns in code its necessary to have these linters to improve the overall code quality.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@TerryHowe

Copy link
Copy Markdown
Member

I think we should ignore codecov here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds comprehensive golangci-lint configuration with 11 additional linters and fixes all lint violations across the codebase. The changes include critical bug fixes, improved error handling patterns, resource leak prevention, and code quality improvements.

Key changes:

  • Enables additional linters: bodyclose, copyloopvar, errorlint, gosec, nilerr, nilnil, noctx, unconvert, unparam, whitespace, and usetesting
  • Fixes a critical bug in tree printer where errors were silently ignored
  • Modernizes error handling using errors.Is and errors.As for better error chain handling
  • Prevents resource leaks by closing HTTP response bodies in tests

Reviewed changes

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

Show a summary per file
File Description
.golangci.yml Adds 11 new linters with appropriate gosec exclusions for project-specific needs
internal/tree/printer.go Fixes bug where recursive print errors were silently ignored (returned nil instead of err)
internal/trace/transport.go Uses errors.Is for io.EOF comparison to properly handle wrapped errors
internal/progress/tracker.go Uses errors.Is for io.EOF comparison in error handling logic
internal/progress/tracker_test.go Updates error comparisons to use errors.Is for more robust error checking
internal/mock/repository.go Removes trailing blank line (whitespace linter)
internal/io/tar_utils_test.go Adds io.LimitReader to prevent unbounded memory consumption in tests (noctx linter)
internal/io/io_test.go Uses errors.Is for io.EOF comparison
internal/crypto/certificate_test.go Closes HTTP response bodies to prevent resource leaks (bodyclose linter)
internal/credential/store_test.go Removes trailing blank line (whitespace linter)
internal/cache/target_test.go Removes unnecessary []byte conversion (unconvert linter)
cmd/oras/root/tag.go Uses errors.As instead of type assertion for safer error type checking (errorlint)
cmd/oras/root/manifest/index/update.go Renames unused parameter to _ (unparam linter)
cmd/oras/root/manifest/index/create.go Adds nolint directives for intentional (nil, nil) returns and splits error handling logic for clarity
cmd/oras/root/cp_test.go Uses errors.Is for error comparisons and removes trailing blank lines
cmd/oras/root/cp.go Renames unused parameter to _ (unparam linter)
cmd/oras/root/backup_test.go Uses errors.Is for error comparisons and removes trailing blank line
cmd/oras/root/attach.go Uses errors.As instead of type assertion (errorlint)
cmd/oras/internal/option/target_test.go Uses errors.As for safer type assertions and removes trailing blank lines
cmd/oras/internal/option/remote_test.go Closes HTTP response bodies and removes trailing blank lines
cmd/oras/internal/option/remote.go Uses errors.Is for error chain checking, renames unused parameter, and fixes format verb to %w
cmd/oras/internal/errors/errors_test.go Uses errors.Is for error comparison
cmd/oras/internal/errors/errors.go Refactors type switches to use errors.As for better error handling (errorlint)
cmd/oras/internal/display/status/tty_test.go Uses errors.Is for error comparisons
cmd/oras/internal/display/status/progress/status_test.go Uses errors.Is for error comparison in helper function
cmd/oras/internal/display/status/console/console_test.go Removes trailing blank line

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@TerryHowe
TerryHowe merged commit a808bec into oras-project:main Dec 26, 2025
@TerryHowe

Copy link
Copy Markdown
Member

Thanks!

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.

Expand golangci-lint configuration with additional linters

3 participants