Class: Shirobai::Cop::Layout::SpaceAroundEqualsInParameterDefault
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::SpaceAroundEqualsInParameterDefault
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::ConfigurableEnforcedStyle, RuboCop::Cop::RangeHelp, BundleEligible
- Defined in:
- lib/shirobai/cop/layout/space_around_equals_in_parameter_default.rb
Overview
Drop-in Rust reimplementation of Layout/SpaceAroundEqualsInParameterDefault.
Rust walks the AST once and emits one [start, end] range per offending
optarg — range_between(arg.end_pos, value.begin_pos), stock's offense
range — computed straight from the OptionalParameterNode's name_loc
/ operator_loc / value positions and the two space_after? byte
checks (\s at the arg-name end and at the = end). This replaces
stock's processed_source.tokens_within(node) token access, the "toucher"
cost, with prism-native node positions.
The wrapper reproduces stock's message (missing under space,
detected under no_space) and its /=\s*(\S+)/ autocorrect verbatim
on the Ruby side, so detection and autocorrect are byte-identical.
Constant Summary collapse
- MSG =
"Surrounding space %<type>s in default value assignment."- STYLE_TO_U8 =
{ space: 0, no_space: 1 }.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
33 |
# File 'lib/shirobai/cop/layout/space_around_equals_in_parameter_default.rb', line 33 def self.badge = RuboCop::Cop::Badge.parse(cop_name) |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: [style].
36 37 38 39 40 |
# File 'lib/shirobai/cop/layout/space_around_equals_in_parameter_default.rb', line 36 def self.bundle_args(config) own = config.for_badge(badge) style = STYLE_TO_U8.fetch((own["EnforcedStyle"] || "space").to_sym, 0) [style] end |
.cop_name ⇒ Object
32 |
# File 'lib/shirobai/cop/layout/space_around_equals_in_parameter_default.rb', line 32 def self.cop_name = "Layout/SpaceAroundEqualsInParameterDefault" |
Instance Method Details
#on_new_investigation ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/shirobai/cop/layout/space_around_equals_in_parameter_default.rb', line 42 def on_new_investigation buffer = processed_source.buffer source = bundle_eligible? ? processed_source.raw_source : buffer.source off = SourceOffsets.for(source) type = style == :space ? "missing" : "detected" offenses_for_source.each do |start, fin| range = Parser::Source::Range.new(buffer, off[start], off[fin]) add_offense(range, message: format(MSG, type: type)) do |corrector| autocorrect(corrector, range) end end end |