Class: Ace::Lint::Molecules::OffenseDeduplicator

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/lint/molecules/offense_deduplicator.rb

Overview

Deduplicates linting offenses from multiple validators Handles offenses from StandardRB, RuboCop, and other Ruby linters

Class Method Summary collapse

Class Method Details

.deduplicate(offenses) ⇒ Array<Hash>

Deduplicate offenses by file:line:column:normalized_message Keeps the offense with the most detailed message when duplicates found

Parameters:

  • offenses (Array<Hash>)

    Offenses to deduplicate

Returns:

  • (Array<Hash>)

    Deduplicated offenses



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ace/lint/molecules/offense_deduplicator.rb', line 13

def self.deduplicate(offenses)
  return [] if offenses.empty?

  seen = {}

  offenses.each do |offense|
    key = offense_key(offense)
    if seen[key]
      # Keep the offense with the longer/more detailed message
      existing_len = seen[key][:message]&.length || 0
      new_len = offense[:message]&.length || 0
      seen[key] = offense if new_len > existing_len
    else
      seen[key] = offense
    end
  end

  seen.values
end