class RuboCop::Formatter::TapFormatter

This formatter formats report data using the Test Anything Protocol. TAP allows for to communicate tests results in a language agnostics way.

Public Instance Methods

file_finished(file, offenses) click to toggle source
# File lib/rubocop/formatter/tap_formatter.rb, line 14
def file_finished(file, offenses)
  if offenses.empty?
    output.puts "ok #{@progress_count} - #{smart_path(file)}"
  else
    output.puts "not ok #{@progress_count} - #{smart_path(file)}"

    count_stats(offenses)
    report_file(file, offenses)
  end

  @progress_count += 1
end
started(target_files) click to toggle source
Calls superclass method
# File lib/rubocop/formatter/tap_formatter.rb, line 8
def started(target_files)
  super
  @progress_count = 1
  output.puts "1..#{target_files.size}"
end

Private Instance Methods

annotate_message(msg) click to toggle source
# File lib/rubocop/formatter/tap_formatter.rb, line 66
def annotate_message(msg)
  msg.gsub(/`(.*?)`/, '\1')
end
message(offense) click to toggle source
# File lib/rubocop/formatter/tap_formatter.rb, line 70
def message(offense)
  message =
    if offense.corrected_with_todo?
      '[Todo] '
    elsif offense.corrected?
      '[Corrected] '
    elsif offense.correctable?
      '[Correctable] '
    else
      ''
    end

  "#{message}#{annotate_message(offense.message)}"
end
report_highlighted_area(highlighted_area) click to toggle source
# File lib/rubocop/formatter/tap_formatter.rb, line 39
def report_highlighted_area(highlighted_area)
  space_area  = highlighted_area.source_buffer.slice(0...highlighted_area.begin_pos)
  source_area = highlighted_area.source
  output.puts("# #{' ' * Unicode::DisplayWidth.of(space_area)}" \
              "#{'^' * Unicode::DisplayWidth.of(source_area)}")
end
report_line(location) click to toggle source
# File lib/rubocop/formatter/tap_formatter.rb, line 29
def report_line(location)
  source_line = location.source_line

  if location.single_line?
    output.puts("# #{source_line}")
  else
    output.puts("# #{source_line} #{yellow(ELLIPSES)}")
  end
end
report_offense(file, offense) click to toggle source
# File lib/rubocop/formatter/tap_formatter.rb, line 46
def report_offense(file, offense)
  output.printf(
    "# %<path>s:%<line>d:%<column>d: %<severity>s: %<message>s\n",
    path: cyan(smart_path(file)),
    line: offense.line,
    column: offense.real_column,
    severity: colored_severity_code(offense),
    message: message(offense)
  )

  begin
    return unless valid_line?(offense)

    report_line(offense.location)
    report_highlighted_area(offense.highlighted_area)
  rescue IndexError
    # range is not on a valid line; perhaps the source file is empty
  end
end