class RuboCop::Formatter::ExtensionReviewFormatter::ERBContext
This class provides helper methods used in the ERB template.
Constants
- DEPARTMENT_DESCRIPTIONS
- LOGO_IMAGE_PATH
- SEVERITY_COLORS
- SORT_ORDER
Attributes
categories[R]
files[R]
summary[R]
Public Class Methods
new(categories, files, summary)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 145 def initialize(categories, files, summary) @categories = sort_categories(categories) @files = files.sort @summary = summary end
Public Instance Methods
base64_encoded_logo_image()
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 262 def base64_encoded_logo_image image = File.read(LOGO_IMAGE_PATH, binmode: true) Base64.encode64(image) end
binding()
click to toggle source
Make Kernel#binding public.
Calls superclass method
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 210 def binding # rubocop:disable Lint/UselessMethodDefinition super end
cop_anchor(cop_name)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 252 def cop_anchor(cop_name) title = cop_name.downcase title.tr!('/', '_') "offense_#{title}" end
decorated_message(offense)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 214 def decorated_message(offense) offense.message .gsub(/`(.+?)`/) do "<code>#{Regexp.last_match(1)}</code>" end .gsub(/\((http[^ ]+)\)/) do url = Regexp.last_match(1) "<br><a href=\"#{url}\">#{url}</a>" end end
department(cop_name)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 151 def department(cop_name) cop_name.split('/').first end
department_description(cop_name)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 155 def department_description(cop_name) dep = department(cop_name) text = DEPARTMENT_DESCRIPTIONS[dep] || 'MISSING DESCRIPTION' format_plain_text(text) end
department_offense_count(cop_name)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 161 def department_offense_count(cop_name) dep = department(cop_name) count = 0 categories.each { |category, offenses| next unless department(category) == dep count += offenses.size } count end
escape(string)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 258 def escape(string) CGI.escapeHTML(string) end
format_plain_text(text)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 182 def format_plain_text(text) paragraphs = text.split(/(\n\r|\r\n|\r|\n){2,}/m) "<p>#{paragraphs.join('</p><p>')}</p>" end
highlighted_source_line(offense)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 225 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)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 232 def hightlight_source_tag(offense) "<span class=\"highlight #{offense.severity}\">" \ "#{escape(offense.highlighted_area.source)}" \ '</span>' end
new_department?(cop_name)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 172 def new_department?(cop_name) @processed_departments ||= Set.new dep = department(cop_name) unless @processed_departments.include?(dep) @processed_departments << dep return true end false end
possible_ellipses(location)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 248 def possible_ellipses(location) location.first_line == location.last_line ? '' : " #{ELLIPSES}" end
sort_categories(categories)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 187 def sort_categories(categories) categories.sort { |a, b| # First sort departments by custom ordering (of importance). # Then sort by cop name. a_department, a_name = a[0].split('/') b_department, b_name = b[0].split('/') # Sort SketchUp cops at the top, then all the rest comes after. # First sorting by department. sort_order_a = SORT_ORDER.index(a_department) sort_order_b = SORT_ORDER.index(b_department) if sort_order_a.nil? && sort_order_b.nil? n = a_department <=> b_department else sort_order_a ||= SORT_ORDER.size sort_order_b ||= SORT_ORDER.size n = sort_order_a <=> sort_order_b end # Them sort by name if departments match. n == 0 ? a_name <=> b_name : n }.to_h end
source_after_highlight(offense)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 243 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)
click to toggle source
# File lib/rubocop/sketchup/formatter/extension_review.rb, line 238 def source_before_highlight(offense) source_line = offense.location.source_line escape(source_line[0...offense.highlighted_area.begin_pos]) end