Skip to content

Commit

Permalink
golangci-lint: enable predeclared linter
Browse files Browse the repository at this point in the history
    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 <[email protected]>
  • Loading branch information
thaJeztah committed Nov 20, 2023
1 parent 82fca99 commit 4a3ebc5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ linters:
- megacheck
- misspell
- nakedret
- predeclared
- revive
- staticcheck
- thelper
Expand Down
10 changes: 5 additions & 5 deletions cli/command/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4a3ebc5

Please sign in to comment.