Sha256: 2a213cbc4b49e9603021e83d72cfe9dcab473bac33562b0d6ece4dee29fd18af

Contents?: true

Size: 1.86 KB

Versions: 20

Compression:

Stored size: 1.86 KB

Contents

# encoding: utf-8

require 'ruby-progressbar'

module RuboCop
  module Formatter
    # 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
    class FuubarStyleFormatter < ClangStyleFormatter
      RESET_SEQUENCE = "\e[0m"

      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

      def file_finished(file, offenses)
        count_stats(offenses)

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

        with_color { @progressbar.increment }
      end

      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

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

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

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/formatter/fuubar_style_formatter.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.35.1 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.35.0 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.34.2 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.34.1 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.34.0 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.33.0 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.32.1 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.32.0 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.31.0 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.30.1 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.30.0 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.29.1 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.29.0 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.28.0 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.27.1 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.27.0 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.26.1 lib/rubocop/formatter/fuubar_style_formatter.rb
rubocop-0.26.0 lib/rubocop/formatter/fuubar_style_formatter.rb