Class: ESLintWebpacker::TextFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/eslint-webpacker/text_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(warnings) ⇒ TextFormatter

Returns a new instance of TextFormatter.



8
9
10
# File 'lib/eslint-webpacker/text_formatter.rb', line 8

def initialize(warnings)
  @warnings = warnings
end

Instance Method Details

#formatObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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