class RuboCop::Formatter::SimpleTextFormatter
A basic formatter that displays only files with offenses. Offenses are displayed at compact form - just the location of the problem and the associated message.
Constants
- COLOR_FOR_SEVERITY
Public Instance Methods
file_finished(file, offenses)
click to toggle source
# File lib/rubocop/formatter/simple_text_formatter.rb, line 27 def file_finished(file, offenses) return if offenses.empty? count_stats(offenses) report_file(file, offenses) end
finished(inspected_files)
click to toggle source
# File lib/rubocop/formatter/simple_text_formatter.rb, line 33 def finished(inspected_files) report_summary(inspected_files.count, @total_offense_count, @total_correction_count) end
report_file(file, offenses)
click to toggle source
# File lib/rubocop/formatter/simple_text_formatter.rb, line 39 def report_file(file, offenses) output.puts yellow("== #{smart_path(file)} ==") offenses.each do |o| output.printf("%s:%3d:%3d: %s\n", colored_severity_code(o), o.line, o.real_column, message(o)) end end
report_summary(file_count, offense_count, correction_count)
click to toggle source
# File lib/rubocop/formatter/simple_text_formatter.rb, line 49 def report_summary(file_count, offense_count, correction_count) report = Report.new(file_count, offense_count, correction_count, rainbow) output.puts output.puts report.summary end
started(_target_files)
click to toggle source
# File lib/rubocop/formatter/simple_text_formatter.rb, line 22 def started(_target_files) @total_offense_count = 0 @total_correction_count = 0 end
Private Instance Methods
annotate_message(msg)
click to toggle source
# File lib/rubocop/formatter/simple_text_formatter.rb, line 82 def annotate_message(msg) msg.gsub(/`(.*?)`/, yellow('\1')) end
colored_severity_code(offense)
click to toggle source
# File lib/rubocop/formatter/simple_text_formatter.rb, line 77 def colored_severity_code(offense) color = COLOR_FOR_SEVERITY[offense.severity.name] colorize(offense.severity.code, color) end
count_stats(offenses)
click to toggle source
# File lib/rubocop/formatter/simple_text_formatter.rb, line 61 def count_stats(offenses) @total_offense_count += offenses.count @total_correction_count += offenses.count(&:corrected?) end
message(offense)
click to toggle source
# File lib/rubocop/formatter/simple_text_formatter.rb, line 86 def message(offense) message = offense.corrected? ? green('[Corrected] ') : '' "#{message}#{annotate_message(offense.message)}" end
smart_path(path)
click to toggle source
# File lib/rubocop/formatter/simple_text_formatter.rb, line 66 def smart_path(path) # Ideally, we calculate this relative to the project root. base_dir = Dir.pwd if path.start_with? base_dir relative_path(path, base_dir) else path end end