Class: Shirobai::Cop::Layout::SpaceBeforeComma
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::SpaceBeforeComma
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- BundleEligible
- Defined in:
- lib/shirobai/cop/layout/space_before_comma.rb
Overview
Drop-in Rust reimplementation of Layout/SpaceBeforeComma.
Stock walks sorted_tokens pairwise (SpaceBeforePunctuation); Rust
reconstructs the same facts byte-side: a comma token is a , byte
outside strings / symbols / regexps / comments / heredoc bodies /
$, / __END__ data, and the previous token's end is the first
non-whitespace byte to the left on the same line. A block or lambda
{ right before the comma is skipped when
Layout/SpaceInsideBlockBraces wants a space after it
(space_required_after_lcurly? — unreachable for commas in code that
parses, but mirrored for exactness).
Each offense is the [start, end) whitespace run before the comma;
the corrector removes it (PunctuationCorrector.remove_space).
Constant Summary collapse
- MSG =
"Space found before comma."
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run:
[Layout/SpaceInsideBlockBraces EnforcedStyle == 'space'](nilfalls back to'space', like stock'sspace_required_after_lcurly?). - .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
27 |
# File 'lib/shirobai/cop/layout/space_before_comma.rb', line 27 def self.badge = RuboCop::Cop::Badge.parse(cop_name) |
.bundle_args(config) ⇒ Object
Packed args for the bundled run:
[Layout/SpaceInsideBlockBraces EnforcedStyle == 'space']
(nil falls back to 'space', like stock's
space_required_after_lcurly?).
33 34 35 36 |
# File 'lib/shirobai/cop/layout/space_before_comma.rb', line 33 def self.bundle_args(config) style = config.for_cop("Layout/SpaceInsideBlockBraces")["EnforcedStyle"] || "space" [[style == "space" ? 1 : 0], []] end |
.cop_name ⇒ Object
26 |
# File 'lib/shirobai/cop/layout/space_before_comma.rb', line 26 def self.cop_name = "Layout/SpaceBeforeComma" |
Instance Method Details
#on_new_investigation ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/shirobai/cop/layout/space_before_comma.rb', line 38 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.remove(range) end end end |