Class: Rubocop::Formatter::OffenseCountFormatter
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- Rubocop::Formatter::OffenseCountFormatter
- Defined in:
- lib/rubocop/formatter/offense_count_formatter.rb
Overview
This formatter displays the list of offended cops with a count of how many offenses of their kind were found. Ordered by desc offense count
Here's the format:
26 LineLength
3 OneLineConditional
29 Total
Instance Attribute Summary collapse
-
#offense_counts ⇒ Object
readonly
Returns the value of attribute offense_counts.
Attributes inherited from BaseFormatter
Instance Method Summary collapse
- #file_finished(file, offenses) ⇒ Object
- #finished(inspected_files) ⇒ Object
- #ordered_offense_counts(offense_counts) ⇒ Object
- #report_summary(file_count, offense_counts) ⇒ Object
- #started(target_files) ⇒ Object
- #total_offense_count(offense_counts = {}) ⇒ Object
Methods inherited from BaseFormatter
Constructor Details
This class inherits a constructor from Rubocop::Formatter::BaseFormatter
Instance Attribute Details
#offense_counts ⇒ Object (readonly)
Returns the value of attribute offense_counts.
15 16 17 |
# File 'lib/rubocop/formatter/offense_count_formatter.rb', line 15 def offense_counts @offense_counts end |
Instance Method Details
#file_finished(file, offenses) ⇒ Object
22 23 24 |
# File 'lib/rubocop/formatter/offense_count_formatter.rb', line 22 def file_finished(file, offenses) offenses.each { |o| @offense_counts[o.cop_name] += 1 } end |
#finished(inspected_files) ⇒ Object
26 27 28 29 |
# File 'lib/rubocop/formatter/offense_count_formatter.rb', line 26 def finished(inspected_files) report_summary(inspected_files.count, ordered_offense_counts(@offense_counts)) end |
#ordered_offense_counts(offense_counts) ⇒ Object
45 46 47 |
# File 'lib/rubocop/formatter/offense_count_formatter.rb', line 45 def ordered_offense_counts(offense_counts) Hash[offense_counts.sort_by { |k, v| [-v, k] }] end |
#report_summary(file_count, offense_counts) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubocop/formatter/offense_count_formatter.rb', line 31 def report_summary(file_count, offense_counts) output.puts offense_count = total_offense_count(offense_counts) offense_counts.each do |cop_name, count| output.puts "#{count.to_s.ljust(offense_count.to_s.length + 2)}" \ "#{cop_name}\n" end output.puts '--' output.puts "#{offense_count} Total" output.puts end |
#started(target_files) ⇒ Object
17 18 19 20 |
# File 'lib/rubocop/formatter/offense_count_formatter.rb', line 17 def started(target_files) super @offense_counts = Hash.new(0) end |
#total_offense_count(offense_counts = {}) ⇒ Object
49 50 51 |
# File 'lib/rubocop/formatter/offense_count_formatter.rb', line 49 def total_offense_count(offense_counts = {}) offense_counts.values.inject(0, :+) end |