Skip to content

#13: fix --fast option: allow enable disabled by --fast linters #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (e *Executor) executeRun(cmd *cobra.Command, args []string) {
}

func (e *Executor) parseConfig(cmd *cobra.Command) {
// XXX: hack with double parsing to acces "config" option here
// XXX: hack with double parsing to access "config" option here
if err := cmd.ParseFlags(os.Args); err != nil {
if err == pflag.ErrHelp {
return
Expand Down
36 changes: 27 additions & 9 deletions pkg/enabled_linters.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,20 +309,16 @@ func getEnabledLintersSet(cfg *config.Config) map[string]Linter { // nolint:gocy
resultLintersSet = lintersToMap(getAllEnabledByDefaultLinters())
}

for _, name := range lcfg.Enable {
resultLintersSet[name] = getLinterByName(name)
}

// --presets can only add linters to default set
for _, p := range lcfg.Presets {
for _, linter := range GetAllLintersForPreset(p) {
resultLintersSet[linter.Name()] = linter
}
}

for _, name := range lcfg.Disable {
delete(resultLintersSet, name)
}

// --fast removes slow linters from current set.
// It should be after --presets to be able to run only fast linters in preset.
// It should be before --enable and --disable to be able to enable or disable specific linter.
if lcfg.Fast {
for name := range resultLintersSet {
if GetLinterConfig(name).DoesFullImport {
Expand All @@ -331,6 +327,14 @@ func getEnabledLintersSet(cfg *config.Config) map[string]Linter { // nolint:gocy
}
}

for _, name := range lcfg.Enable {
resultLintersSet[name] = getLinterByName(name)
}

for _, name := range lcfg.Disable {
delete(resultLintersSet, name)
}

return resultLintersSet
}

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

func uniqStrings(ss []string) []string {
us := map[string]bool{}
for _, s := range ss {
us[s] = true
}

var ret []string
for k := range us {
ret = append(ret, k)
}

return ret
}

func verbosePrintLintersStatus(cfg *config.Config, linters []Linter) {
var linterNames []string
for _, linter := range linters {
Expand All @@ -392,6 +410,6 @@ func verbosePrintLintersStatus(cfg *config.Config, linters []Linter) {
logrus.Infof("Active linters: %s", linterNames)

if len(cfg.Linters.Presets) != 0 {
logrus.Infof("Active presets: %s", cfg.Linters.Presets)
logrus.Infof("Active presets: %s", uniqStrings(cfg.Linters.Presets))
}
}