Class: Shirobai::Cop::Layout::SpaceInsideParens
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::SpaceInsideParens
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- BundleEligible
- Defined in:
- lib/shirobai/cop/layout/space_inside_parens.rb
Overview
Drop-in Rust reimplementation of Layout/SpaceInsideParens.
Stock iterates sorted_tokens pairwise; Rust reconstructs the pair
facts around every unmasked ( / ) byte (strings, comments, char
literals and __END__ data are the only non-token paren bytes) plus
one AST-collected token fact: the tLPAREN_ARG positions (the
space-separated first-argument paren of a parenless call, which is
not left_parens? and never fires the left-side checks).
Each offense is [start, end, code]: code 0 removes the range
("Space inside parentheses detected."), code 1 inserts a space before
it ("No space inside parentheses detected.").
Constant Summary collapse
- MESSAGES =
[ "Space inside parentheses detected.", "No space inside parentheses detected." ].freeze
- STYLES =
{ "no_space" => 0, "space" => 1, "compact" => 2 }.freeze
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run:
[[EnforcedStyle], []]. - .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
30 |
# File 'lib/shirobai/cop/layout/space_inside_parens.rb', line 30 def self.badge = RuboCop::Cop::Badge.parse(cop_name) |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: [[EnforcedStyle], []].
33 34 35 36 |
# File 'lib/shirobai/cop/layout/space_inside_parens.rb', line 33 def self.bundle_args(config) cop_config = config.for_badge(badge) [[STYLES.fetch(cop_config["EnforcedStyle"] || "no_space")], []] end |
.cop_name ⇒ Object
29 |
# File 'lib/shirobai/cop/layout/space_inside_parens.rb', line 29 def self.cop_name = "Layout/SpaceInsideParens" |
Instance Method Details
#on_new_investigation ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/shirobai/cop/layout/space_inside_parens.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, code| range = Parser::Source::Range.new(buffer, off[start], off[fin]) add_offense(range, message: MESSAGES.fetch(code)) do |corrector| if code.zero? corrector.remove(range) else corrector.insert_before(range, " ") end end end end |