Sha256: ffe6aa0c4bde776d6d2b993cd9d7c56c47bc78b1701a68ca9bf2e35bd34c7fdc

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

require 'private_attr/everywhere'
require_relative 'location_formatter'

module Reek
  module Report
    #
    # Formatter handling the formatting of the report at large.
    # Formatting of the individual warnings is handled by the
    # passed-in warning formatter.
    #
    # @api private
    module Formatter
      def self.format_list(warnings, formatter: SimpleWarningFormatter.new)
        warnings.map do |warning|
          "  #{formatter.format warning}"
        end.join("\n")
      end

      def self.header(examiner)
        count = examiner.smells_count
        result = Rainbow("#{examiner.description} -- ").cyan +
          Rainbow("#{count} warning").yellow
        result += Rainbow('s').yellow unless count == 1
        result
      end
    end

    #
    # Basic formatter that just shows a simple message for each warning,
    # prepended with the result of the passed-in location formatter.
    #
    # @api private
    class SimpleWarningFormatter
      def initialize(location_formatter: BlankLocationFormatter)
        @location_formatter = location_formatter
      end

      def format(warning)
        "#{location_formatter.format(warning)}#{base_format(warning)}"
      end

      private

      def base_format(warning)
        "#{warning.context} #{warning.message} (#{warning.smell_type})"
      end

      private

      private_attr_reader :location_formatter
    end

    #
    # Formatter that adds a link to the wiki to the basic message from
    # SimpleWarningFormatter.
    #
    # @api private
    class WikiLinkWarningFormatter < SimpleWarningFormatter
      BASE_URL_FOR_HELP_LINK = 'https://github.com/troessner/reek/blob/master/docs/'

      def format(warning)
        "#{super} " \
          "[#{explanatory_link(warning)}.md]"
      end

      def explanatory_link(warning)
        "#{BASE_URL_FOR_HELP_LINK}#{class_name_to_param(warning.smell_type)}"
      end

      def class_name_to_param(name)
        name.split(/(?=[A-Z])/).join('-')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reek-3.3.1 lib/reek/report/formatter.rb