-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
dev: rewrite linters Manager #4419
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
Changes from 21 commits
6762019
13936c8
9789895
c9648c1
9fe1be4
cf874b4
b29e407
88342f5
c4f9898
20df06d
81badef
d30c3f2
2328668
bfd4182
cf975a4
df61470
1d822ca
1fe1894
4647f2f
3dafb43
9d196f4
45fef5d
aaef7fc
a701970
83c68d6
ad6b6e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
type Linters struct { | ||
Enable []string | ||
Disable []string | ||
|
@@ -9,3 +14,52 @@ type Linters struct { | |
|
||
Presets []string | ||
} | ||
|
||
func (l *Linters) Validate() error { | ||
if err := l.validateAllDisableEnableOptions(); err != nil { | ||
return err | ||
} | ||
|
||
if err := l.validateDisabledAndEnabledAtOneMoment(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (l *Linters) validateAllDisableEnableOptions() error { | ||
if l.EnableAll && l.DisableAll { | ||
return errors.New("--enable-all and --disable-all options must not be combined") | ||
} | ||
|
||
if l.DisableAll { | ||
if len(l.Enable) == 0 && len(l.Presets) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cosmetic: gocritic also highlights that linters were already enabled or disabled via presets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gocritic handles its own rules, not our linters or presets. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. of course, I meant checkers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I don't understand what is your suggestion here. |
||
return errors.New("all linters were disabled, but no one linter was enabled: must enable at least one") | ||
} | ||
|
||
if len(l.Disable) != 0 { | ||
return fmt.Errorf("can't combine options --disable-all and --disable %s", l.Disable[0]) | ||
ldez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
if l.EnableAll && len(l.Enable) != 0 && !l.Fast { | ||
return fmt.Errorf("can't combine options --enable-all and --enable %s", l.Enable[0]) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (l *Linters) validateDisabledAndEnabledAtOneMoment() error { | ||
enabledLintersSet := map[string]bool{} | ||
ldez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for _, name := range l.Enable { | ||
enabledLintersSet[name] = true | ||
} | ||
|
||
for _, name := range l.Disable { | ||
if enabledLintersSet[name] { | ||
return fmt.Errorf("linter %q can't be disabled and enabled at one moment", name) | ||
} | ||
} | ||
ldez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return nil | ||
} |
Uh oh!
There was an error while loading. Please reload this page.