Fix some quality issues (#1914)

* 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>
This commit is contained in:
Siddhant N Trivedi
2021-01-10 00:09:21 +05:30
committed by GitHub
parent fcc2fea684
commit cf35b8021c
5 changed files with 18 additions and 22 deletions

View 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

View 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'})
}
}

View 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, "/")...)...)
}

View 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
}()

View 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)