Class: ESLintRails::TextFormatter
- Inherits:
-
Object
- Object
- ESLintRails::TextFormatter
- Defined in:
- lib/eslint-rails-ee/text_formatter.rb
Instance Method Summary collapse
- #format(should_autocorrect = false) ⇒ Object
-
#initialize(warnings) ⇒ TextFormatter
constructor
A new instance of TextFormatter.
Constructor Details
#initialize(warnings) ⇒ TextFormatter
Returns a new instance of TextFormatter.
7 8 9 |
# File 'lib/eslint-rails-ee/text_formatter.rb', line 7 def initialize(warnings) @warnings = warnings end |
Instance Method Details
#format(should_autocorrect = false) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/eslint-rails-ee/text_formatter.rb', line 11 def format(should_autocorrect=false) max_line_column_length = max_length_of_attribute(:location) max_rule_id_length = max_length_of_attribute(:rule_id) = max_length_of_attribute(:message) @warnings.each do |warning| = [ warning.location.ljust(max_line_column_length + 1), warning.severity.to_s.ljust(6), warning.rule_id.ljust(max_rule_id_length), warning..ljust() ].join(" ") = case warning.severity when :low .yellow when :high .red else raise 'Couldn\'t figure out how to format this mess. Stahp.' end puts end puts "#{@warnings.size} warning(s) found #{should_autocorrect ? 'after auto-correcting some issues' : ''}" end |