Class: Shirobai::Cop::Lint::ParenthesesAsGroupedExpression

Inherits:
RuboCop::Cop::Base
  • Object
show all
Extended by:
RuboCop::Cop::AutoCorrector
Defined in:
lib/shirobai/cop/lint/parentheses_as_grouped_expression.rb

Overview

Drop-in Rust reimplementation of ‘Lint/ParenthesesAsGroupedExpression`.

Detection and autocorrect both happen in Rust; Ruby turns the byte offsets handed back into offenses and a single ‘corrector.remove(range)` call (matching stock’s ‘add_offense(range) { |c| c.remove(range) }`).

The cop carries no config (stock has neither ‘EnforcedStyle` nor `AllowedMethods`), so `bundle_args` returns an empty vector and the bundle path is always taken.

Constant Summary collapse

MSG =
"`%<argument>s` interpreted as grouped expression."

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.badgeObject



21
# File 'lib/shirobai/cop/lint/parentheses_as_grouped_expression.rb', line 21

def self.badge = RuboCop::Cop::Badge.parse("Lint/ParenthesesAsGroupedExpression")

.bundle_args(_config) ⇒ Object

Config-less cop. Returns an empty array so ‘Dispatch.packed_config` can splat it without touching `nums` or `lists`.



25
26
27
# File 'lib/shirobai/cop/lint/parentheses_as_grouped_expression.rb', line 25

def self.bundle_args(_config)
  []
end

.cop_nameObject



20
# File 'lib/shirobai/cop/lint/parentheses_as_grouped_expression.rb', line 20

def self.cop_name = "Lint/ParenthesesAsGroupedExpression"

Instance Method Details

#bundle_eligible?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/shirobai/cop/lint/parentheses_as_grouped_expression.rb', line 29

def bundle_eligible?
  true
end

#on_new_investigationObject



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

def on_new_investigation
  buffer = processed_source.buffer
  off = SourceOffsets.for(processed_source.raw_source)
  fetch_offenses.each do |space_start, space_end, arg_start, arg_end|
    range = Parser::Source::Range.new(buffer, off[space_start], off[space_end])
    arg_range = Parser::Source::Range.new(buffer, off[arg_start], off[arg_end])
    message = format(MSG, argument: arg_range.source)
    add_offense(range, message: message) do |corrector|
      corrector.remove(range)
    end
  end
end