Skip to content

Commit cc53468

Browse files
committed
#13: fix --fast option: allow enable disabled by --fast linters
1 parent 45de6fd commit cc53468

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

pkg/commands/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func (e *Executor) executeRun(cmd *cobra.Command, args []string) {
320320
}
321321

322322
func (e *Executor) parseConfig(cmd *cobra.Command) {
323-
// XXX: hack with double parsing to acces "config" option here
323+
// XXX: hack with double parsing to access "config" option here
324324
if err := cmd.ParseFlags(os.Args); err != nil {
325325
if err == pflag.ErrHelp {
326326
return

pkg/enabled_linters.go

+27-9
Original file line numberDiff line numberDiff line change
@@ -309,20 +309,16 @@ func getEnabledLintersSet(cfg *config.Config) map[string]Linter { // nolint:gocy
309309
resultLintersSet = lintersToMap(getAllEnabledByDefaultLinters())
310310
}
311311

312-
for _, name := range lcfg.Enable {
313-
resultLintersSet[name] = getLinterByName(name)
314-
}
315-
312+
// --presets can only add linters to default set
316313
for _, p := range lcfg.Presets {
317314
for _, linter := range GetAllLintersForPreset(p) {
318315
resultLintersSet[linter.Name()] = linter
319316
}
320317
}
321318

322-
for _, name := range lcfg.Disable {
323-
delete(resultLintersSet, name)
324-
}
325-
319+
// --fast removes slow linters from current set.
320+
// It should be after --presets to be able to run only fast linters in preset.
321+
// It should be before --enable and --disable to be able to enable or disable specific linter.
326322
if lcfg.Fast {
327323
for name := range resultLintersSet {
328324
if GetLinterConfig(name).DoesFullImport {
@@ -331,6 +327,14 @@ func getEnabledLintersSet(cfg *config.Config) map[string]Linter { // nolint:gocy
331327
}
332328
}
333329

330+
for _, name := range lcfg.Enable {
331+
resultLintersSet[name] = getLinterByName(name)
332+
}
333+
334+
for _, name := range lcfg.Disable {
335+
delete(resultLintersSet, name)
336+
}
337+
334338
return resultLintersSet
335339
}
336340

@@ -384,6 +388,20 @@ func GetEnabledLinters(cfg *config.Config) ([]Linter, error) {
384388
return resultLinters, nil
385389
}
386390

391+
func uniqStrings(ss []string) []string {
392+
us := map[string]bool{}
393+
for _, s := range ss {
394+
us[s] = true
395+
}
396+
397+
var ret []string
398+
for k := range us {
399+
ret = append(ret, k)
400+
}
401+
402+
return ret
403+
}
404+
387405
func verbosePrintLintersStatus(cfg *config.Config, linters []Linter) {
388406
var linterNames []string
389407
for _, linter := range linters {
@@ -392,6 +410,6 @@ func verbosePrintLintersStatus(cfg *config.Config, linters []Linter) {
392410
logrus.Infof("Active linters: %s", linterNames)
393411

394412
if len(cfg.Linters.Presets) != 0 {
395-
logrus.Infof("Active presets: %s", cfg.Linters.Presets)
413+
logrus.Infof("Active presets: %s", uniqStrings(cfg.Linters.Presets))
396414
}
397415
}

0 commit comments

Comments
 (0)