feat(lint): audit golangci-lint config and fix all issues#413
Conversation
- Add new linters: testifylint, usestdlibvars, fatcontext, intrange, dupword, err113 - Create static error definitions in cli/errors.go, middlewares/errors.go, and extend core/errors.go for err113 compliance - Fix testifylint issues (go-require, require-error patterns) - Fix intrange issues (Go 1.22+ range syntax) - Add comprehensive test file exclusions for practical linting: errcheck, dupl, errorlint, gocritic, predeclared, staticcheck, unparam - Configure goconst min-occurrences: 5 to avoid struct tag false positives - Add paralleltest/tparallel exclusions for integration and mutation tests Linter results: 0 issues Test results: All passing
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
There was a problem hiding this comment.
Pull request overview
This PR comprehensively audits and updates the golangci-lint configuration, enabling 6 new linters and fixing all surfacing issues across 66 files. The changes enforce Go best practices including static error definitions (err113), stdlib constants (usestdlibvars), and Go 1.22+ integer range syntax (intrange).
Key Changes:
- Enabled 6 new linters: testifylint, usestdlibvars, fatcontext, intrange, dupword, err113
- Created static error definitions in 3 new files for err113 compliance
- Replaced 100+ hardcoded HTTP method strings with
http.Method*constants - Converted traditional for loops to Go 1.22 integer range syntax (
for range n) - Improved testify assertions (e.g.,
assert.Error→require.Error,assert.Equal→assert.JSONEqfor JSON) - Enhanced error handling with
errors.Is/errors.Aspatterns - Removed unused code and struct fields
- Added comprehensive test file linting exclusions for practical development
Reviewed changes
Copilot reviewed 66 out of 66 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
.golangci.yml |
Added 6 new linters, configured goconst min-occurrences to 5, added extensive test file exclusions for paralleltest/tparallel |
cli/errors.go |
New file with 15 static validation error definitions for CLI |
middlewares/errors.go |
New file with 23 static error definitions for presets, webhooks, and security |
core/errors.go |
Extended with 24 new static errors for validation, scheduler, shutdown, resilience, and Docker SDK |
web/server_test.go |
Replaced all "GET"/"POST" strings with http.MethodGet/http.MethodPost (20+ occurrences) |
web/middleware_test.go |
Applied usestdlibvars and intrange fixes |
web/health_test.go |
Applied usestdlibvars fixes |
web/auth_integration_test.go |
Applied usestdlibvars fixes, added proper import grouping |
middlewares/webhook_test.go |
Changed assert.Error to require.Error for proper test flow |
middlewares/webhook_config_test.go |
Fixed testifylint issue with swapped expected/actual arguments |
middlewares/slack.go |
Replaced 200 with http.StatusOK constant |
middlewares/preset_test.go |
Changed assert.Equal to assert.JSONEq for JSON comparison, assert.Error to require.Error |
middlewares/preset_github_test.go |
Changed assert.Error to require.Error |
middlewares/preset_cache_test.go |
Applied intrange fixes, removed unused goroutine parameter |
middlewares/mail_test.go |
Fixed goroutine error handling by capturing errors in variables and checking after goroutine completion |
middlewares/dedup_test.go |
Applied intrange fixes, changed assert.Len to assert.Empty, added helpful comment about assert vs require in goroutines |
middlewares/errors.go |
New static error definitions file |
metrics/prometheus_test.go |
Applied usestdlibvars and intrange fixes |
metrics/prometheus.go |
Removed redundant nolint comment |
logging/structured_test.go |
Applied intrange fixes |
core/workflow.go |
Wrapped errors with static definitions using %w |
core/shutdown.go |
Replaced dynamic errors with static definitions, renamed errors variable to shutdownErrors to avoid shadowing |
core/scheduler_*.go |
Applied intrange fixes throughout scheduler tests |
core/scheduler.go |
Wrapped errors with static definitions |
core/runservice.go |
Replaced dynamic error with ErrImageRequired |
core/runjob.go |
Replaced dynamic error with ErrImageOrContainer |
core/resilient_job.go |
Wrapped error with ErrRateLimitExceeded |
core/resilience.go |
Replaced all dynamic errors in circuit breaker, rate limiter, and bulkhead with static definitions |
core/localjob.go |
Replaced dynamic error with ErrEmptyCommand |
core/docker_sdk_provider.go |
Replaced dynamic errors with static ErrResponseChannelClosed |
core/cron_utils.go |
Applied intrange fix |
core/common.go |
Applied intrange fixes, wrapped errors with ErrUnsupportedFieldType |
core/buffer_pool*.go |
Applied intrange fixes across buffer pool code and tests |
core/adapters/docker/convert_test.go |
Changed method name from Cancelled() to Canceled(), fixed error comparison to use errors.Is |
core/adapters/docker/auth_test.go |
Replaced octal file permissions with 0o600 notation |
core/adapters/mock/client_test.go |
Applied intrange fixes, removed unused goroutine parameter |
config/validator.go |
Applied intrange fix |
config/sanitizer_test.go |
Added t.Parallel() to all tests and subtests |
config/sanitizer_mutation_test.go |
Added t.Parallel() to all tests and subtests |
config/command_validator_test.go |
Added t.Parallel() to all tests, applied intrange fixes in benchmarks |
config/command_validator_mutation_test.go |
Added t.Parallel() to all tests and subtests |
cli/progress_test.go |
Applied intrange fixes |
cli/errors.go |
New file with 15 static validation error definitions |
cli/docker_handler_test.go |
Changed assert.Equal to assert.Len/assert.Empty, assert.NotNil to assert.Error/require.Error, fixed comment spelling (cancelled → canceled) |
cli/docker_handler_shutdown_test.go |
Fixed comment spelling (cancelled → canceled) |
cli/daemon_test.go |
Added errors import, fixed context error checks to use errors.Is |
cli/daemon_lifecycle_test.go |
Changed assert.Error to require.Error |
cli/daemon.go |
Added errors import, fixed http.ErrServerClosed check to use errors.Is |
cli/config_webhook_integration_test.go |
Removed unused containsString helper function |
cli/config_test.go |
Removed unused toJSON helper function, improved assertions with assert.Empty/assert.Len |
cli/config_parsing_test.go |
Simplified else-if structure |
cli/config_extra_test.go |
Improved error assertions, changed assert.Equal to assert.Len/assert.Empty |
cli/config_execjob_init_test.go |
Changed assert.Equal to assert.Empty |
cli/config_dependencies_test.go |
Simplified nil/empty checks by removing redundant nil checks |
test/testutil/eventually_test.go |
Removed unused errors []string field from mockTB struct |
core/common_test.go |
Changed assert.NotNil to require.Error |
core/common_extra3_test.go |
Applied intrange fix |
core/localjob_test.go |
Changed error type assertion to use errors.As |
core/localjob_comprehensive_test.go |
Simplified else-if structure, applied intrange fix |
core/missing_coverage_test.go |
Simplified else-if structure |
core/regression_test.go |
Applied intrange fix |
core/performance_metrics_integration_test.go |
Applied intrange fixes |
core/runjob_simple_test.go |
Applied intrange fixes, updated error message expectation |
core/resilience_test.go |
Fixed error comparisons to use errors.Is, applied intrange fixes |
core/scheduler_concurrency_test.go |
Added errors import, fixed ErrEmptySchedule check to use errors.Is, applied intrange fixes |
core/scheduler_concurrency_benchmark_test.go |
Applied intrange fixes throughout benchmarks |
- Revert Cancelled() to British spelling (Docker SDK compatibility) - Fix inverted logic in localjob_test.go (errors.As check)
469db0d to
68b2cf0
Compare
## Summary Updates CHANGELOG.md with release notes for v0.17.0 including: - **Secure Web Authentication** (#408) - **Doctor Command Enhancements** (#408) - **ntfy-token Preset** (#409) - **Webhook Host Whitelist** (#410) - **CronClock Interface** (#412) - **Cookie Security Hardening** (#411) - **GitHub Actions Pinning** (#411) - **Test Infrastructure Improvements** (#412) - **Performance Optimizations** (#412) - **Linting Audit** (#413) ## Test Plan - [x] Changelog follows Keep a Changelog format - [x] All PR references are correct - [x] Date is correct (2025-12-22)
|
🚀 Released in v0.17.0 Thank you for your contribution! 🙏 This is now available in the latest release. Please test and verify everything works as expected in your environment. If you encounter any issues, please open a new issue. |
Summary
Changes
New Linters Added
Static Error Definitions
cli/errors.go- Validation errors for CLImiddlewares/errors.go- Preset, webhook, and security errorscore/errors.gowith scheduler, shutdown, resilience errorsTest File Exclusions
Relaxed linting for test files (practical trade-off):
Configuration
Test plan
golangci-lint run→ 0 issuesgo test ./...→ All passinggo test ./... -tags=integration,e2e→ All passingMetrics