Sha256: 5d4a49d86f649657d3c648c2f4338f5f904430274702ef03c0533e2e191e8fda

Contents?: true

Size: 1.46 KB

Versions: 11

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true
require 'codeclimate_engine'

module Reek
  module Report
    # Generates a hash in the structure specified by the Code Climate engine spec
    class CodeClimateFormatter
      def initialize(warning)
        @warning = warning
      end

      def render
        CCEngine::Issue.new(check_name: check_name,
                            description: description,
                            categories: categories,
                            location: location,
                            remediation_points: remediation_points,
                            content: content).render
      end

      private

      attr_reader :warning

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

      def check_name
        warning.smell_type
      end

      def 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

      def remediation_points
        configuration[warning.smell_type].fetch('remediation_points')
      end

      def content
        configuration[warning.smell_type].fetch('content')
      end

      def configuration
        @configuration ||= begin
          config_file = File.expand_path('../code_climate_configuration.yml', __FILE__)
          YAML.load_file config_file
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
reek-4.4.2 lib/reek/report/code_climate/code_climate_formatter.rb
reek-4.4.1 lib/reek/report/code_climate/code_climate_formatter.rb
reek-4.4.0 lib/reek/report/code_climate/code_climate_formatter.rb
reek-4.3.0 lib/reek/report/code_climate/code_climate_formatter.rb
reek-4.2.5 lib/reek/report/code_climate/code_climate_formatter.rb
reek-4.2.4 lib/reek/report/code_climate/code_climate_formatter.rb
reek-4.2.3 lib/reek/report/code_climate/code_climate_formatter.rb
reek-4.2.2 lib/reek/report/code_climate/code_climate_formatter.rb
reek-4.2.1 lib/reek/report/code_climate/code_climate_formatter.rb
reek-4.2.0 lib/reek/report/code_climate/code_climate_formatter.rb
reek-4.1.1 lib/reek/report/code_climate/code_climate_formatter.rb