Sha256: c27d757bf7803b300d9449e192f1ca6544a2e7d9a203b267abcad534474a90fa

Contents?: true

Size: 1.09 KB

Versions: 8

Compression:

Stored size: 1.09 KB

Contents

require 'codeclimate_engine'
require 'private_attr'

module Reek
  module Report
    # Generates a hash in the structure specified by the Code Climate engine spec
    class CodeClimateFormatter
      private_attr_reader :warning

      def initialize(warning)
        @warning = warning
      end

      def to_hash
        CCEngine::Issue.new(check_name: check_name,
                            description: description,
                            categories: categories,
                            location: location
                           ).to_hash
      end

      private

      def description
        [warning.context, warning.message].join(' ')
      end

      def check_name
        [warning.smell_category, warning.smell_type].join('/')
      end

      def categories
        # TODO: provide mappings for Reek's smell categories
        ['Complexity']
      end

      def location
        warning_lines = warning.lines
        CCEngine::Location::LineRange.new(
          path: warning.source,
          line_range: warning_lines.first..warning_lines.last
        )
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reek-3.9.1 lib/reek/report/code_climate_formatter.rb
reek-3.9.0 lib/reek/report/code_climate_formatter.rb
reek-3.8.3 lib/reek/report/code_climate_formatter.rb
reek-3.8.2 lib/reek/report/code_climate_formatter.rb
reek-3.8.1 lib/reek/report/code_climate_formatter.rb
reek-3.8.0 lib/reek/report/code_climate_formatter.rb
reek-3.7.1 lib/reek/report/code_climate_formatter.rb
reek-3.7.0 lib/reek/report/code_climate_formatter.rb