Class: Shirobai::Cop::Performance::TimesMap

Inherits:
RuboCop::Cop::Base
  • Object
show all
Extended by:
RuboCop::Cop::AutoCorrector
Includes:
BundleEligible
Defined in:
lib/shirobai/cop/performance/times_map.rb

Overview

Drop-in Rust reimplementation of Performance/TimesMap (rubocop-performance 1.26.1).

Rust replicates the stock times_map_call pattern (literal block on x.times.map / x.times.collect, or a sole block-pass argument) with the handleable_receiver? gate (int/float literal receiver of times, or an explicit .-dispatched times call) and builds both the message (only if ... 0 or more for non-literal counts) and the Array.new(...) replacement from source slices. The wrapper applies the replacement to the parser-send range (the call without its literal block), exactly like stock's corrector.replace(map_or_collect, ...).

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.badgeObject



23
# File 'lib/shirobai/cop/performance/times_map.rb', line 23

def self.badge = RuboCop::Cop::Badge.parse(cop_name)

.bundle_args(_config) ⇒ Object

Config-less: nothing to pack (the shared segment only carries the department enable flag for this cop).



27
28
29
# File 'lib/shirobai/cop/performance/times_map.rb', line 27

def self.bundle_args(_config)
  []
end

.cop_nameObject



22
# File 'lib/shirobai/cop/performance/times_map.rb', line 22

def self.cop_name = "Performance/TimesMap"

Instance Method Details

#on_new_investigationObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/shirobai/cop/performance/times_map.rb', line 31

def on_new_investigation
  buffer = processed_source.buffer
  source = bundle_eligible? ? processed_source.raw_source : buffer.source
  off = SourceOffsets.for(source)
  resolved_offenses.each do |start, fin, replace_start, replace_end, message, replacement|
    range = Parser::Source::Range.new(buffer, off[start], off[fin])
    add_offense(range, message: message) do |corrector|
      corrector.replace(
        Parser::Source::Range.new(buffer, off[replace_start], off[replace_end]),
        replacement
      )
    end
  end
end