Skip to content

feat(lint): audit golangci-lint config and fix all issues#413

Merged
CybotTM merged 4 commits intomainfrom
feat/golangci-lint-audit
Dec 20, 2025
Merged

feat(lint): audit golangci-lint config and fix all issues#413
CybotTM merged 4 commits intomainfrom
feat/golangci-lint-audit

Conversation

@CybotTM
Copy link
Member

@CybotTM CybotTM commented Dec 20, 2025

Summary

  • Add new linters: testifylint, usestdlibvars, fatcontext, intrange, dupword, err113
  • Create static error definitions for err113 compliance (cli/errors.go, middlewares/errors.go, core/errors.go)
  • Fix all surfacing linter issues (100+ issues → 0)
  • Add comprehensive test file exclusions for practical linting

Changes

New Linters Added

Linter Purpose
testifylint Enforce testify best practices
usestdlibvars Use stdlib constants (http.MethodGet, etc.)
fatcontext Detect context.Context in structs
intrange Go 1.22+ integer range syntax
dupword Detect duplicate words in comments
err113 Require static error definitions

Static Error Definitions

  • cli/errors.go - Validation errors for CLI
  • middlewares/errors.go - Preset, webhook, and security errors
  • Extended core/errors.go with scheduler, shutdown, resilience errors

Test File Exclusions

Relaxed linting for test files (practical trade-off):

  • errcheck, dupl, errorlint, gocritic, predeclared, staticcheck, unparam

Configuration

  • goconst min-occurrences: 5 (avoids struct tag false positives)
  • paralleltest/tparallel exclusions for integration/mutation tests

Test plan

  • golangci-lint run → 0 issues
  • go test ./... → All passing
  • go test ./... -tags=integration,e2e → All passing

Metrics

Metric Value
Files changed 66
Linter (uncached) 11.5s
Unit tests 2.3s
All tests (integration+e2e) 25s

- 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
Copilot AI review requested due to automatic review settings December 20, 2025 15:51
@github-actions
Copy link

github-actions bot commented Dec 20, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions
Copy link

⚠️ Mutation Testing Results

Mutation Score: 0.00% (threshold: 60%)

⚠️ Score is below threshold. Consider improving test coverage or test quality.

What is mutation testing?

Mutation testing measures test quality by introducing small changes (mutations) to the code and checking if tests detect them. A higher score means better test effectiveness.

  • Killed mutants: Tests caught the mutation (good!)
  • Survived mutants: Tests missed the mutation (needs improvement)

Copy link

Copilot AI left a comment

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 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.Errorrequire.Error, assert.Equalassert.JSONEq for JSON)
  • Enhanced error handling with errors.Is/errors.As patterns
  • 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)
@CybotTM CybotTM force-pushed the feat/golangci-lint-audit branch from 469db0d to 68b2cf0 Compare December 20, 2025 18:03
@CybotTM CybotTM added this pull request to the merge queue Dec 20, 2025
Merged via the queue into main with commit 234fbd3 Dec 20, 2025
27 checks passed
@CybotTM CybotTM deleted the feat/golangci-lint-audit branch December 20, 2025 18:13
github-merge-queue bot pushed a commit that referenced this pull request Dec 22, 2025
## 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)
@CybotTM CybotTM added the released:v0.17.0 Included in v0.17.0 release label Dec 22, 2025
@CybotTM
Copy link
Member Author

CybotTM commented Dec 22, 2025

🚀 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released:v0.17.0 Included in v0.17.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants