Class: RuboCop::Formatter::HTMLFormatter::ERBContext Private
- Inherits:
-
Object
- Object
- RuboCop::Formatter::HTMLFormatter::ERBContext
- Defined in:
- lib/rubocop/formatter/html_formatter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This class provides helper methods used in the ERB template.
Constant Summary collapse
- SEVERITY_COLORS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ refactor: Color.new(0xED, 0x9C, 0x28, 1.0), convention: Color.new(0xED, 0x9C, 0x28, 1.0), warning: Color.new(0x96, 0x28, 0xEF, 1.0), error: Color.new(0xD2, 0x32, 0x2D, 1.0), fatal: Color.new(0xD2, 0x32, 0x2D, 1.0) }.freeze
- LOGO_IMAGE_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
File.('../../../assets/logo.png', __dir__)
Constants included from PathUtil
Instance Attribute Summary collapse
- #files ⇒ Object readonly private
- #summary ⇒ Object readonly private
Instance Method Summary collapse
- #base64_encoded_logo_image ⇒ Object private
-
#binding ⇒ Object
private
Make Kernel#binding public.
-
#decorated_message(offense) ⇒ Object
private
rubocop:enable Lint/UselessMethodDefinition.
- #escape(string) ⇒ Object private
- #highlight_source_tag(offense) ⇒ Object private
- #highlighted_source_line(offense) ⇒ Object private
-
#initialize(files, summary) ⇒ ERBContext
constructor
private
A new instance of ERBContext.
- #possible_ellipses(location) ⇒ Object private
- #source_after_highlight(offense) ⇒ Object private
- #source_before_highlight(offense) ⇒ Object private
Methods included from TextUtil
Methods included from PathUtil
absolute?, glob?, hidden_dir?, hidden_file?, hidden_file_in_not_hidden_dir?, match_path?, maybe_hidden_file?, relative_path, smart_path
Constructor Details
#initialize(files, summary) ⇒ ERBContext
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ERBContext.
78 79 80 81 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 78 def initialize(files, summary) @files = files.sort_by(&:path) @summary = summary end |
Instance Attribute Details
#files ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 76 def files @files end |
#summary ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 76 def summary @summary end |
Instance Method Details
#base64_encoded_logo_image ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
125 126 127 128 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 125 def base64_encoded_logo_image image = File.read(LOGO_IMAGE_PATH, binmode: true) Base64.encode64(image) end |
#binding ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Make Kernel#binding public. rubocop:disable Lint/UselessMethodDefinition
85 86 87 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 85 def binding super end |
#decorated_message(offense) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:enable Lint/UselessMethodDefinition
90 91 92 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 90 def (offense) offense..gsub(/`(.+?)`/) { "<code>#{Regexp.last_match(1)}</code>" } end |
#escape(string) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
121 122 123 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 121 def escape(string) CGI.escapeHTML(string) end |
#highlight_source_tag(offense) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
101 102 103 104 105 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 101 def highlight_source_tag(offense) "<span class=\"highlight #{offense.severity}\">" \ "#{escape(offense.highlighted_area.source)}" \ '</span>' end |
#highlighted_source_line(offense) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
94 95 96 97 98 99 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 94 def highlighted_source_line(offense) source_before_highlight(offense) + highlight_source_tag(offense) + source_after_highlight(offense) + possible_ellipses(offense.location) end |
#possible_ellipses(location) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
117 118 119 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 117 def possible_ellipses(location) location.single_line? ? '' : " #{ELLIPSES}" end |
#source_after_highlight(offense) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
112 113 114 115 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 112 def source_after_highlight(offense) source_line = offense.location.source_line escape(source_line[offense.highlighted_area.end_pos..]) end |
#source_before_highlight(offense) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
107 108 109 110 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 107 def source_before_highlight(offense) source_line = offense.location.source_line escape(source_line[0...offense.highlighted_area.begin_pos]) end |