class ESLintWebpacker::TextFormatter

Public Class Methods

new(warnings) click to toggle source
# File lib/eslint-webpacker/text_formatter.rb, line 8
def initialize(warnings)
  @warnings = warnings
end

Public Instance Methods

format() click to toggle source
# File lib/eslint-webpacker/text_formatter.rb, line 12
def format
  max_line_column_length = max_length_of_attribute(:location)
  max_rule_id_length = max_length_of_attribute(:rule_id)
  max_message_length = max_length_of_attribute(:message)
  @warnings.each do |warning|
    message = [
      warning.location.ljust(max_line_column_length + 1),
      warning.severity.to_s.ljust(6),
      warning.rule_id.ljust(max_rule_id_length),
      warning.message.ljust(max_message_length)
    ].join(' ')
    colorized_message =
      case warning.severity
      when :low
        message.green
      when :high
        message.yellow
      else
        raise 'BULLSHIT'
      end
    puts colorized_message
  end

  puts "#{@warnings.size} warning(s) found."
end

Private Instance Methods

max_length_of_attribute(attr_key) click to toggle source
# File lib/eslint-webpacker/text_formatter.rb, line 40
def max_length_of_attribute(attr_key)
  @warnings.map { |warning| warning.send(attr_key).size }.max
end