From 606cbd60a198bf682479783c37c1a3dbd1e96167 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 20 Nov 2023 11:15:36 +0100 Subject: [PATCH] golangci-lint: enable predeclared linter cli/command/utils.go:190:35: param new has same name as predeclared identifier (predeclared) func StringSliceReplaceAt(s, old, new []string, requireIndex int) ([]string, bool) { ^ Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 1 + cli/command/utils.go | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index bef425b96d..8afc71aedf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -14,6 +14,7 @@ linters: - megacheck - misspell - nakedret + - predeclared - revive - staticcheck - thelper diff --git a/cli/command/utils.go b/cli/command/utils.go index 91b9fc1891..d55d5dc28a 100644 --- a/cli/command/utils.go +++ b/cli/command/utils.go @@ -184,17 +184,17 @@ func stringSliceIndex(s, subs []string) int { return -1 } -// StringSliceReplaceAt replaces the sub-slice old, with the sub-slice new, in the string +// StringSliceReplaceAt replaces the sub-slice find, with the sub-slice replace, in the string // slice s, returning a new slice and a boolean indicating if the replacement happened. // requireIdx is the index at which old needs to be found at (or -1 to disregard that). -func StringSliceReplaceAt(s, old, new []string, requireIndex int) ([]string, bool) { - idx := stringSliceIndex(s, old) +func StringSliceReplaceAt(s, find, replace []string, requireIndex int) ([]string, bool) { + idx := stringSliceIndex(s, find) if (requireIndex != -1 && requireIndex != idx) || idx == -1 { return s, false } out := append([]string{}, s[:idx]...) - out = append(out, new...) - out = append(out, s[idx+len(old):]...) + out = append(out, replace...) + out = append(out, s[idx+len(find):]...) return out, true }