Class: RuboCop::OffenseLimit Private
- Inherits:
-
Object
- Object
- RuboCop::OffenseLimit
- Defined in:
- lib/rubocop/offense_limit.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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.
Instance Attribute Summary collapse
- #max ⇒ Object readonly private
Instance Method Summary collapse
-
#elided_per_cop ⇒ Hash{String => Integer}
private
How many offenses each cop had left out, sorted by cop name.
-
#filter(offenses) ⇒ Array<Cop::Offense>
private
The offenses still within their cop's limit.
-
#initialize(max) ⇒ OffenseLimit
constructor
private
A new instance of OffenseLimit.
Constructor Details
#initialize(max) ⇒ OffenseLimit
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of OffenseLimit.
14 15 16 17 |
# File 'lib/rubocop/offense_limit.rb', line 14 def initialize(max) @max = max @offered = Hash.new(0) end |
Instance Attribute Details
#max ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rubocop/offense_limit.rb', line 12 def max @max end |
Instance Method Details
#elided_per_cop ⇒ Hash{String => Integer}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns how many offenses each cop had left out, sorted by cop name.
26 27 28 |
# 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>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the offenses still within their cop's limit.
20 21 22 |
# File 'lib/rubocop/offense_limit.rb', line 20 def filter(offenses) offenses.select { |offense| (@offered[offense.cop_name] += 1) <= @max } end |