Merge pull request #16 from golangci/feature/fix-fast-option
#13: fix --fast option: allow enable disabled by --fast linters
This commit is contained in:
commit
bbd28f4618
@ -320,7 +320,7 @@ func (e *Executor) executeRun(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) parseConfig(cmd *cobra.Command) {
|
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 := cmd.ParseFlags(os.Args); err != nil {
|
||||||
if err == pflag.ErrHelp {
|
if err == pflag.ErrHelp {
|
||||||
return
|
return
|
||||||
|
@ -309,20 +309,16 @@ func getEnabledLintersSet(cfg *config.Config) map[string]Linter { // nolint:gocy
|
|||||||
resultLintersSet = lintersToMap(getAllEnabledByDefaultLinters())
|
resultLintersSet = lintersToMap(getAllEnabledByDefaultLinters())
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, name := range lcfg.Enable {
|
// --presets can only add linters to default set
|
||||||
resultLintersSet[name] = getLinterByName(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, p := range lcfg.Presets {
|
for _, p := range lcfg.Presets {
|
||||||
for _, linter := range GetAllLintersForPreset(p) {
|
for _, linter := range GetAllLintersForPreset(p) {
|
||||||
resultLintersSet[linter.Name()] = linter
|
resultLintersSet[linter.Name()] = linter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, name := range lcfg.Disable {
|
// --fast removes slow linters from current set.
|
||||||
delete(resultLintersSet, name)
|
// 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 {
|
if lcfg.Fast {
|
||||||
for name := range resultLintersSet {
|
for name := range resultLintersSet {
|
||||||
if GetLinterConfig(name).DoesFullImport {
|
if GetLinterConfig(name).DoesFullImport {
|
||||||
@ -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
|
return resultLintersSet
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,6 +388,20 @@ func GetEnabledLinters(cfg *config.Config) ([]Linter, error) {
|
|||||||
return resultLinters, nil
|
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) {
|
func verbosePrintLintersStatus(cfg *config.Config, linters []Linter) {
|
||||||
var linterNames []string
|
var linterNames []string
|
||||||
for _, linter := range linters {
|
for _, linter := range linters {
|
||||||
@ -392,6 +410,6 @@ func verbosePrintLintersStatus(cfg *config.Config, linters []Linter) {
|
|||||||
logrus.Infof("Active linters: %s", linterNames)
|
logrus.Infof("Active linters: %s", linterNames)
|
||||||
|
|
||||||
if len(cfg.Linters.Presets) != 0 {
|
if len(cfg.Linters.Presets) != 0 {
|
||||||
logrus.Infof("Active presets: %s", cfg.Linters.Presets)
|
logrus.Infof("Active presets: %s", uniqStrings(cfg.Linters.Presets))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user