123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::Formatter::HTMLFormatter

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: RuboCop::Formatter::BaseFormatter
Defined in: lib/rubocop/formatter/html_formatter.rb

Overview

This formatter saves the output as an html file.

Constant Summary

Class Method Summary

Instance Attribute Summary

BaseFormatter - Inherited

Instance Method Summary

BaseFormatter - Inherited

#file_finished

Invoked at the end of inspecting each files.

#file_started

Invoked at the beginning of inspecting each files.

#finished

Invoked after all files are inspected or interrupted by user.

#started

Invoked once before any files are inspected.

Constructor Details

.new(output, options = {}) ⇒ HTMLFormatter

[ GitHub ]

  
# File 'lib/rubocop/formatter/html_formatter.rb', line 29

def initialize(output, options = {})
  super
  @files = []
  @summary = Summary.new(offense_count: 0)
end

Instance Attribute Details

#files (readonly)

[ GitHub ]

  
# File 'lib/rubocop/formatter/html_formatter.rb', line 27

attr_reader :files, :summary

#summary (readonly)

[ GitHub ]

  
# File 'lib/rubocop/formatter/html_formatter.rb', line 27

attr_reader :files, :summary

Instance Method Details

#file_finished(file, offenses)

[ GitHub ]

  
# File 'lib/rubocop/formatter/html_formatter.rb', line 39

def file_finished(file, offenses)
  files << FileOffenses.new(path: file, offenses: offenses)
  summary.offense_count += offenses.count
end

#finished(inspected_files)

[ GitHub ]

  
# File 'lib/rubocop/formatter/html_formatter.rb', line 44

def finished(inspected_files)
  summary.inspected_files = inspected_files

  render_html
end

#render_html

[ GitHub ]

  
# File 'lib/rubocop/formatter/html_formatter.rb', line 50

def render_html
  context = ERBContext.new(files, summary)

  template = File.read(TEMPLATE_PATH, encoding: Encoding::UTF_8)
  erb = ERB.new(template)
  html = erb.result(context.binding).lines.map do |line|
    line.match?(/\A\s*\z/) ? "\n" : line
  end.join

  output.write html
end

#started(target_files)

[ GitHub ]

  
# File 'lib/rubocop/formatter/html_formatter.rb', line 35

def started(target_files)
  summary.target_files = target_files
end