Class: Shirobai::Cop::Layout::InitialIndentation

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

Overview

Drop-in Rust reimplementation of Layout/InitialIndentation.

Rust answers only the cheap question — "is the first non-comment token indented?" — with a leading-byte scan that never materializes the token stream. On the overwhelming majority of files (column-0 start) the scan settles it and this cop touches no tokens, which is the whole point: stock's first_token forces the parser-gem token stream on EVERY file (the "toucher" cost).

Only when the scan reports an offense does the wrapper fall through to stock's exact first_token / space_before construction (below, verbatim from vendor/rubocop/lib/rubocop/cop/layout/initial_indentation.rb). Because that construction is stock's own code, the offense range and the autocorrect bytes are byte-identical by construction; the Rust scan is a pure speed gate. The scan can only over-report (it never skips a token stock keeps), and space_before's column.zero? / no-space-to-the-left guards filter any over-report back to stock's answer.

Constant Summary collapse

MSG =
"Indentation of first line in file detected."

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.badgeObject



31
# File 'lib/shirobai/cop/layout/initial_indentation.rb', line 31

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

.bundle_args(_config) ⇒ Object

Config-less: contributes nothing to nums / lists. Kept for the 4+1 single-source-of-config convention.



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

def self.bundle_args(_config)
  []
end

.cop_nameObject



30
# File 'lib/shirobai/cop/layout/initial_indentation.rb', line 30

def self.cop_name = "Layout/InitialIndentation"

Instance Method Details

#on_new_investigationObject



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

def on_new_investigation
  return unless offense?

  space_before(first_token) do |space|
    add_offense(first_token.pos) do |corrector|
      corrector.remove(space)
    end
  end
end