Class: Shirobai::Cop::Layout::SpaceInsideStringInterpolation
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::SpaceInsideStringInterpolation
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::ConfigurableEnforcedStyle, RuboCop::Cop::RangeHelp, BundleEligible
- Defined in:
- lib/shirobai/cop/layout/space_inside_string_interpolation.rb
Overview
Drop-in Rust reimplementation of Layout/SpaceInsideStringInterpolation.
Stock is an Interpolation + SurroundingSpace cop: for every
interpolation #{...} it reads processed_source.tokens_within(begin_node)
to find the #{` / `} delimiters and the space just inside them — a
per-interpolation token-stream access (the "toucher" cost). Rust does the
whole check from the delimiter byte positions and emits, per offending
delimiter, the offense range plus the autocorrect edits; the wrapper only
builds ranges and replays the edits.
The autocorrect (stock's SpaceCorrector) runs once per interpolation
(stock's ignore_node), so Rust attaches all of an interpolation's edits
to its FIRST offense; the wrapper applies them only on that offense.
Constant Summary collapse
- MSG =
"%<command>s space inside string interpolation."- STYLE_TO_U8 =
{ no_space: 0, space: 1 }.freeze
- COMMANDS =
{ 0 => "Do not use", 1 => "Use" }.freeze
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run:
[style]. - .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
38 |
# File 'lib/shirobai/cop/layout/space_inside_string_interpolation.rb', line 38 def self.badge = RuboCop::Cop::Badge.parse(cop_name) |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: [style].
41 42 43 44 |
# File 'lib/shirobai/cop/layout/space_inside_string_interpolation.rb', line 41 def self.bundle_args(config) own = config.for_badge(badge) [STYLE_TO_U8.fetch((own["EnforcedStyle"] || "no_space").to_sym, 0)] end |
.cop_name ⇒ Object
37 |
# File 'lib/shirobai/cop/layout/space_inside_string_interpolation.rb', line 37 def self.cop_name = "Layout/SpaceInsideStringInterpolation" |
Instance Method Details
#on_new_investigation ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/shirobai/cop/layout/space_inside_string_interpolation.rb', line 46 def on_new_investigation buffer = processed_source.buffer off = SourceOffsets.for(bundle_eligible? ? processed_source.raw_source : buffer.source) offenses_for_source.each do |start, fin, command, edits| range = Parser::Source::Range.new(buffer, off[start], off[fin]) add_offense(range, message: format(MSG, command: COMMANDS.fetch(command))) do |corrector| edits.each do |edit_start, edit_end, insert| if insert corrector.insert_before( Parser::Source::Range.new(buffer, off[edit_start], off[edit_start]), " " ) else corrector.remove(Parser::Source::Range.new(buffer, off[edit_start], off[edit_end])) end end end end end |