Class: Shirobai::Cop::Layout::DotPosition
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::DotPosition
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::ConfigurableEnforcedStyle
- Defined in:
- lib/shirobai/cop/layout/dot_position.rb
Overview
Drop-in Rust reimplementation of ‘Layout/DotPosition`.
Rust finds dots (‘.`/`&.`) that violate the enforced multi-line position and returns the offense range together with the autocorrect ranges (what to remove, where to re-insert the dot). Ruby supplies the style and applies the corrections. Offenses come from the per-file bundled run (`Shirobai::Dispatch`); the style is purely config-driven, so this cop is always bundle-eligible.
Constant Summary collapse
- STYLE_TO_U8 =
{ "leading" => 0, "trailing" => 1 }.freeze
Class Method Summary collapse
- .autocorrect_incompatible_with ⇒ Object
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[style]`.
- .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.autocorrect_incompatible_with ⇒ Object
23 24 25 |
# File 'lib/shirobai/cop/layout/dot_position.rb', line 23 def self.autocorrect_incompatible_with [RuboCop::Cop::Style::RedundantSelf] end |
.badge ⇒ Object
21 |
# File 'lib/shirobai/cop/layout/dot_position.rb', line 21 def self.badge = RuboCop::Cop::Badge.parse("Layout/DotPosition") |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[style]`. `EnforcedStyle` may be absent when the config does not mention this cop (the slice is then discarded); default to `leading` (0) in that case.
30 31 32 |
# File 'lib/shirobai/cop/layout/dot_position.rb', line 30 def self.bundle_args(config) [STYLE_TO_U8[config.for_badge(badge)["EnforcedStyle"]] || 0] end |
.cop_name ⇒ Object
20 |
# File 'lib/shirobai/cop/layout/dot_position.rb', line 20 def self.cop_name = "Layout/DotPosition" |
Instance Method Details
#on_new_investigation ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/shirobai/cop/layout/dot_position.rb', line 34 def on_new_investigation buffer = processed_source.buffer off = SourceOffsets.for(processed_source.raw_source) Dispatch.offenses_for(processed_source, config, :dot_position) .each do |dot_start, dot_end, remove_start, remove_end, insert_pos| dot = Parser::Source::Range.new(buffer, off[dot_start], off[dot_end]) add_offense(dot, message: (dot)) do |corrector| corrector.remove(Parser::Source::Range.new(buffer, off[remove_start], off[remove_end])) insert = off[insert_pos] corrector.insert_before(Parser::Source::Range.new(buffer, insert, insert), dot.source) end end end |