Class: RuboCop::Formatter::PacmanFormatter Private
- Inherits:
-
ClangStyleFormatter
- Object
- BaseFormatter
- SimpleTextFormatter
- ClangStyleFormatter
- RuboCop::Formatter::PacmanFormatter
- Includes:
- TextUtil
- Defined in:
- lib/rubocop/formatter/pacman_formatter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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. https://github.com/go-labs/rspec_pacman_formatter
Constant Summary collapse
- FALLBACK_TERMINAL_WIDTH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
80- GHOST =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'ᗣ'- PACMAN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Rainbow('ᗧ').yellow.bright
- PACDOT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Rainbow('•').yellow.bright
Constants inherited from ClangStyleFormatter
Constants inherited from SimpleTextFormatter
SimpleTextFormatter::COLOR_FOR_SEVERITY
Constants included from PathUtil
Instance Attribute Summary collapse
- #progress_line ⇒ Object private
Attributes inherited from BaseFormatter
Instance Method Summary collapse
- #cols ⇒ Object private
- #file_finished(file, offenses) ⇒ Object private
- #file_started(_file, _options) ⇒ Object private
-
#initialize(output, options = {}) ⇒ PacmanFormatter
constructor
private
A new instance of PacmanFormatter.
- #next_step(offenses) ⇒ Object private
- #pacdots(number) ⇒ Object private
- #started(target_files) ⇒ Object private
- #step(character) ⇒ Object private
- #update_progress_line ⇒ Object private
Methods included from TextUtil
Methods inherited from ClangStyleFormatter
Methods inherited from SimpleTextFormatter
#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, smart_path
Methods included from Colorizable
Methods inherited from BaseFormatter
Constructor Details
#initialize(output, options = {}) ⇒ PacmanFormatter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of PacmanFormatter.
19 20 21 22 23 24 |
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 19 def initialize(output, = {}) super @progress_line = '' @total_files = 0 @repetitions = 0 end |
Instance Attribute Details
#progress_line ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 12 def progress_line @progress_line end |
Instance Method Details
#cols ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 53 54 55 |
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 50 def cols @cols ||= begin _height, width = $stdout.winsize width.nil? || width.zero? ? FALLBACK_TERMINAL_WIDTH : width end end |
#file_finished(file, offenses) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 41 |
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 37 def file_finished(file, offenses) count_stats(offenses) unless offenses.empty? next_step(offenses) report_file(file, offenses) end |
#file_started(_file, _options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 |
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 33 def file_started(_file, ) step(PACMAN) end |
#next_step(offenses) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 46 47 48 |
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 43 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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 65 66 |
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 64 def pacdots(number) @progress_line = PACDOT * number end |
#started(target_files) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 29 30 31 |
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 26 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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 68 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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 60 61 62 |
# File 'lib/rubocop/formatter/pacman_formatter.rb', line 57 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 |