mirror of
https://github.com/zyedidia/micro.git
synced 2024-11-09 08:26:38 +03:00
Fix quality issues (#1856)
* Add .deepsource.toml * Remove unnecessary comparison with bool * Remove unnecessary use of slice * Replace multiple `append`s with one * Remove unnecessary wrapping of function call * Fix check for empty string * Simplify error creation with `fmt.Errorf` * Fix defers before error check Signed-off-by: sourya_deepsource <sourya@deepsource.io> * Remove untrappable `os.Kill` signal Signed-off-by: sourya_deepsource <sourya@deepsource.io> * Remove empty else branch Signed-off-by: sourya_deepsource <sourya@deepsource.io> * Add missing error check Signed-off-by: sourya_deepsource <sourya@deepsource.io> * Merge variable declaration and assignment Signed-off-by: sourya_deepsource <sourya@deepsource.io> * Remove unnecessary `nil` check Signed-off-by: sourya_deepsource <sourya@deepsource.io> * Revert changes to generated files Signed-off-by: sourya_deepsource <sourya@deepsource.io> * Remove .deepsource.toml Signed-off-by: sourya_deepsource <sourya@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:
parent
6dd92faf1a
commit
fc3dd9a62f
@ -50,9 +50,7 @@ func luaImportMicro() *lua.LTable {
|
||||
ulua.L.SetField(pkg, "CurPane", luar.New(ulua.L, func() action.Pane {
|
||||
return action.MainTab().CurPane()
|
||||
}))
|
||||
ulua.L.SetField(pkg, "CurTab", luar.New(ulua.L, func() *action.Tab {
|
||||
return action.MainTab()
|
||||
}))
|
||||
ulua.L.SetField(pkg, "CurTab", luar.New(ulua.L, action.MainTab))
|
||||
ulua.L.SetField(pkg, "Tabs", luar.New(ulua.L, func() *action.TabList {
|
||||
return action.Tabs
|
||||
}))
|
||||
|
@ -272,7 +272,7 @@ func main() {
|
||||
}
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Kill, syscall.SIGTERM)
|
||||
signal.Notify(c, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
<-c
|
||||
|
@ -991,7 +991,7 @@ func (h *BufPane) CutLine() bool {
|
||||
if !h.Cursor.HasSelection() {
|
||||
return false
|
||||
}
|
||||
if h.freshClip == true {
|
||||
if h.freshClip {
|
||||
if h.Cursor.HasSelection() {
|
||||
if clip, err := clipboard.Read(clipboard.ClipboardReg); err != nil {
|
||||
InfoBar.Error(err)
|
||||
@ -999,7 +999,7 @@ func (h *BufPane) CutLine() bool {
|
||||
clipboard.WriteMulti(clip+string(h.Cursor.GetSelection()), clipboard.ClipboardReg, h.Cursor.Num, h.Buf.NumCursors())
|
||||
}
|
||||
}
|
||||
} else if time.Since(h.lastCutTime)/time.Second > 10*time.Second || h.freshClip == false {
|
||||
} else if time.Since(h.lastCutTime)/time.Second > 10*time.Second || !h.freshClip {
|
||||
h.Copy()
|
||||
}
|
||||
h.freshClip = true
|
||||
|
@ -159,7 +159,7 @@ modSearch:
|
||||
}
|
||||
}
|
||||
|
||||
if len(k) == 0 {
|
||||
if k == "" {
|
||||
return KeyEvent{}, false
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,6 @@ func (b *Buffer) CycleAutocomplete(forward bool) {
|
||||
end := c.Loc
|
||||
if prevSuggestion < len(b.Suggestions) && prevSuggestion >= 0 {
|
||||
start = end.Move(-util.CharacterCountInString(b.Completions[prevSuggestion]), b)
|
||||
} else {
|
||||
// end = start.Move(1, b)
|
||||
}
|
||||
|
||||
b.Replace(start, end, b.Completions[b.CurSuggestion])
|
||||
|
@ -69,7 +69,7 @@ func (b *Buffer) Backup() error {
|
||||
}
|
||||
|
||||
backupdir, err := util.ReplaceHome(b.Settings["backupdir"].(string))
|
||||
if len(backupdir) == 0 || err != nil {
|
||||
if backupdir == "" || err != nil {
|
||||
backupdir = filepath.Join(config.ConfigDir, "backups")
|
||||
}
|
||||
if _, err := os.Stat(backupdir); os.IsNotExist(err) {
|
||||
|
@ -610,6 +610,9 @@ func (b *Buffer) UpdateRules() {
|
||||
}
|
||||
|
||||
header, err = highlight.MakeHeaderYaml(data)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error parsing header for syntax file " + f.Name() + ": " + err.Error())
|
||||
}
|
||||
file, err := highlight.ParseFile(data)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
|
||||
|
@ -130,7 +130,7 @@ func NewLineArray(size uint64, endings FileFormat, reader io.Reader) *LineArray
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
la.lines = Append(la.lines, Line{
|
||||
data: data[:],
|
||||
data: data,
|
||||
state: nil,
|
||||
match: nil,
|
||||
rehighlight: false,
|
||||
|
@ -51,8 +51,8 @@ func (b *Buffer) Unserialize() error {
|
||||
return nil
|
||||
}
|
||||
file, err := os.Open(filepath.Join(config.ConfigDir, "buffers", util.EscapePath(b.AbsPath)))
|
||||
defer file.Close()
|
||||
if err == nil {
|
||||
defer file.Close()
|
||||
var buffer SerializedBuffer
|
||||
decoder := gob.NewDecoder(file)
|
||||
err = decoder.Decode(&buffer)
|
||||
|
@ -121,8 +121,7 @@ func ParseColorscheme(text string) (map[string]tcell.Style, error) {
|
||||
func StringToStyle(str string) tcell.Style {
|
||||
var fg, bg string
|
||||
spaceSplit := strings.Split(str, " ")
|
||||
var split []string
|
||||
split = strings.Split(spaceSplit[len(spaceSplit)-1], ",")
|
||||
split := strings.Split(spaceSplit[len(spaceSplit)-1], ",")
|
||||
if len(split) > 1 {
|
||||
fg, bg = split[0], split[1]
|
||||
} else {
|
||||
|
@ -479,9 +479,7 @@ func (pl PluginPackages) GetAllVersions(name string) PluginVersions {
|
||||
result := make(PluginVersions, 0)
|
||||
p := pl.Get(name)
|
||||
if p != nil {
|
||||
for _, v := range p.Versions {
|
||||
result = append(result, v)
|
||||
}
|
||||
result = append(result, p.Versions...)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ func InitGlobalSettings() error {
|
||||
for k, v := range parsedSettings {
|
||||
if !strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
|
||||
if _, ok := GlobalSettings[k]; ok && !verifySetting(k, reflect.TypeOf(v), reflect.TypeOf(GlobalSettings[k])) {
|
||||
err = errors.New(fmt.Sprintf("Global Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", k, reflect.TypeOf(v), GlobalSettings[k], reflect.TypeOf(GlobalSettings[k])))
|
||||
err = fmt.Errorf("Global Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", k, reflect.TypeOf(v), GlobalSettings[k], reflect.TypeOf(GlobalSettings[k]))
|
||||
continue
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ func InitLocalSettings(settings map[string]interface{}, path string) error {
|
||||
if settings["filetype"].(string) == k[3:] {
|
||||
for k1, v1 := range v.(map[string]interface{}) {
|
||||
if _, ok := settings[k1]; ok && !verifySetting(k1, reflect.TypeOf(v1), reflect.TypeOf(settings[k1])) {
|
||||
parseError = errors.New(fmt.Sprintf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", k, reflect.TypeOf(v1), settings[k1], reflect.TypeOf(settings[k1])))
|
||||
parseError = fmt.Errorf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", k, reflect.TypeOf(v1), settings[k1], reflect.TypeOf(settings[k1]))
|
||||
continue
|
||||
}
|
||||
settings[k1] = v1
|
||||
@ -141,7 +141,7 @@ func InitLocalSettings(settings map[string]interface{}, path string) error {
|
||||
if g.MatchString(path) {
|
||||
for k1, v1 := range v.(map[string]interface{}) {
|
||||
if _, ok := settings[k1]; ok && !verifySetting(k1, reflect.TypeOf(v1), reflect.TypeOf(settings[k1])) {
|
||||
parseError = errors.New(fmt.Sprintf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", k, reflect.TypeOf(v1), settings[k1], reflect.TypeOf(settings[k1])))
|
||||
parseError = fmt.Errorf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", k, reflect.TypeOf(v1), settings[k1], reflect.TypeOf(settings[k1]))
|
||||
continue
|
||||
}
|
||||
settings[k1] = v1
|
||||
|
@ -557,7 +557,7 @@ func (w *BufWindow) displayBuffer() {
|
||||
if r == '\t' {
|
||||
indentrunes := []rune(b.Settings["indentchar"].(string))
|
||||
// if empty indentchar settings, use space
|
||||
if indentrunes == nil || len(indentrunes) == 0 {
|
||||
if len(indentrunes) == 0 {
|
||||
indentrunes = []rune{' '}
|
||||
}
|
||||
|
||||
|
@ -14,9 +14,9 @@ import (
|
||||
func (i *InfoBuf) LoadHistory() {
|
||||
if config.GetGlobalOption("savehistory").(bool) {
|
||||
file, err := os.Open(filepath.Join(config.ConfigDir, "buffers", "history"))
|
||||
defer file.Close()
|
||||
var decodedMap map[string][]string
|
||||
if err == nil {
|
||||
defer file.Close()
|
||||
decoder := gob.NewDecoder(file)
|
||||
err = decoder.Decode(&decodedMap)
|
||||
|
||||
@ -48,8 +48,8 @@ func (i *InfoBuf) SaveHistory() {
|
||||
}
|
||||
|
||||
file, err := os.Create(filepath.Join(config.ConfigDir, "buffers", "history"))
|
||||
defer file.Close()
|
||||
if err == nil {
|
||||
defer file.Close()
|
||||
encoder := gob.NewEncoder(file)
|
||||
|
||||
err = encoder.Encode(i.History)
|
||||
|
@ -54,7 +54,7 @@ func (i *InfoBuf) Close() {
|
||||
func (i *InfoBuf) Message(msg ...interface{}) {
|
||||
// only display a new message if there isn't an active prompt
|
||||
// this is to prevent overwriting an existing prompt to the user
|
||||
if i.HasPrompt == false {
|
||||
if !i.HasPrompt {
|
||||
displayMessage := fmt.Sprint(msg...)
|
||||
// if there is no active prompt then style and display the message as normal
|
||||
i.Msg = displayMessage
|
||||
@ -78,7 +78,7 @@ func (i *InfoBuf) ClearGutter() {
|
||||
func (i *InfoBuf) Error(msg ...interface{}) {
|
||||
// only display a new message if there isn't an active prompt
|
||||
// this is to prevent overwriting an existing prompt to the user
|
||||
if i.HasPrompt == false {
|
||||
if !i.HasPrompt {
|
||||
// if there is no active prompt then style and display the message as normal
|
||||
i.Msg = fmt.Sprint(msg...)
|
||||
i.HasMessage, i.HasError = false, true
|
||||
|
Loading…
Reference in New Issue
Block a user