Class: Shirobai::Cop::Layout::SpaceAroundMethodCallOperator

Inherits:
RuboCop::Cop::Base
  • Object
show all
Extended by:
RuboCop::Cop::AutoCorrector
Includes:
RuboCop::Cop::RangeHelp
Defined in:
lib/shirobai/cop/layout/space_around_method_call_operator.rb

Overview

Drop-in Rust reimplementation of Layout/SpaceAroundMethodCallOperator.

Rust walks the AST, reproduces the stock cop's on_send / on_csend (the space before/after a ./&. call operator) and on_const (the space after a ::), flagging a non-empty run of only spaces/tabs (stock's SPACES_REGEXP = /\A[ \t]+\z/, so a run spanning a newline is left alone). It returns, per offense, the offending whitespace range — which is both the offense highlight and the autocorrect removal range (stock's corrector.remove(range)).

The cop has no configuration, so it is always bundle eligible; the offenses come from the per-file bundled run (Shirobai::Dispatch). The autocorrect re-passes re-investigate a fresh ProcessedSource, which recomputes the bundle from scratch, so this cop keeps no cross-pass state.

Constant Summary collapse

MSG =
"Avoid using spaces around a method call operator."

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.badgeObject



27
# File 'lib/shirobai/cop/layout/space_around_method_call_operator.rb', line 27

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

.bundle_args(_config) ⇒ Object

No packed configuration: the cop contributes nothing to the bundle's (nums, lists) wire format. Kept for symmetry with the other wrappers.



31
32
33
# File 'lib/shirobai/cop/layout/space_around_method_call_operator.rb', line 31

def self.bundle_args(_config)
  []
end

.cop_nameObject



26
# File 'lib/shirobai/cop/layout/space_around_method_call_operator.rb', line 26

def self.cop_name = "Layout/SpaceAroundMethodCallOperator"

Instance Method Details

#on_new_investigationObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/shirobai/cop/layout/space_around_method_call_operator.rb', line 35

def on_new_investigation
  buffer = processed_source.buffer
  off = SourceOffsets.for(processed_source.raw_source)

  offenses_for_source.each do |start, fin|
    range = Parser::Source::Range.new(buffer, off[start], off[fin])
    add_offense(range) do |corrector|
      corrector.remove(range)
    end
  end
end