Class: Rfix::Formatter

Inherits:
RuboCop::Formatter::SimpleTextFormatter
  • Object
show all
Extended by:
Dry::Initializer
Includes:
Dry::Core::Constants, Log
Defined in:
lib/rfix/formatter.rb

Constant Summary collapse

NoSuchFileError =
Class.new(Error)
SURROUNDING_LINES =
2
NEWLINE =
"\n"
SPACE =
" "
PADDING =
1

Instance Method Summary collapse

Methods included from Log

prompt, say, say!

Constructor Details

#initialize(output, options = EMPTY_HASH) ⇒ Formatter

Returns a new instance of Formatter.



52
53
54
55
56
# File 'lib/rfix/formatter.rb', line 52

def initialize(output, options = EMPTY_HASH)
  TTY::ProgressBar.new(":current/:total (:eta) [:bar]", output: output).then do |bar|
    super(output, output: output, options: options, params: options, progress: bar)
  end
end

Instance Method Details

#file_finished(_file, offenses) ⇒ Object



70
71
72
73
74
# File 'lib/rfix/formatter.rb', line 70

def file_finished(_file, offenses)
  @reported_offenses += offenses

  progress.advance
end

#finished(files) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rfix/formatter.rb', line 77

def finished(files)
  progress.finish
  mark_command_line
  reported_offenses.each do |offense|
    progress.log(NEWLINE)

    framed(offense) do
      report_line_with_highlight(offense)
    end
  rescue NoSuchFileError
    # NOP
  end
  report_summary(files)
end

#started(files) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/rfix/formatter.rb', line 58

def started(files)
  progress.configure do |config|
    config.bar_format = :block
    config.total = files.count
    config.clear_head = true
    config.clear = true
    config.width = width
  end
end