autofix: function call can be replaced with helper function (#6805)

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
This commit is contained in:
deepsource-autofix[bot]
2022-03-06 16:33:55 +08:00
committed by GitHub
parent deec3516d5
commit 5afca6ca8e
10 changed files with 22 additions and 24 deletions

View File

@@ -112,10 +112,10 @@ func parseKeyString(content string) (string, error) {
// Transform all legal line endings to a single "\n"
// Replace all windows full new lines ("\r\n")
content = strings.Replace(content, "\r\n", "\n", -1)
content = strings.ReplaceAll(content, "\r\n", "\n")
// Replace all windows half new lines ("\r"), if it happen not to match replace above
content = strings.Replace(content, "\r", "\n", -1)
content = strings.ReplaceAll(content, "\r", "\n")
// Replace ending new line as its may cause unwanted behaviour (extra line means not a single line key | OpenSSH key)
content = strings.TrimRight(content, "\n")
@@ -374,8 +374,7 @@ func checkKeyContent(content string) error {
func addKey(e Engine, key *PublicKey) (err error) {
// Calculate fingerprint.
tmpPath := strings.Replace(path.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()),
"id_rsa.pub"), "\\", "/", -1)
tmpPath := strings.ReplaceAll(path.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()), "id_rsa.pub"), "\\", "/")
_ = os.MkdirAll(path.Dir(tmpPath), os.ModePerm)
if err = ioutil.WriteFile(tmpPath, []byte(key.Content), 0644); err != nil {
return err

View File

@@ -51,18 +51,18 @@ func (p *SlackPayload) JSONPayload() ([]byte, error) {
// see: https://api.slack.com/docs/formatting
func SlackTextFormatter(s string) string {
// replace & < >
s = strings.Replace(s, "&", "&amp;", -1)
s = strings.Replace(s, "<", "&lt;", -1)
s = strings.Replace(s, ">", "&gt;", -1)
s = strings.ReplaceAll(s, "&", "&amp;")
s = strings.ReplaceAll(s, "<", "&lt;")
s = strings.ReplaceAll(s, ">", "&gt;")
return s
}
func SlackShortTextFormatter(s string) string {
s = strings.Split(s, "\n")[0]
// replace & < >
s = strings.Replace(s, "&", "&amp;", -1)
s = strings.Replace(s, "<", "&lt;", -1)
s = strings.Replace(s, ">", "&gt;", -1)
s = strings.ReplaceAll(s, "&", "&amp;")
s = strings.ReplaceAll(s, "<", "&lt;")
s = strings.ReplaceAll(s, ">", "&gt;")
return s
}

View File

@@ -33,7 +33,7 @@ func ToWikiPageURL(name string) string {
// that are not belong to wiki repository.
func ToWikiPageName(urlString string) string {
name, _ := url.QueryUnescape(urlString)
return strings.Replace(strings.TrimLeft(path.Clean("/"+name), "/"), "/", " ", -1)
return strings.ReplaceAll(strings.TrimLeft(path.Clean("/"+name), "/"), "/", " ")
}
// WikiCloneLink returns clone URLs of repository wiki.