Skip to content

Migrate golangci-lint config to v2 and add new linters#272

Merged
orestisfl merged 6 commits intoelastic:mainfrom
orestisfl:golangci-lint-v2-migration
Dec 11, 2025
Merged

Migrate golangci-lint config to v2 and add new linters#272
orestisfl merged 6 commits intoelastic:mainfrom
orestisfl:golangci-lint-v2-migration

Conversation

@orestisfl
Copy link
Copy Markdown
Contributor

What does this PR do?

Migrate .golangci.yml to v2 format:

  • Update configuration schema to version 2
  • Move goimports to formatters section
  • Preserve all linter descriptions as comments

Fix linter issues:

  • Replace exec.Command with exec.CommandContext (noctx)
  • Update deprecated nolint directives (deadcode/structcheck -> unused)
  • Fix bug in util.go: sc.Err() check was wrapping wrong error variable (caught by nilnesserr linter)

Add new linters:

  • containedctx: detects struct contained context.Context field
  • contextcheck: checks whether function uses non-inherited context
  • exptostd: detects golang.org/x/exp functions replaceable by std
  • nilnesserr: reports err != nil checks returning different nil error
  • prealloc: finds slice declarations that could be pre-allocated
  • predeclared: finds code shadowing Go's predeclared identifiers
  • usetesting: detects uses replaceable by standard testing helpers

Auto-fixed issues from golangci-lint --fix across multiple files.

Why is it important?

bug fix, catch future bugs, developer productivity

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.md

Migrate .golangci.yml to v2 format:
- Update configuration schema to version 2
- Move goimports to formatters section
- Preserve all linter descriptions as comments

Fix linter issues:
- Replace exec.Command with exec.CommandContext (noctx)
- Update deprecated nolint directives (deadcode/structcheck -> unused)
- Fix bug in util.go: sc.Err() check was wrapping wrong error variable
  (caught by nilnesserr linter)

Add new linters:
- containedctx: detects struct contained context.Context field
- contextcheck: checks whether function uses non-inherited context
- exptostd: detects golang.org/x/exp functions replaceable by std
- nilnesserr: reports err != nil checks returning different nil error
- prealloc: finds slice declarations that could be pre-allocated
- predeclared: finds code shadowing Go's predeclared identifiers
- usetesting: detects uses replaceable by standard testing helpers

Auto-fixed issues from golangci-lint --fix across multiple files.
@orestisfl orestisfl self-assigned this Dec 4, 2025
@orestisfl orestisfl added the bug Something isn't working label Dec 4, 2025
@orestisfl orestisfl requested a review from a team as a code owner December 4, 2025 17:28
@orestisfl orestisfl added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Dec 4, 2025
@orestisfl orestisfl requested review from andrzej-stencel and faec and removed request for a team December 4, 2025 17:28
Fix unused field warnings on Windows:
- Move IOStat struct to platform-specific files
- Linux version includes lastCPU/curCPU fields for iostat calculations
- Windows/Darwin/FreeBSD versions only have lastDiskIOCounters

Fix usetesting warnings:
- Replace context.Background() with t.Context() in test functions
@orestisfl orestisfl merged commit e62283e into elastic:main Dec 11, 2025
5 checks passed
@orestisfl orestisfl deleted the golangci-lint-v2-migration branch December 11, 2025 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants