refactor: replace strings.Replace with strings.ReplaceAll (#15392)

strings.ReplaceAll(s, old, new) is a wrapper function for
strings.Replace(s, old, new, -1). But strings.ReplaceAll is more
readable and removes the hardcoded -1.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2022-08-04 03:22:48 +08:00
committed by GitHub
parent 475a88e813
commit 6141d61839
36 changed files with 56 additions and 56 deletions

View File

@@ -553,7 +553,7 @@ func expandPattern(pattern string) []string {
if start != -1 && end != -1 && end > start {
regexToRemove = base[start+1 : end]
}
pattern = strings.Replace(pattern, regexToRemove, "", -1)
pattern = strings.ReplaceAll(pattern, regexToRemove, "")
// Simplify named fields that have limited options, e.g. (?P<foo>a|b|c) -> (<P<foo>.+)
pattern = altFieldsGroupRe.ReplaceAllStringFunc(pattern, func(s string) string {
@@ -767,7 +767,7 @@ func (d *OASDocument) CreateOperationIDs(context string) {
// Space-split on non-words, title case everything, recombine
opID := nonWordRe.ReplaceAllString(strings.ToLower(path), " ")
opID = strings.Title(opID)
opID = method + strings.Replace(opID, " ", "", -1)
opID = method + strings.ReplaceAll(opID, " ", "")
// deduplicate operationIds. This is a safeguard, since generated IDs should
// already be unique given our current path naming conventions.