Sha256: 9a3b553b1a872dfc7fa5b384712aa046516d4dec8825af0497afdafeecd4d944

Contents?: true

Size: 1.56 KB

Versions: 28

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

require 'codeclimate_engine'
require_relative 'code_climate_configuration'

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,
                            fingerprint: fingerprint,
                            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 fingerprint
        CodeClimateFingerprint.new(warning).compute
      end

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

      def configuration
        @configuration ||= begin
          CodeClimateConfiguration.load
        end
      end
    end
  end
end

Version data entries

28 entries across 26 versions & 2 rubygems

Version Path
reek-6.0.3 lib/reek/report/code_climate/code_climate_formatter.rb
reek-6.0.2 lib/reek/report/code_climate/code_climate_formatter.rb
reek-6.0.1 lib/reek/report/code_climate/code_climate_formatter.rb
reek-6.0.0 lib/reek/report/code_climate/code_climate_formatter.rb
reek-5.6.0 lib/reek/report/code_climate/code_climate_formatter.rb
reek-5.5.0 lib/reek/report/code_climate/code_climate_formatter.rb
reek-5.4.1 lib/reek/report/code_climate/code_climate_formatter.rb
reek-5.4.0 lib/reek/report/code_climate/code_climate_formatter.rb
reek-5.3.2 lib/reek/report/code_climate/code_climate_formatter.rb
reek-5.3.1 lib/reek/report/code_climate/code_climate_formatter.rb
reek-5.3.0 lib/reek/report/code_climate/code_climate_formatter.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/report/code_climate/code_climate_formatter.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/report/code_climate/code_climate_formatter.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/report/code_climate/code_climate_formatter.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/report/code_climate/code_climate_formatter.rb
reek-5.2.0 lib/reek/report/code_climate/code_climate_formatter.rb
reek-5.1.0 lib/reek/report/code_climate/code_climate_formatter.rb
reek-5.0.2 lib/reek/report/code_climate/code_climate_formatter.rb
reek-5.0.1 lib/reek/report/code_climate/code_climate_formatter.rb
reek-5.0.0 lib/reek/report/code_climate/code_climate_formatter.rb