Sha256: dad9861f319031abab92db94033412acf2e1a96d4948b0d77969ea1c1d9b98d5

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

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
    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

3 entries across 3 versions & 1 rubygems

Version Path
reek-3.2.1 lib/reek/report/formatter.rb
reek-3.1 lib/reek/report/formatter.rb
reek-3.0.4 lib/reek/report/formatter.rb