Sha256: c12de8883f30e5111ffc288c9fea324f110116c432bd03f8b192560cb8f098c6

Contents?: true

Size: 1.01 KB

Versions: 14

Compression:

Stored size: 1.01 KB

Contents

module CC
  module Analyzer
    class IssueLocationFormatValidation < 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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
codeclimate-0.34.1 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.34.0 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.33.0 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.32.1 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.32.0 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.32.0.rc1 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.31.1 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.31.0 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.30.1 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.30.0 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.29.0 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.28.0 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.27.2 lib/cc/analyzer/issue_location_format_validation.rb
codeclimate-0.27.1 lib/cc/analyzer/issue_location_format_validation.rb