Sha256: 75f1310f3a62bb0763818b690a8c354341123745d9fe3bad679da8f923098332

Contents?: true

Size: 1.11 KB

Versions: 48

Compression:

Stored size: 1.11 KB

Contents

module CC
  module Analyzer
    module IssueValidations
      class LocationFormatValidation < Validation
        def valid?
          if location["lines"]
            valid_lines?(location["lines"])
          elsif location["positions"]
            valid_positions?(location["positions"])
          else
            false
          end
        end

        def message
          "Location is not formatted correctly"
        end

        private

        def location
          @location ||= object.fetch("location", {})
        end

        def valid_positions?(positions)
          positions.is_a?(Hash) &&
            valid_position?(positions["begin"]) &&
            valid_position?(positions["end"])
        end

        def valid_position?(position)
          position &&
            (
              [position["line"], position["column"]].all? { |value| value.is_a?(Integer) } ||
              position["offset"].is_a?(Integer)
            )
        end

        def valid_lines?(lines)
          lines.is_a?(Hash) && [lines["begin"], lines["end"]].all? { |value| value.is_a?(Integer) }
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
codeclimate-0.63.5 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.63.4 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.63.3 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.63.2 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.63.1 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.63.0 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.62.0 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.61.1 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.61.0 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.60.1 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.60.0 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.59.1 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.59.0 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.58.0 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.57.0 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.56.0 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.55.0 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.54.0 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.53.0 lib/cc/analyzer/issue_validations/location_format_validation.rb
codeclimate-0.52.0 lib/cc/analyzer/issue_validations/location_format_validation.rb