Sha256: 4f9f680f6c6745b1355e7667116919ef866143d01cb30be6943d08ae1d1c19ff

Contents?: true

Size: 1.54 KB

Versions: 6868

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require 'pathname'

module RuboCop
  module Formatter
    # This formatter displays the list of offensive files, sorted by number of
    # offenses with the worst offenders first.
    #
    # Here's the format:
    #
    # 26  this/file/is/really/bad.rb
    # 3   just/ok.rb
    # --
    # 29  Total
    class WorstOffendersFormatter < BaseFormatter
      attr_reader :offense_counts

      def started(target_files)
        super
        @offense_counts = {}
      end

      def file_finished(file, offenses)
        return if offenses.empty?

        path = Pathname.new(file).relative_path_from(Pathname.new(Dir.pwd))
        @offense_counts[path] = offenses.size
      end

      def finished(_inspected_files)
        report_summary(@offense_counts)
      end

      # rubocop:disable Metrics/AbcSize
      def report_summary(offense_counts)
        per_file_counts = ordered_offense_counts(offense_counts)
        total_count = total_offense_count(offense_counts)

        output.puts

        per_file_counts.each do |file_name, count|
          output.puts "#{count.to_s.ljust(total_count.to_s.length + 2)}" \
                      "#{file_name}\n"
        end
        output.puts '--'
        output.puts "#{total_count}  Total"

        output.puts
      end
      # rubocop:enable Metrics/AbcSize

      def ordered_offense_counts(offense_counts)
        Hash[offense_counts.sort_by { |k, v| [-v, k] }]
      end

      def total_offense_count(offense_counts)
        offense_counts.values.inject(0, :+)
      end
    end
  end
end

Version data entries

6,868 entries across 6,842 versions & 30 rubygems

Version Path
cybrid_api_bank_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_id_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_organization_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_bank_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_id_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_organization_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_bank_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_id_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_organization_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_bank_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_id_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_organization_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_bank_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_id_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_organization_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
avalara_sdk-24.12.1 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_bank_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_organization_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_id_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb
cybrid_api_bank_ruby-0.123.124 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/formatter/worst_offenders_formatter.rb