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.6.3 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.6.2 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.6.1 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.6.0 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.5.0 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.4.4 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.4.3 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.4.1 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.4.0 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.3.2 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.3.1 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.3.0 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.2.12 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.2.11 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.2.9 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.2.7 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.2.6 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.2.4 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.2.2 lib/cc/analyzer/issue_sorter.rb
codeclimate-0.2.1 lib/cc/analyzer/issue_sorter.rb