Class: RuboCop::Formatter::ExtensionReviewFormatter

Inherits:
BaseFormatter
  • Object
show all
Defined in:
lib/rubocop/sketchup/formatter/extension_review.rb

Overview

This formatter saves the output as an html file.

Defined Under Namespace

Classes: Color, ERBContext

Constant Summary collapse

ELLIPSES =
'<span class="extra-code">...</span>'.freeze
TEMPLATE_PATH =
File.expand_path('../../../../../assets/output.html.erb', __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, options = {}) ⇒ ExtensionReviewFormatter

Returns a new instance of ExtensionReviewFormatter.


31
32
33
34
35
36
# File 'lib/rubocop/sketchup/formatter/extension_review.rb', line 31

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

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories


29
30
31
# File 'lib/rubocop/sketchup/formatter/extension_review.rb', line 29

def categories
  @categories
end

#filesObject (readonly)

Returns the value of attribute files


29
30
31
# File 'lib/rubocop/sketchup/formatter/extension_review.rb', line 29

def files
  @files
end

#summaryObject (readonly)

Returns the value of attribute summary


29
30
31
# File 'lib/rubocop/sketchup/formatter/extension_review.rb', line 29

def summary
  @summary
end

Instance Method Details

#file_finished(file, offenses) ⇒ Object


42
43
44
45
46
47
48
49
50
# File 'lib/rubocop/sketchup/formatter/extension_review.rb', line 42

def file_finished(file, offenses)
  files << file
  offenses.each { |offense|
    report = OpenStruct.new(path: file, offense: offense)
    categories[offense.cop_name] ||= []
    categories[offense.cop_name] << report
  }
  summary.offense_count += offenses.count
end

#finished(inspected_files) ⇒ Object


52
53
54
55
56
# File 'lib/rubocop/sketchup/formatter/extension_review.rb', line 52

def finished(inspected_files)
  summary.inspected_files = inspected_files

  render_html
end

#render_htmlObject


58
59
60
61
62
63
64
65
66
# File 'lib/rubocop/sketchup/formatter/extension_review.rb', line 58

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

  template = File.read(TEMPLATE_PATH, encoding: Encoding::UTF_8)
  erb = ERB.new(template, nil, '-')
  html = erb.result(context.binding)

  output.write html
end

#started(target_files) ⇒ Object


38
39
40
# File 'lib/rubocop/sketchup/formatter/extension_review.rb', line 38

def started(target_files)
  summary.target_files = target_files
end