Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace strings.Replace with strings.ReplaceAll #978

Merged
merged 1 commit into from May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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