Sha256: 0d8147913bc81ae9c0b33b232c79027df461b8522db0bf3cd3c1d643486a8da6

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

require 'reek/cli/report/location_formatter'

module Reek
  module Cli
    module Report
      #
      # Formatter handling the formatting of the report at large.
      # Formatting of the individual warnings is handled by the
      # passed-in warning formatter.
      #
      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.
      #
      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.
      #
      class WikiLinkWarningFormatter < SimpleWarningFormatter
        BASE_URL_FOR_HELP_LINK = 'https://github.com/troessner/reek/wiki/'

        def format(warning)
          "#{super} " \
            "[#{explanatory_link(warning)}]"
        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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reek-2.0.4 lib/reek/cli/report/formatter.rb
reek-2.0.3 lib/reek/cli/report/formatter.rb