lib/reek/cli/report/formatter.rb in reek-1.6.6 vs lib/reek/cli/report/formatter.rb in reek-2.0.0
- old
+ new
@@ -1,10 +1,16 @@
+require 'reek/cli/report/location_formatter'
+
module Reek
module Cli
module Report
+ #
+ # Formatter handling the formatting of the report at large. Formatting
+ # the individual warnings is handled by the warning formatter passed in.
+ #
module Formatter
- def self.format_list(warnings, formatter = SimpleWarningFormatter)
+ def self.format_list(warnings, formatter = SimpleWarningFormatter.new)
warnings.map do |warning|
" #{formatter.format warning}"
end.join("\n")
end
@@ -15,44 +21,47 @@
result += Rainbow('s').yellow unless count == 1
result
end
end
- module UltraVerboseWarningFormattter
- BASE_URL_FOR_HELP_LINK = 'https://github.com/troessner/reek/wiki/'
+ #
+ # Basic formatter that just shows a simple message for each warning,
+ # pre-pended with the result of the passed-in location formatter.
+ #
+ class SimpleWarningFormatter
+ def initialize(location_formatter = BlankLocationFormatter)
+ @location_formatter = location_formatter
+ end
- module_function
-
def format(warning)
- "#{WarningFormatterWithLineNumbers.format(warning)} " \
- "[#{explanatory_link(warning)}]"
+ "#{@location_formatter.format(warning)}#{base_format(warning)}"
end
- def explanatory_link(warning)
- "#{BASE_URL_FOR_HELP_LINK}#{class_name_to_param(warning.smell_type)}"
- end
+ private
- def class_name_to_param(name)
- name.split(/(?=[A-Z])/).join('-')
+ def base_format(warning)
+ "#{warning.context} #{warning.message} (#{warning.smell_type})"
end
end
- module SimpleWarningFormatter
- def self.format(warning)
- "#{warning.context} #{warning.message} (#{warning.smell_type})"
+ #
+ # 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
- end
- module WarningFormatterWithLineNumbers
- def self.format(warning)
- "#{warning.lines.inspect}:#{SimpleWarningFormatter.format(warning)}"
+ def explanatory_link(warning)
+ "#{BASE_URL_FOR_HELP_LINK}#{class_name_to_param(warning.smell_type)}"
end
- end
- module SingleLineWarningFormatter
- def self.format(warning)
- "#{warning.source}:#{warning.lines.first}: " \
- "#{SimpleWarningFormatter.format(warning)}"
+ def class_name_to_param(name)
+ name.split(/(?=[A-Z])/).join('-')
end
end
end
end
end