Class: Shirobai::Cop::Layout::MultilineMethodCallIndentation
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::MultilineMethodCallIndentation
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::Alignment, RuboCop::Cop::ConfigurableEnforcedStyle, RuboCop::Cop::RangeHelp
- Defined in:
- lib/shirobai/cop/layout/multiline_method_call_indentation.rb
Overview
Drop-in Rust reimplementation of ‘Layout/MultilineMethodCallIndentation`.
Rust parses the source, finds ‘.`-chained method calls whose selector is misindented across lines, and returns the offending range, the column delta and the formatted message. Ruby supplies the flattened config (style + indentation widths) and applies the realignment via `AlignmentCorrector` (special-casing calls that carry a multiline block). Offenses come from the per-file bundled run (`Shirobai::Dispatch`); the config derivation is purely config-driven, so this cop is always bundle-eligible.
Constant Summary collapse
- STYLE_MAP =
{ "aligned" => 0, "indented" => 1, "indented_relative_to_receiver" => 2 }.freeze
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[style, indentation_width, base_indentation_width]`.
- .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
25 |
# File 'lib/shirobai/cop/layout/multiline_method_call_indentation.rb', line 25 def self.badge = RuboCop::Cop::Badge.parse("Layout/MultilineMethodCallIndentation") |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[style, indentation_width, base_indentation_width]`. `EnforcedStyle` is absent when the config does not mention this cop (e.g. a spec configures only the sibling multiline cop, and this cop’s offenses are discarded); default to the first supported style (‘0`) in that case.
32 33 34 35 36 |
# File 'lib/shirobai/cop/layout/multiline_method_call_indentation.rb', line 32 def self.bundle_args(config) cop_config = config.for_badge(badge) base = config.for_cop("Layout/IndentationWidth")["Width"] || 2 [STYLE_MAP[cop_config["EnforcedStyle"]] || 0, cop_config["IndentationWidth"] || base, base] end |
.cop_name ⇒ Object
24 |
# File 'lib/shirobai/cop/layout/multiline_method_call_indentation.rb', line 24 def self.cop_name = "Layout/MultilineMethodCallIndentation" |
Instance Method Details
#on_new_investigation ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/shirobai/cop/layout/multiline_method_call_indentation.rb', line 48 def on_new_investigation buffer = processed_source.buffer offenses = Dispatch.offenses_for(processed_source, config, :multiline_method_call) off = SourceOffsets.for(processed_source.raw_source) offenses.each do |start, fin, column_delta, , body_s, body_e, end_s, end_e| range = Parser::Source::Range.new(buffer, off[start], off[fin]) add_offense(range, message: ) do |corrector| if end_e > end_s correct_with_block(corrector, range, column_delta, buffer, off[body_s], off[body_e], off[end_s], off[end_e]) else RuboCop::Cop::AlignmentCorrector.correct(corrector, processed_source, range, column_delta) end end end end |
#validate_config ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/shirobai/cop/layout/multiline_method_call_indentation.rb', line 38 def validate_config return unless style == :aligned && cop_config["IndentationWidth"] raise RuboCop::ValidationError, "The `Layout/MultilineMethodCallIndentation` " \ "cop only accepts an `IndentationWidth` " \ "configuration parameter when " \ "`EnforcedStyle` is `indented`." end |