Validate gocritic settings. Return error if settings includes a unsupported gocritic checker (#1563)
This commit is contained in:
parent
cfbbead393
commit
62710a8d97
@ -242,13 +242,7 @@ func (s *GocriticSettings) Validate(log logutils.Log) error {
|
|||||||
return errors.Wrap(err, "validate disabled checks")
|
return errors.Wrap(err, "validate disabled checks")
|
||||||
}
|
}
|
||||||
|
|
||||||
for checkName := range s.SettingsPerCheck {
|
if err := s.validateCheckerNames(log); err != nil {
|
||||||
if !s.IsCheckEnabled(checkName) {
|
|
||||||
log.Warnf("Gocritic settings were provided for not enabled check %q", checkName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.validateCheckerNames(); err != nil {
|
|
||||||
return errors.Wrap(err, "validation failed")
|
return errors.Wrap(err, "validation failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,6 +266,7 @@ func sprintStrings(ss []string) string {
|
|||||||
return fmt.Sprint(ss)
|
return fmt.Sprint(ss)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getAllCheckerNames returns a map containing all checker names supported by gocritic.
|
||||||
func getAllCheckerNames() map[string]bool {
|
func getAllCheckerNames() map[string]bool {
|
||||||
allCheckerNames := map[string]bool{}
|
allCheckerNames := map[string]bool{}
|
||||||
for _, checker := range allGocriticCheckers {
|
for _, checker := range allGocriticCheckers {
|
||||||
@ -311,7 +306,7 @@ func getDefaultDisabledGocriticCheckersNames() []string {
|
|||||||
return disabled
|
return disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GocriticSettings) validateCheckerNames() error {
|
func (s *GocriticSettings) validateCheckerNames(log logutils.Log) error {
|
||||||
allowedNames := getAllCheckerNames()
|
allowedNames := getAllCheckerNames()
|
||||||
|
|
||||||
for _, name := range s.EnabledChecks {
|
for _, name := range s.EnabledChecks {
|
||||||
@ -328,6 +323,16 @@ func (s *GocriticSettings) validateCheckerNames() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for checkName := range s.SettingsPerCheck {
|
||||||
|
if _, ok := allowedNames[checkName]; !ok {
|
||||||
|
return fmt.Errorf("invalid setting, checker %s doesn't exist, all existing checkers: %s",
|
||||||
|
checkName, sprintAllowedCheckerNames(allowedNames))
|
||||||
|
}
|
||||||
|
if !s.IsCheckEnabled(checkName) {
|
||||||
|
log.Warnf("Gocritic settings were provided for not enabled check %q", checkName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user