Skip to content

Commit

Permalink
refactor: replace strings.Replace with strings.ReplaceAll (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juneezee committed May 15, 2022
1 parent b69554f commit 143d208
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions ginkgo/generators/generate_command.go
Expand Up @@ -136,8 +136,8 @@ func generateTestFileForSubject(subject string, conf GeneratorsConfig) {
}

func formatSubject(name string) string {
name = strings.Replace(name, "-", "_", -1)
name = strings.Replace(name, " ", "_", -1)
name = strings.ReplaceAll(name, "-", "_")
name = strings.ReplaceAll(name, " ", "_")
name = strings.Split(name, ".go")[0]
name = strings.Split(name, "_test")[0]
return name
Expand Down Expand Up @@ -223,7 +223,7 @@ func getPackageImportPath() string {
if modRoot != "" {
modName := moduleName(modRoot)
if modName != "" {
cd := strings.Replace(workingDir, modRoot, "", -1)
cd := strings.ReplaceAll(workingDir, modRoot, "")
cd = strings.ReplaceAll(cd, sep, "/")
return modName + cd
}
Expand Down
10 changes: 5 additions & 5 deletions ginkgo/generators/generators_common.go
Expand Up @@ -19,8 +19,8 @@ func getPackageAndFormattedName() (string, string, string) {
path, err := os.Getwd()
command.AbortIfError("Could not get current working directory:", err)

dirName := strings.Replace(filepath.Base(path), "-", "_", -1)
dirName = strings.Replace(dirName, " ", "_", -1)
dirName := strings.ReplaceAll(filepath.Base(path), "-", "_")
dirName = strings.ReplaceAll(dirName, " ", "_")

pkg, err := build.ImportDir(path, 0)
packageName := pkg.Name
Expand All @@ -47,10 +47,10 @@ func ensureLegalPackageName(name string) string {
}

func prettifyName(name string) string {
name = strings.Replace(name, "-", " ", -1)
name = strings.Replace(name, "_", " ", -1)
name = strings.ReplaceAll(name, "-", " ")
name = strings.ReplaceAll(name, "_", " ")
name = strings.Title(name)
name = strings.Replace(name, " ", "", -1)
name = strings.ReplaceAll(name, " ", "")
return name
}

Expand Down
4 changes: 2 additions & 2 deletions ginkgo/internal/run.go
Expand Up @@ -330,8 +330,8 @@ func runAfterRunHook(command string, noColor bool, suite TestSuite) {
if suite.State.Is(TestSuiteStatePassed) {
passed = "[PASS]"
}
command = strings.Replace(command, "(ginkgo-suite-passed)", passed, -1)
command = strings.Replace(command, "(ginkgo-suite-name)", suite.PackageName, -1)
command = strings.ReplaceAll(command, "(ginkgo-suite-passed)", passed)
command = strings.ReplaceAll(command, "(ginkgo-suite-name)", suite.PackageName)

// Must break command into parts
splitArgs := regexp.MustCompile(`'.+'|".+"|\S+`)
Expand Down
12 changes: 6 additions & 6 deletions reporters/teamcity_report.go
Expand Up @@ -17,12 +17,12 @@ import (
)

func tcEscape(s string) string {
s = strings.Replace(s, "|", "||", -1)
s = strings.Replace(s, "'", "|'", -1)
s = strings.Replace(s, "\n", "|n", -1)
s = strings.Replace(s, "\r", "|r", -1)
s = strings.Replace(s, "[", "|[", -1)
s = strings.Replace(s, "]", "|]", -1)
s = strings.ReplaceAll(s, "|", "||")
s = strings.ReplaceAll(s, "'", "|'")
s = strings.ReplaceAll(s, "\n", "|n")
s = strings.ReplaceAll(s, "\r", "|r")
s = strings.ReplaceAll(s, "[", "|[")
s = strings.ReplaceAll(s, "]", "|]")
return s
}

Expand Down

0 comments on commit 143d208

Please sign in to comment.