Sha256: 6e819d59fcd12ee3b96140b383b9dcb9165684075d0c0157fbcac10e474f3134

Contents?: true

Size: 1.93 KB

Versions: 95

Compression:

Stored size: 1.93 KB

Contents

module CC
  class Config
    module Validation
      class YAML < FileValidator
        private

        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

        def validate_version
          if !data.key?("version") && (data.key?("plugins") || data.key?("exclude_patterns"))
            warnings << %(missing 'version' key. Please add `version: "2"`)
          end
        end

        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

        def deprecated_key_warnings
          deprecate_key("engines", "plugins")
          deprecate_key("exclude_paths", "exclude_patterns")
          deprecate_key("languages")
          deprecate_key("ratings")
        end

        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
      end
    end
  end
end

Version data entries

95 entries across 95 versions & 2 rubygems

Version Path
codeclimate-0.85.27 lib/cc/config/validation/yaml.rb
codeclimate-0.85.26 lib/cc/config/validation/yaml.rb
codeclimate-0.85.25 lib/cc/config/validation/yaml.rb
codeclimate-0.85.24 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.54 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.53 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.52 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.51 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.50 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.49 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.48 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.47 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.46 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.45 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.44 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.43 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.42 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.41 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.40 lib/cc/config/validation/yaml.rb
codeclimate-fede-0.85.39 lib/cc/config/validation/yaml.rb