Skip to content

Commit

Permalink
Don't disable if disable-all specified
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed May 6, 2020
1 parent e2f46da commit 6a71936
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 6 additions & 2 deletions pkg/golangcilint/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,18 @@ func (r *Runner) EnableLinter(linterName string) {
r.cfg.Linters[linterName] = linter
}

func (r *Runner) DisableLinter(linterName string) {
func (r *Runner) DisableLinter(linterName string) error {
linter, ok := r.cfg.Linters[linterName]
if !ok {
r.logger.WithField("linter", linterName).Error("linter not found")
return
return nil
}
if linter.EnabledByConfig() && r.cfg.DisableAll {
return fmt.Errorf("can't disable '%s' linter because 'disable-all' is specified in the config file", linter.Name())
}
linter.Disable()
r.cfg.Linters[linterName] = linter
return nil
}

func (r *Runner) GetVersion() string {
Expand Down
7 changes: 5 additions & 2 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ func (g *Gui) enableLinter(node *tview.TreeNode, linter *config.Linter) {
node.SetColor(item.EnabledLinterColor)
}

func (g *Gui) disableLinter(node *tview.TreeNode, linter *config.Linter) {
g.runner.DisableLinter(linter.Name())
func (g *Gui) disableLinter(node *tview.TreeNode, linter *config.Linter) error {
if err := g.runner.DisableLinter(linter.Name()); err != nil {
return err
}
node.SetColor(item.DefaultLinterColor)
return nil
}

// switchPanel switches to focus on the given Primitive.
Expand Down
8 changes: 6 additions & 2 deletions pkg/gui/item/linters.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package item
import (
"sort"

"github.com/k0kubun/pp"

"github.com/nakabonne/golintui/pkg/golangcilint/config"

"github.com/gdamore/tcell"
Expand Down Expand Up @@ -32,7 +34,7 @@ func NewLinters(linters []config.Linter) *Linters {
return l
}

func (l *Linters) SetKeybinds(globalKeybind func(event *tcell.EventKey), selectAction, unselectAction func(*tview.TreeNode, *config.Linter)) {
func (l *Linters) SetKeybinds(globalKeybind func(event *tcell.EventKey), selectAction func(*tview.TreeNode, *config.Linter), unselectAction func(*tview.TreeNode, *config.Linter) error) {
l.SetSelectedFunc(func(node *tview.TreeNode) {
ref, ok := node.GetReference().(config.Linter)
if !ok {
Expand All @@ -41,7 +43,9 @@ func (l *Linters) SetKeybinds(globalKeybind func(event *tcell.EventKey), selectA
// TODO: Use ref.Enable() to check if enabled.
// For that, be sure to populate a pointer to linter to the reference.
if node.GetColor() == EnabledLinterColor {
unselectAction(node, &ref)
if err := unselectAction(node, &ref); err != nil {
pp.Println(err) // TODO: Replace popup
}
} else {
selectAction(node, &ref)
}
Expand Down

0 comments on commit 6a71936

Please sign in to comment.