Class: Shirobai::Cop::Layout::SpaceAfterComma

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

Overview

Drop-in Rust reimplementation of Layout/SpaceAfterComma.

Stock walks tokens pairwise (SpaceAfterPunctuation); Rust reconstructs the same facts byte-side: a comma token is a , byte outside opaque literal regions, and "the next token is adjacent" is "the next byte is not whitespace and not a \-newline continuation". The allowed next tokens (tRPAREN / tRBRACK / tPIPE / tSTRING_DEND, plus tRCURLY when Layout/SpaceInsideHashLiteralBraces is no_space, plus a following semicolon which has no kind) reduce to byte tests against the interpolation-closing positions collected in the shared walk.

Each offense is the [start, end) range of the comma itself; the corrector replaces it with ", " (PunctuationCorrector.add_space).

Constant Summary collapse

MSG =
"Space missing after comma."

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.badgeObject



28
# File 'lib/shirobai/cop/layout/space_after_comma.rb', line 28

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

.bundle_args(config) ⇒ Object

Packed args for the bundled run: [Layout/SpaceInsideHashLiteralBraces EnforcedStyle == 'no_space'] (nil falls back to 'space', like stock's space_style_before_rcurly).



34
35
36
37
# File 'lib/shirobai/cop/layout/space_after_comma.rb', line 34

def self.bundle_args(config)
  style = config.for_cop("Layout/SpaceInsideHashLiteralBraces")["EnforcedStyle"] || "space"
  [[style == "no_space" ? 1 : 0], []]
end

.cop_nameObject



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

def self.cop_name = "Layout/SpaceAfterComma"

Instance Method Details

#on_new_investigationObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/shirobai/cop/layout/space_after_comma.rb', line 39

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|
    range = Parser::Source::Range.new(buffer, off[start], off[fin])
    add_offense(range, message: MSG) do |corrector|
      corrector.replace(range, "#{range.source} ")
    end
  end
end