diff --git a/lib/rubocop/config_loader.rb b/lib/rubocop/config_loader.rb index df106e325ded..9f969fdc21b8 100644 --- a/lib/rubocop/config_loader.rb +++ b/lib/rubocop/config_loader.rb @@ -217,8 +217,6 @@ def load_yaml_configuration(absolute_path) raise(TypeError, "Malformed configuration in #{absolute_path}") end - check_cop_config_value(hash) - hash end @@ -240,24 +238,6 @@ def check_duplication(yaml_code, absolute_path) end end - def check_cop_config_value(hash, parent = nil) - hash.each do |key, value| - check_cop_config_value(value, key) if value.is_a?(Hash) - - next unless %w[Enabled - Safe - SafeAutoCorrect - AutoCorrect].include?(key) && value.is_a?(String) - - next if key == 'Enabled' && value == 'pending' - - abort( - "Property #{Rainbow(key).yellow} of cop #{Rainbow(parent).yellow}" \ - " is supposed to be a boolean and #{Rainbow(value).yellow} is not." - ) - end - end - # Read the specified file, or exit with a friendly, concise message on # stderr. Care is taken to use the standard OS exit code for a "file not # found" error. diff --git a/lib/rubocop/config_validator.rb b/lib/rubocop/config_validator.rb index c4514d1e4e94..012f12028965 100644 --- a/lib/rubocop/config_validator.rb +++ b/lib/rubocop/config_validator.rb @@ -32,7 +32,9 @@ def initialize(config) end def validate - # Don't validate RuboCop's own files. Avoids infinite recursion. + check_cop_config_value(@config) + + # Don't validate RuboCop's own files further. Avoids infinite recursion. return if @config.internal? valid_cop_names, invalid_cop_names = @config.keys.partition do |key| @@ -244,5 +246,27 @@ def reject_mutually_exclusive_defaults msg = 'Cops cannot be both enabled by default and disabled by default' raise ValidationError, msg end + + def check_cop_config_value(hash, parent = nil) + hash.each do |key, value| + check_cop_config_value(value, key) if value.is_a?(Hash) + + next unless %w[Enabled + Safe + SafeAutoCorrect + AutoCorrect].include?(key) && value.is_a?(String) + + next if key == 'Enabled' && value == 'pending' + + raise ValidationError, msg_not_boolean(parent, key, value) + end + end + + # FIXME: Handling colors in exception messages like this is ugly. + def msg_not_boolean(parent, key, value) + "#{Rainbow('').reset}" \ + "Property #{Rainbow(key).yellow} of cop #{Rainbow(parent).yellow}" \ + " is supposed to be a boolean and #{Rainbow(value).yellow} is not." + end end end diff --git a/spec/rubocop/config_loader_spec.rb b/spec/rubocop/config_loader_spec.rb index d2390cc74252..0c8b5c3bf14e 100644 --- a/spec/rubocop/config_loader_spec.rb +++ b/spec/rubocop/config_loader_spec.rb @@ -1087,7 +1087,7 @@ def cop_enabled?(cop_class) expect do load_file end.to raise_error( - SystemExit, + RuboCop::ValidationError, /supposed to be a boolean and disable is not/ ) end