forked from rubocop/rubocop
/
progress_formatter.rb
64 lines (52 loc) · 1.59 KB
/
progress_formatter.rb
1
2
3
4
5
6
7
8
9
10
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true
module RuboCop
module Formatter
# This formatter display dots for files with no offenses and
# letters for files with problems in the them. In the end it
# appends the regular report data in the clang style format.
class ProgressFormatter < ClangStyleFormatter
include TextUtil
DOT = '.'
def initialize(output, options = {})
super
@dot = green(DOT)
end
def started(target_files)
super
@offenses_for_files = {}
output.puts "Inspecting #{pluralize(target_files.size, 'file')}"
end
def file_finished(file, offenses)
unless offenses.empty?
count_stats(offenses)
@offenses_for_files[file] = offenses
end
report_file_as_mark(offenses)
end
def finished(inspected_files)
output.puts
unless @offenses_for_files.empty?
output.puts
output.puts 'Offenses:'
output.puts
@offenses_for_files.each do |file, offenses|
report_file(file, offenses)
end
end
report_summary(inspected_files.size,
@total_offense_count,
@total_correction_count,
@total_correctable_count)
end
def report_file_as_mark(offenses)
mark = if offenses.empty?
@dot
else
highest_offense = offenses.max_by(&:severity)
colored_severity_code(highest_offense)
end
output.write mark
end
end
end
end