Class: RuboCop::Formatter::HTMLFormatter::ERBContext
- Inherits:
-
Object
- Object
- RuboCop::Formatter::HTMLFormatter::ERBContext
show all
- Includes:
- TextUtil, PathUtil
- Defined in:
- lib/rubocop/formatter/html_formatter.rb
Overview
This class provides helper methods used in the ERB template.
Constant Summary
collapse
- SEVERITY_COLORS =
{
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 =
File.expand_path('../../../assets/logo.png', __dir__)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from TextUtil
pluralize
Methods included from PathUtil
absolute?, 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
86
87
88
89
|
# File 'lib/rubocop/formatter/html_formatter.rb', line 86
def initialize(files, summary)
@files = files.sort_by(&:path)
@summary = summary
end
|
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
84
85
86
|
# File 'lib/rubocop/formatter/html_formatter.rb', line 84
def files
@files
end
|
#summary ⇒ Object
Returns the value of attribute summary.
84
85
86
|
# File 'lib/rubocop/formatter/html_formatter.rb', line 84
def summary
@summary
end
|
Instance Method Details
#base64_encoded_logo_image ⇒ Object
133
134
135
136
|
# File 'lib/rubocop/formatter/html_formatter.rb', line 133
def base64_encoded_logo_image
image = File.read(LOGO_IMAGE_PATH, binmode: true)
Base64.encode64(image)
end
|
#binding ⇒ Object
Make Kernel#binding public. rubocop:disable Lint/UselessMethodDefinition
93
94
95
|
# File 'lib/rubocop/formatter/html_formatter.rb', line 93
def binding
super
end
|
#decorated_message(offense) ⇒ Object
rubocop:enable Lint/UselessMethodDefinition
98
99
100
|
# File 'lib/rubocop/formatter/html_formatter.rb', line 98
def decorated_message(offense)
offense.message.gsub(/`(.+?)`/) { "<code>#{Regexp.last_match(1)}</code>" }
end
|
#escape(string) ⇒ Object
129
130
131
|
# File 'lib/rubocop/formatter/html_formatter.rb', line 129
def escape(string)
CGI.escapeHTML(string)
end
|
#highlighted_source_line(offense) ⇒ Object
102
103
104
105
106
107
|
# File 'lib/rubocop/formatter/html_formatter.rb', line 102
def highlighted_source_line(offense)
source_before_highlight(offense) +
hightlight_source_tag(offense) +
source_after_highlight(offense) +
possible_ellipses(offense.location)
end
|
#hightlight_source_tag(offense) ⇒ Object
109
110
111
112
113
|
# File 'lib/rubocop/formatter/html_formatter.rb', line 109
def hightlight_source_tag(offense)
"<span class=\"highlight #{offense.severity}\">" \
"#{escape(offense.highlighted_area.source)}" \
'</span>'
end
|
#possible_ellipses(location) ⇒ Object
125
126
127
|
# File 'lib/rubocop/formatter/html_formatter.rb', line 125
def possible_ellipses(location)
location.first_line == location.last_line ? '' : " #{ELLIPSES}"
end
|
#source_after_highlight(offense) ⇒ Object
120
121
122
123
|
# File 'lib/rubocop/formatter/html_formatter.rb', line 120
def source_after_highlight(offense)
source_line = offense.location.source_line
escape(source_line[offense.highlighted_area.end_pos..-1])
end
|
#source_before_highlight(offense) ⇒ Object
115
116
117
118
|
# File 'lib/rubocop/formatter/html_formatter.rb', line 115
def source_before_highlight(offense)
source_line = offense.location.source_line
escape(source_line[0...offense.highlighted_area.begin_pos])
end
|