]> git.lizzy.rs Git - micro.git/commitdiff
Fix some quality issues (#1914)
authorSiddhant N Trivedi <68370997+siddhant-deepsource@users.noreply.github.com>
Sat, 9 Jan 2021 18:39:21 +0000 (00:09 +0530)
committerGitHub <noreply@github.com>
Sat, 9 Jan 2021 18:39:21 +0000 (13:39 -0500)
* Add .deepsource.toml

* Fix unnecessary typecasting on `bytes.Buffer`

* Fix check for empty string

* Replace nested if block with else-if

* Replace nested if block with else-if

* Replaced string.Replace() with string.ReplaceAll where n<0

* Remove deepsource toml file

Signed-off-by: siddhant-deepsource <siddhant@deepsource.io>
Co-authored-by: DeepSource Bot <bot@deepsource.io>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
internal/action/actions.go
internal/buffer/buffer.go
internal/config/runtime.go
internal/shell/job.go
internal/util/util.go

index ee9c78aaee081077f78f795ab2b6de060f3ca183..ce9f9d8094869d9ece5147b5fa2adf9211edb783 100644 (file)
@@ -1166,7 +1166,7 @@ func (h *BufPane) paste(clip string) {
        if h.Buf.Settings["smartpaste"].(bool) {
                if h.Cursor.X > 0 && len(util.GetLeadingWhitespace([]byte(strings.TrimLeft(clip, "\r\n")))) == 0 {
                        leadingWS := util.GetLeadingWhitespace(h.Buf.LineBytes(h.Cursor.Y))
-                       clip = strings.Replace(clip, "\n", "\n"+string(leadingWS), -1)
+                       clip = strings.ReplaceAll(clip, "\n", "\n"+string(leadingWS))
                }
        }
 
@@ -1349,10 +1349,8 @@ func (h *BufPane) HalfPageDown() bool {
        v := h.GetView()
        if h.Buf.LinesNum()-(v.StartLine+v.Height) > v.Height/2 {
                h.ScrollDown(v.Height / 2)
-       } else {
-               if h.Buf.LinesNum() >= v.Height {
-                       v.StartLine = h.Buf.LinesNum() - v.Height
-               }
+       } else if h.Buf.LinesNum() >= v.Height {
+               v.StartLine = h.Buf.LinesNum() - v.Height
        }
        h.SetView(v)
        return true
index dba08fe76842b4b2879c3fdd142f5719f5c9aa39..c2fda6658325eb869c9dab0f38ccc46cb22aa9a0 100644 (file)
@@ -355,12 +355,10 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
 
        if startcursor.X != -1 && startcursor.Y != -1 {
                b.StartCursor = startcursor
-       } else {
-               if b.Settings["savecursor"].(bool) || b.Settings["saveundo"].(bool) {
-                       err := b.Unserialize()
-                       if err != nil {
-                               screen.TermMessage(err)
-                       }
+       } else if b.Settings["savecursor"].(bool) || b.Settings["saveundo"].(bool) {
+               err := b.Unserialize()
+               if err != nil {
+                       screen.TermMessage(err)
                }
        }
 
@@ -1003,9 +1001,9 @@ func (b *Buffer) Retab() {
                ws := util.GetLeadingWhitespace(l)
                if len(ws) != 0 {
                        if toSpaces {
-                               ws = bytes.Replace(ws, []byte{'\t'}, bytes.Repeat([]byte{' '}, tabsize), -1)
+                               ws = bytes.ReplaceAll(ws, []byte{'\t'}, bytes.Repeat([]byte{' '}, tabsize))
                        } else {
-                               ws = bytes.Replace(ws, bytes.Repeat([]byte{' '}, tabsize), []byte{'\t'}, -1)
+                               ws = bytes.ReplaceAll(ws, bytes.Repeat([]byte{' '}, tabsize), []byte{'\t'})
                        }
                }
 
index 13548447960b4f4f76d7efa65971c084f6e3dfeb..5d174dea16d39c5d889d652c24ccad810b34b9ec 100644 (file)
@@ -6812,7 +6812,7 @@ func runtimeSyntaxZshYaml() (*asset, error) {
 // It returns an error if the asset could not be found or
 // could not be loaded.
 func Asset(name string) ([]byte, error) {
-       cannonicalName := strings.Replace(name, "\\", "/", -1)
+       cannonicalName := strings.ReplaceAll(name, "\\", "/")
        if f, ok := _bindata[cannonicalName]; ok {
                a, err := f()
                if err != nil {
@@ -6838,7 +6838,7 @@ func MustAsset(name string) []byte {
 // It returns an error if the asset could not be found or
 // could not be loaded.
 func AssetInfo(name string) (os.FileInfo, error) {
-       cannonicalName := strings.Replace(name, "\\", "/", -1)
+       cannonicalName := strings.ReplaceAll(name, "\\", "/")
        if f, ok := _bindata[cannonicalName]; ok {
                a, err := f()
                if err != nil {
@@ -7198,8 +7198,8 @@ var _bindata = map[string]func() (*asset, error){
 // AssetDir("") will return []string{"data"}.
 func AssetDir(name string) ([]string, error) {
        node := _bintree
-       if len(name) != 0 {
-               cannonicalName := strings.Replace(name, "\\", "/", -1)
+       if name != "" {
+               cannonicalName := strings.ReplaceAll(name, "\\", "/")
                pathList := strings.Split(cannonicalName, "/")
                for _, p := range pathList {
                        node = node.Children[p]
@@ -7620,6 +7620,6 @@ func RestoreAssets(dir, name string) error {
 }
 
 func _filePath(dir, name string) string {
-       cannonicalName := strings.Replace(name, "\\", "/", -1)
+       cannonicalName := strings.ReplaceAll(name, "\\", "/")
        return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
 }
index f45d402011f78c2b9e1dbb3ffd4a7d1d0243b211..6e1f4b18a5ec2667b2303dc30e0d4298e4ac3def 100644 (file)
@@ -78,7 +78,7 @@ func JobSpawn(cmdName string, cmdArgs []string, onStdout, onStderr, onExit func(
        go func() {
                // Run the process in the background and create the onExit callback
                proc.Run()
-               jobFunc := JobFunction{onExit, string(outbuf.Bytes()), userargs}
+               jobFunc := JobFunction{onExit, outbuf.String(), userargs}
                Jobs <- jobFunc
        }()
 
index 667b85650b04ea739e65e933380f29f40383f2a1..f312ef56e91c7bfa4eb76ea60ddb89da5c846ce7 100644 (file)
@@ -341,9 +341,9 @@ func EscapePath(path string) string {
        path = filepath.ToSlash(path)
        if runtime.GOOS == "windows" {
                // ':' is not valid in a path name on Windows but is ok on Unix
-               path = strings.Replace(path, ":", "%", -1)
+               path = strings.ReplaceAll(path, ":", "%")
        }
-       return strings.Replace(path, "/", "%", -1)
+       return strings.ReplaceAll(path, "/", "%")
 }
 
 // GetLeadingWhitespace returns the leading whitespace of the given byte array
@@ -430,7 +430,7 @@ func IsAutocomplete(c rune) bool {
 }
 
 func ParseSpecial(s string) string {
-       return strings.Replace(s, "\\t", "\t", -1)
+       return strings.ReplaceAll(s, "\\t", "\t")
 }
 
 // String converts a byte array to a string (for lua plugins)