Skip to content

Commit

Permalink
refactor: replace strings.Replace with strings.ReplaceAll (#7660)
Browse files Browse the repository at this point in the history
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>

Co-authored-by: PFedak <pzfedak@gmail.com>
  • Loading branch information
Juneezee and PFedak committed Jun 1, 2022
1 parent e4359f6 commit 46e73c1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/internal/cmdutil/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ func CreateAlias(cmd *cobra.Command, invocation string) *cobra.Command {
if cmd.Use == "" {
cur.Use = arg
} else {
cur.Use = strings.Replace(cmd.Use, "{{alias}}", arg, -1)
cur.Use = strings.ReplaceAll(cmd.Use, "{{alias}}", arg)
}
cur.Example = strings.Replace(cmd.Example, "{{alias}}", fmt.Sprintf("%s %s", os.Args[0], invocation), -1)
cur.Example = strings.ReplaceAll(cmd.Example, "{{alias}}", fmt.Sprintf("%s %s", os.Args[0], invocation))
} else {
cur.Use = arg
}
Expand Down
2 changes: 1 addition & 1 deletion src/internal/collection/postgres_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ type postgresListener struct {

func NewPostgresListener(dsn string) PostgresListener {
// Apparently this is very important for lib/pq to work
dsn = strings.Replace(dsn, "statement_cache_mode=describe", "", -1)
dsn = strings.ReplaceAll(dsn, "statement_cache_mode=describe", "")
eg, _ := errgroup.WithContext(context.Background())

l := &postgresListener{
Expand Down
2 changes: 1 addition & 1 deletion src/internal/ppsutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func PipelineRcName(name string, version uint64) string {
// k8s won't allow RC names that contain upper-case letters
// or underscores
// TODO: deal with name collision
name = strings.Replace(name, "_", "-", -1)
name = strings.ReplaceAll(name, "_", "-")
return fmt.Sprintf("pipeline-%s-v%d", strings.ToLower(name), version)
}

Expand Down
4 changes: 2 additions & 2 deletions src/internal/pretty/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

// UnescapeHTML returns s with < and > unescaped.
func UnescapeHTML(s string) string {
s = strings.Replace(s, "\\u003c", "<", -1)
s = strings.Replace(s, "\\u003e", ">", -1)
s = strings.ReplaceAll(s, "\\u003c", "<")
s = strings.ReplaceAll(s, "\\u003e", ">")
return s
}

Expand Down
4 changes: 2 additions & 2 deletions src/internal/uuid/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func New() string {

// NewWithoutDashes returns a new uuid without no "-".
func NewWithoutDashes() string {
return strings.Replace(New(), "-", "", -1)
return strings.ReplaceAll(New(), "-", "")
}

// NewWithoutUnderscores returns a new uuid without no "_".
func NewWithoutUnderscores() string {
return strings.Replace(New(), "_", "", -1)
return strings.ReplaceAll(New(), "_", "")
}

// IsUUIDWithoutDashes checks whether a string is a UUID without dashes
Expand Down

0 comments on commit 46e73c1

Please sign in to comment.