123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::Formatter::FuubarStyleFormatter

Overview

This formatter displays a progress bar and shows details of offenses as soon as they are detected. This is inspired by the Fuubar formatter for RSpec by Jeff Kreeftmeijer. https://github.com/jeffkreeftmeijer/fuubar

Constant Summary

::RuboCop::PathUtil - Included

HIDDEN_FILE_PATTERN, SMART_PATH_CACHE

SimpleTextFormatter - Inherited

COLOR_FOR_SEVERITY

ClangStyleFormatter - Inherited

ELLIPSES

Class Method Summary

Instance Attribute Summary

Instance Method Summary

ClangStyleFormatter - Inherited

SimpleTextFormatter - Inherited

::RuboCop::PathUtil - Included

#absolute?

Returns true for an absolute Unix or Windows path.

#glob?

Returns true for a glob.

#hidden_dir?, #hidden_file?, #hidden_file_in_not_hidden_dir?,
#match_path?

Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.

#maybe_hidden_file?

Loose check to reduce memory allocations.

#relative_path, #smart_path

Colorizable - Included

BaseFormatter - Inherited

#file_finished

Invoked at the end of inspecting each files.

#file_started

Invoked at the beginning of inspecting each files.

#finished

Invoked after all files are inspected or interrupted by user.

#started

Invoked once before any files are inspected.

Constructor Details

.new(*output) ⇒ FuubarStyleFormatter

[ GitHub ]

  
# File 'lib/rubocop/formatter/fuubar_style_formatter.rb', line 14

def initialize(*output)
  @severest_offense = nil

  super
end

Instance Method Details

#count_stats(offenses)

[ GitHub ]

  
# File 'lib/rubocop/formatter/fuubar_style_formatter.rb', line 51

def count_stats(offenses)
  super

  offenses = offenses.reject(&:corrected?)
  return if offenses.empty?

  offenses << @severest_offense if @severest_offense
  @severest_offense = offenses.max_by(&:severity)
end

#file_finished(file, offenses)

[ GitHub ]

  
# File 'lib/rubocop/formatter/fuubar_style_formatter.rb', line 40

def file_finished(file, offenses)
  count_stats(offenses)

  unless offenses.empty?
    @progressbar.clear
    report_file(file, offenses)
  end

  with_color { @progressbar.increment }
end

#progressbar_color

[ GitHub ]

  
# File 'lib/rubocop/formatter/fuubar_style_formatter.rb', line 71

def progressbar_color
  if @severest_offense
    COLOR_FOR_SEVERITY[@severest_offense.severity.name]
  else
    :green
  end
end

#started(target_files)

[ GitHub ]

  
# File 'lib/rubocop/formatter/fuubar_style_formatter.rb', line 20

def started(target_files)
  super

  @severest_offense = nil

  file_phrase = target_files.count == 1 ? 'file' : 'files'

  # 185/407 files |====== 45 ======>                    |  ETA: 00:00:04
  # %c / %C       |       %w       >         %i         |       %e
  bar_format = " %c/%C #{file_phrase} |%w>%i| %e "

  @progressbar = ProgressBar.create(
    output: output,
    total: target_files.count,
    format: bar_format,
    autostart: false
  )
  with_color { @progressbar.start }
end

#with_color

[ GitHub ]

  
# File 'lib/rubocop/formatter/fuubar_style_formatter.rb', line 61

def with_color
  if rainbow.enabled
    output.write colorize('', progressbar_color).chomp(RESET_SEQUENCE)
    yield
    output.write RESET_SEQUENCE
  else
    yield
  end
end