123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::OffenseLimit Private

Relationships & Source Files
Inherits: Object
Defined in: lib/rubocop/offense_limit.rb

Overview

Caps how many offenses each cop gets to report.

Counted across a whole run rather than per file, since a cop that fires a handful of times in every file is exactly the one worth capping. Offenses have to be offered in a stable order (files in the order they are reported) for the same ones to survive every time.

Class Method Summary

Instance Attribute Summary

  • #max readonly Internal use only

Instance Method Summary

Constructor Details

.new(max) ⇒ OffenseLimit

[ GitHub ]

  
# File 'lib/rubocop/offense_limit.rb', line 14

def initialize(max)
  @max = max
  @offered = Hash.new(0)
end

Instance Attribute Details

#max (readonly)

[ GitHub ]

  
# File 'lib/rubocop/offense_limit.rb', line 12

attr_reader :max

Instance Method Details

#elided_per_cop ⇒ Hash{String => Integer}

Returns:

  • (Hash{String => Integer}) —

    how many offenses each cop had left out, sorted by cop name

[ GitHub ]

  
# File 'lib/rubocop/offense_limit.rb', line 26

def elided_per_cop
  @offered.filter_map { |cop, count| [cop, count - @max] if count > @max }.sort.to_h
end

#filter(offenses) ⇒ Array<Cop::Offense>

Returns:

  • (Array<Cop::Offense>) —

    the offenses still within their cop’s limit

[ GitHub ]

  
# File 'lib/rubocop/offense_limit.rb', line 20

def filter(offenses)
  offenses.select { |offense| (@offered[offense.cop_name] += 1) <= @max }
end