class RuboCop::Formatter::RedmineWikiFormatter

A Redmine wiki formatter that displays only files with offenses.

Public Instance Methods

file_finished(file, offenses) click to toggle source
# File lib/rubocop/formatter/redmine_wiki_formatter.rb, line 15
def file_finished(file, offenses)
  @files << file
  return if offenses.empty?
  @total_offense_file_count += 1
  count_stats(offenses)
  report_file(file, offenses)
end
finished(inspected_files) click to toggle source
# File lib/rubocop/formatter/redmine_wiki_formatter.rb, line 23
def finished(inspected_files)
  output.printf("h2. Summary\r\n\r\n")
  output.printf("* Generated on %s\r\n", DateTime.now)
  output.printf("* %s inspected, %s detected in %s\r\n", 
    pluralize(@files.count, 'file'), 
    pluralize(@total_offense_count, 'offense', no_for_zero: true),
    pluralize(@total_offense_file_count, 'file'))
end
report_file(file, offenses) click to toggle source
# File lib/rubocop/formatter/redmine_wiki_formatter.rb, line 32
def report_file(file, offenses)
  output.puts("h2. #{smart_path(file)} - #{pluralize(offenses.count, 'offense')}\r\n\r\n")

  offenses.each do |o|
    output.printf("h3. Line %d, Column %d\r\n\r\n%s\r\n", o.line, o.real_column, message(o))
    output.printf("<pre><code>%s</code></pre>\r\n\r\n", o.location.source_line)
  end
  output.printf("\r\n")
end
started(_target_files) click to toggle source
# File lib/rubocop/formatter/redmine_wiki_formatter.rb, line 7
def started(_target_files)
  @files = []
  @total_offense_file_count = 0
  @total_offense_count = 0
  @total_correction_count = 0
  output.printf("h1. RuboCop (version %s) Inspection Report\r\n\r\n", RuboCop::Version::STRING)
end

Private Instance Methods

count_stats(offenses) click to toggle source
# File lib/rubocop/formatter/redmine_wiki_formatter.rb, line 44
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/redmine_wiki_formatter.rb, line 60
def message(offense)
  message = offense.corrected? ? '[Corrected] ' : ''
  message << offense.message
end
smart_path(path) click to toggle source
# File lib/rubocop/formatter/redmine_wiki_formatter.rb, line 49
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