class NdrDevSupport::Rubocop::Reporter
Handles the display of any rubocop output
Constants
- COLOURS
- FOOTER
- HEADER
Public Class Methods
new(offenses)
click to toggle source
# File lib/ndr_dev_support/rubocop/reporter.rb, line 18 def initialize(offenses) @offenses = Hash[offenses.sort_by { |file, _offenses| file }] end
Public Instance Methods
report()
click to toggle source
Prints out a report, and returns an appriopriate exit status for the rake task to terminate with.
# File lib/ndr_dev_support/rubocop/reporter.rb, line 24 def report if @offenses.none? warn Rainbow('No relevant changes found.').yellow return true end print_summary puts print_offenses @offenses.values.all?(&:empty?) end
Private Instance Methods
colour_severity(severity, initial_only = false)
click to toggle source
# File lib/ndr_dev_support/rubocop/reporter.rb, line 39 def colour_severity(severity, initial_only = false) colour = COLOURS[severity] message = initial_only ? severity[0, 1].upcase : severity colour ? Rainbow(message).color(colour) : message end
formatted_offense(filename, offense)
click to toggle source
# File lib/ndr_dev_support/rubocop/reporter.rb, line 65 def formatted_offense(filename, offense) format('%s:%d:%d: %s: %s %s', Rainbow(filename).cyan, offense['location']['line'], offense['location']['column'], colour_severity(offense['severity'], true), offense['message'], colour_severity(offense['severity']) ) end
print_offenses()
click to toggle source
# File lib/ndr_dev_support/rubocop/reporter.rb, line 57 def print_offenses @offenses.each do |filename, file_offenses| file_offenses.each do |offense| puts formatted_offense(filename, offense) end end end
print_summary()
click to toggle source
# File lib/ndr_dev_support/rubocop/reporter.rb, line 45 def print_summary puts HEADER @offenses.each do |filename, file_offenses| puts format(' * %s has %d relevant offence%s.', Rainbow(filename).fg(file_offenses.empty? ? :green : :red), file_offenses.length, file_offenses.one? ? '' : 's' ) end puts FOOTER end