class NdrDevSupport::Rubocop::Reporter

Handles the display of any rubocop output

Constants

COLOURS

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
print_summary() click to toggle source