class CC::Config::Validation::YAML

Private Instance Methods

deprecate_key(key, new_key = nil) click to toggle source
# File lib/cc/config/validation/yaml.rb, line 53
def deprecate_key(key, new_key = nil)
  if data.key?(key)
    warnings <<
      if new_key.nil?
        "'#{key}' has been deprecated, and will not be used"
      else
        "'#{key}' has been deprecated, please use '#{new_key}' instead"
      end
  end
end
deprecated_key_warnings() click to toggle source
# File lib/cc/config/validation/yaml.rb, line 46
def deprecated_key_warnings
  deprecate_key("engines", "plugins")
  deprecate_key("exclude_paths", "exclude_patterns")
  deprecate_key("languages")
  deprecate_key("ratings")
end
validate() click to toggle source
# File lib/cc/config/validation/yaml.rb, line 7
def validate
  @data = ::YAML.safe_load(File.read(path))

  return unless validate_hash_data

  validate_version
  validate_prepare

  validate_one_of(%w[engines plugins])
  validate_one_of(%w[exclude_paths exclude_patterns])

  validate_engines("engines", legacy: true)
  validate_engines("plugins")

  validate_checks

  validate_exclude_pattern("exclude_patterns")
  validate_exclude_pattern("exclude_paths", legacy: true)

  deprecated_key_warnings
  warn_unrecognized_keys(%w[checks prepare engines plugins ratings languages exclude_paths exclude_patterns version])
rescue Psych::SyntaxError => ex
  errors << "Unable to parse: #{ex.message}"
end
validate_one_of(keys) click to toggle source
# File lib/cc/config/validation/yaml.rb, line 38
def validate_one_of(keys)
  num = keys.map { |k| data.key?(k) }.select(&:present?).count
  if num > 1
    wrapped_keys = keys.map { |k| "'#{k}'" }
    errors << "only use one of #{wrapped_keys.join(", ")}"
  end
end
validate_version() click to toggle source
# File lib/cc/config/validation/yaml.rb, line 32
def validate_version
  if !data.key?("version") && (data.key?("plugins") || data.key?("exclude_patterns"))
    warnings << %(missing 'version' key. Please add `version: "2"`)
  end
end