class RuboCop::Formatter::HTMLFormatter

This formatter saves the output as an html file.

Constants

Color
ELLIPSES
TEMPLATE_PATH

Attributes

files[R]
summary[R]

Public Class Methods

new(output, options = {}) click to toggle source
Calls superclass method RuboCop::Formatter::BaseFormatter::new
# File lib/rubocop/formatter/html_formatter.rb, line 31
def initialize(output, options = {})
  super
  @files = []
  @summary = OpenStruct.new(offense_count: 0)
end

Public Instance Methods

file_finished(file, offenses) click to toggle source
# File lib/rubocop/formatter/html_formatter.rb, line 41
def file_finished(file, offenses)
  files << OpenStruct.new(path: file, offenses: offenses)
  summary.offense_count += offenses.count
end
finished(inspected_files) click to toggle source
# File lib/rubocop/formatter/html_formatter.rb, line 46
def finished(inspected_files)
  summary.inspected_files = inspected_files

  render_html
end
render_html() click to toggle source
# File lib/rubocop/formatter/html_formatter.rb, line 52
def render_html
  context = ERBContext.new(files, summary)

  template = File.read(TEMPLATE_PATH, encoding: Encoding::UTF_8)

  # The following condition is workaround for until Ruby 2.6 is released.
  # https://github.com/ruby/ruby/commit/cc777d09f44fa909a336ba14f3aa802ffe16e010
  erb = if RUBY_VERSION >= '2.6'
          ERB.new(template, trim_mode: '-')
        else
          ERB.new(template, nil, '-')
        end
  html = erb.result(context.binding)

  output.write html
end
started(target_files) click to toggle source
# File lib/rubocop/formatter/html_formatter.rb, line 37
def started(target_files)
  summary.target_files = target_files
end