Support disable rule when enable-all is true

Similar to the behavior of command line flags:
enable-all to enable existing linters then disable unwanted ones.
But for vet rules.
This commit is contained in:
ferhat elmas 2020-03-11 17:20:25 +01:00
parent 76a82c6ed1
commit 4d367808be
2 changed files with 6 additions and 0 deletions

View File

@ -101,6 +101,11 @@ var (
func isAnalyzerEnabled(name string, cfg *config.GovetSettings, defaultAnalyzers []*analysis.Analyzer) bool { func isAnalyzerEnabled(name string, cfg *config.GovetSettings, defaultAnalyzers []*analysis.Analyzer) bool {
if cfg.EnableAll { if cfg.EnableAll {
for _, n := range cfg.Disable {
if n == name {
return false
}
}
return true return true
} }
// Raw for loops should be OK on small slice lengths. // Raw for loops should be OK on small slice lengths.

View File

@ -79,6 +79,7 @@ func TestGovetAnalyzerIsEnabled(t *testing.T) {
{Name: "bools", Enabled: false, Disable: []string{"bools"}}, {Name: "bools", Enabled: false, Disable: []string{"bools"}},
{Name: "unsafeptr", Enabled: true, Enable: []string{"unsafeptr"}}, {Name: "unsafeptr", Enabled: true, Enable: []string{"unsafeptr"}},
{Name: "shift", Enabled: true, EnableAll: true}, {Name: "shift", Enabled: true, EnableAll: true},
{Name: "shadow", EnableAll: true, Disable: []string{"shadow"}, Enabled: false},
} { } {
cfg := &config.GovetSettings{ cfg := &config.GovetSettings{
Enable: tc.Enable, Enable: tc.Enable,