lib/rubocop/config_loader.rb in rubocop-0.74.0 vs lib/rubocop/config_loader.rb in rubocop-0.75.0
- old
+ new
@@ -197,10 +197,12 @@
unless hash.is_a?(Hash)
raise(TypeError, "Malformed configuration in #{absolute_path}")
end
+ check_cop_config_value(hash)
+
hash
end
def check_duplication(yaml_code, absolute_path)
smart_path = PathUtil.smart_path(absolute_path)
@@ -218,10 +220,26 @@
end
warn Rainbow(message).yellow
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)
+
+ 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.
def read_file(absolute_path)
IO.read(absolute_path, encoding: Encoding::UTF_8)
@@ -238,14 +256,14 @@
elsif Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
YAML.safe_load(
yaml_code,
permitted_classes: [Regexp, Symbol],
permitted_symbols: [],
- aliases: false,
+ aliases: true,
filename: filename
)
else
- YAML.safe_load(yaml_code, [Regexp, Symbol], [], false, filename)
+ YAML.safe_load(yaml_code, [Regexp, Symbol], [], true, filename)
end
end
end
# Initializing class ivars