From c1313a92a098e716b19da6112f66b5e053747bc5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 May 2025 19:23:08 +0200 Subject: [PATCH] golangci-lint: enable makezero linter cli/command/container/formatter_stats_test.go:339:11: append to slice `stats` with non-zero initialized length (makezero) stats = append(stats, entry) ^ Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 1 + cli/command/container/formatter_stats_test.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f16bfa547a..2432972bd2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -42,6 +42,7 @@ linters: - govet - importas # Enforces consistent import aliases. - ineffassign + - makezero # Finds slice declarations with non-zero initial length. - mirror # Detects wrong mirror patterns of bytes/strings usage. - misspell # Detects commonly misspelled English words in comments. - nakedret # Detects uses of naked returns. diff --git a/cli/command/container/formatter_stats_test.go b/cli/command/container/formatter_stats_test.go index bf85d2e130..8569ef4de4 100644 --- a/cli/command/container/formatter_stats_test.go +++ b/cli/command/container/formatter_stats_test.go @@ -148,7 +148,7 @@ container2 -- -- `, }, } - stats := []StatsEntry{ + entries := []StatsEntry{ { Container: "container1", CPUPercentage: 20, @@ -181,7 +181,7 @@ container2 -- -- t.Run(string(tc.context.Format), func(t *testing.T) { var out bytes.Buffer tc.context.Output = &out - err := statsFormatWrite(tc.context, stats, "windows", false) + err := statsFormatWrite(tc.context, entries, "windows", false) if err != nil { assert.Error(t, err, tc.expected) } else { @@ -309,10 +309,10 @@ func TestContainerStatsContextWriteTrunc(t *testing.T) { func BenchmarkStatsFormat(b *testing.B) { b.ReportAllocs() - stats := genStats() + entries := genStats() for i := 0; i < b.N; i++ { - for _, s := range stats { + for _, s := range entries { _ = s.CPUPerc() _ = s.MemUsage() _ = s.MemPerc() @@ -335,9 +335,9 @@ func genStats() []statsContext { NetworkTx: 987.654321, PidsCurrent: 123456789, }} - stats := make([]statsContext, 100) - for i := 0; i < 100; i++ { - stats = append(stats, entry) + entries := make([]statsContext, 0, 100) + for range 100 { + entries = append(entries, entry) } - return stats + return entries }