Sha256: c68edf010625df84058fe39b26999421685584d47ed8d578dcab4e5662ea7e62

Contents?: true

Size: 824 Bytes

Versions: 64

Compression:

Stored size: 824 Bytes

Contents

module CC
  module Analyzer
    class IssueSorter
      def initialize(issues)
        @issues = issues
      end

      def by_location
        @issues.sort_by { |i| line_or_offset(i) }
      end

      private

      def line_or_offset(issue)
        location = issue["location"]

        case
        when location["lines"]
          location["lines"]["begin"].to_i
        when location["positions"] && location["positions"]["begin"]["line"]
          location["positions"]["begin"]["line"].to_i + location["positions"]["begin"]["column"].to_i
        when location["positions"] && location["positions"]["begin"]["offset"]
          location["positions"]["begin"]["offset"].to_i + 1_000_000_000 # push offsets to end of list
        else
          0 # whole-file issues are first
        end
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
codeclimate-0.14.2 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.14.1 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.14.0 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.13.0 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.11.0 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.10.1 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.10.0 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.9.7 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.9.6 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.9.5 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.9.4 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.9.3 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.9.2 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.9.1 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.9.0 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.8.1 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.8.0 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.7.2 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.7.0 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.6.4 lib/cc/analyzer/issue_sorter.rb