You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable the modernize linter from golangci-lint's suite. It flags
outdated Go syntax and rewrites it to modern equivalents: min/max
builtins, range-over-int loops, slices/maps helpers, any, t.Context()
in tests, fmt.Appendf, strings.CutPrefix, and more. Keeping it enabled
stops outdated patterns from re-entering the codebase, which matters
more now that much code is produced by AI agents trained on older Go,
and it often yields simpler, more efficient code.
The omitzero analyzer is disabled: it rewrites ,omitempty struct tags to
,omitzero, which changes JSON marshaling semantics and is not a
mechanical, behavior-preserving fix.
The loop also runs `go fix -inline`, which applies //go:fix inline
directives. modernize marks its own pointer helpers with the directive,
and dependencies/stdlib carry it on deprecated APIs, so this pulls in
mechanical migrations such as io/ioutil -> io and reflect.Ptr ->
reflect.Pointer. `go fix` inlines the call sites but never deletes the
now-dead helper declarations; a follow-up commit removes those.
Every Go change here is a linter/`go fix` auto-fix, restricted to the
files owned by @elastic/elastic-agent-data-plane; the rest of the
repository is modernized in a stacked follow-up PR so each team reviews
only its own code.
The .golangci.yml change is made by hand. The Go changes (except for
some manual changes that were highlighted in the review) are then fully
reproducible by running this with bash from the repository root:
set -euo pipefail
OWNER="@elastic/elastic-agent-data-plane"
export CGO_ENABLED=1
MAX_PASSES=10
modernize() {
golangci-lint run --enable-only modernize \
--max-issues-per-linter 0 --max-same-issues 0 --timeout=90m --fix ./...
}
for pass in $(seq "$MAX_PASSES"); do
echo ">>> pass $pass: fmt"
before="$(git diff | git hash-object --stdin)"
golangci-lint fmt ./...
echo ">>> pass $pass: modernize --fix"
if modernize; then :; fi
echo ">>> pass $pass: go fix -inline"
if go fix -inline ./...; then :; fi
echo ">>> pass $pass done: $(git diff --name-only | wc -l) files changed"
[ "$before" = "$(git diff | git hash-object --stdin)" ] && { echo ">>> fixpoint at pass $pass"; break; }
done
golangci-lint fmt ./...
changed="$(mktemp)"
keep="$(mktemp)"
trap 'rm -f "$changed" "$keep"' EXIT
git diff --name-only -- '*.go' | sort -u >"$changed"
git diff --name-only -- '*.go' | xargs -r codeowners -o "$OWNER" \
| awk '{print $1}' | sort -u >"$keep"
comm -23 "$changed" "$keep" | tr '\n' '\0' | xargs -0 -r git checkout --
echo "PR1 data-plane .go files: $(git diff --name-only -- '*.go' | wc -l)"
0 commit comments