Class: Shirobai::Cop::Layout::SpaceAfterColon

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

Overview

Drop-in Rust reimplementation of Layout/SpaceAfterColon.

Stock is AST-only (on_pair / on_kwoptarg); Rust mirrors it on the shared walk. A colon pair's colon is the last byte of the key symbol's closing_loc (prism keeps the label colon inside the symbol — plain, quoted and interpolated keys alike, in hashes, keyword arguments and hash patterns); a keyword optional parameter's colon is the last byte of its name_loc. Rockets and value omissions ({a:}, in {a:} — an ImplicitNode value) are skipped, and required keyword arguments (a:) are not kwoptargs. The byte after the colon is checked against /\s/ (EOF does not match).

Each offense is the [start, end) range of the colon; the corrector inserts a space after it.

Constant Summary collapse

MSG =
"Space missing after colon."

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.badgeObject



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

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

.bundle_args(_config) ⇒ Object

Config-less: contributes nothing to nums / lists.



30
31
32
# File 'lib/shirobai/cop/layout/space_after_colon.rb', line 30

def self.bundle_args(_config)
  []
end

.cop_nameObject



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

def self.cop_name = "Layout/SpaceAfterColon"

Instance Method Details

#on_new_investigationObject



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

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.insert_after(range, " ")
    end
  end
end