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 28
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 35
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 41
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 51
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 23
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 73
def annotate_message(msg)
  msg.gsub(/`(.*?)`/m, yellow('\1'))
end
colored_severity_code(offense) click to toggle source
# File lib/rubocop/formatter/simple_text_formatter.rb, line 68
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 63
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 77
def message(offense)
  message = offense.corrected? ? green('[Corrected] ') : ''
  "#{message}#{annotate_message(offense.message)}"
end