Class: RuboCop::Formatter::PacmanFormatter
Overview
This formatter prints a PACDOT per every file to be analyzed. Pacman will “eat” one PACDOT per file when no offense is detected. Otherwise it will print a Ghost. This is inspired by the Pacman formatter for RSpec by Carlos Rojas. github.com/go-labs/rspec_pacman_formatter
Constant Summary
collapse
- FALLBACK_TERMINAL_WIDTH =
80
- GHOST =
'ᗣ'
- PACMAN =
Rainbow('ᗧ').yellow.bright
- PACDOT =
Rainbow('•').yellow.bright
ClangStyleFormatter::ELLIPSES
SimpleTextFormatter::COLOR_FOR_SEVERITY
Constants included
from PathUtil
PathUtil::HIDDEN_FILE_PATTERN
Instance Attribute Summary collapse
#options, #output
Instance Method Summary
collapse
Methods included from TextUtil
pluralize
#report_file
#finished, #report_file, #report_summary
Methods included from PathUtil
absolute?, glob?, hidden_dir?, hidden_file?, hidden_file_in_not_hidden_dir?, match_path?, maybe_hidden_file?, relative_path, remote_file?, smart_path
#colorize, #rainbow
#finished
Constructor Details
#initialize(output, options = {}) ⇒ PacmanFormatter
Returns a new instance of PacmanFormatter.
20
21
22
23
24
25
|
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 20
def initialize(output, options = {})
super
@progress_line = ''
@total_files = 0
@repetitions = 0
end
|
Instance Attribute Details
#progress_line ⇒ Object
Returns the value of attribute progress_line.
13
14
15
|
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 13
def progress_line
@progress_line
end
|
Instance Method Details
#cols ⇒ Object
51
52
53
54
55
56
|
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 51
def cols
@cols ||= begin
_height, width = $stdout.winsize
width.nil? || width.zero? ? FALLBACK_TERMINAL_WIDTH : width
end
end
|
#file_finished(file, offenses) ⇒ Object
38
39
40
41
42
|
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 38
def file_finished(file, offenses)
count_stats(offenses) unless offenses.empty?
next_step(offenses)
report_file(file, offenses)
end
|
#file_started(_file, _options) ⇒ Object
34
35
36
|
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 34
def file_started(_file, _options)
step(PACMAN)
end
|
#next_step(offenses) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 44
def next_step(offenses)
return step('.') if offenses.empty?
ghost_color = COLOR_FOR_SEVERITY[offenses.last.severity.name]
step(colorize(GHOST, ghost_color))
end
|
#pacdots(number) ⇒ Object
65
66
67
|
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 65
def pacdots(number)
@progress_line = PACDOT * number
end
|
#started(target_files) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 27
def started(target_files)
super
@total_files = target_files.size
output.puts "Eating #{pluralize(target_files.size, 'file')}"
update_progress_line
end
|
#step(character) ⇒ Object
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 69
def step(character)
regex = /#{Regexp.quote(PACMAN)}|#{Regexp.quote(PACDOT)}/
@progress_line = @progress_line.sub(regex, character)
output.printf("%<line>s\r", line: @progress_line)
return unless /ᗣ|\./.match?(@progress_line[-1])
@repetitions += 1
output.puts
update_progress_line
end
|
#update_progress_line ⇒ Object
58
59
60
61
62
63
|
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 58
def update_progress_line
return pacdots(@total_files) unless @total_files > cols
return pacdots(cols) unless (@total_files / cols).eql?(@repetitions)
pacdots(@total_files - (cols * @repetitions))
end
|