Class: Shirobai::Cop::Layout::MultilineOperationIndentation
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::MultilineOperationIndentation
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::Alignment, RuboCop::Cop::ConfigurableEnforcedStyle
- Defined in:
- lib/shirobai/cop/layout/multiline_operation_indentation.rb
Overview
Drop-in Rust reimplementation of ‘Layout/MultilineOperationIndentation`.
Rust parses the source, finds binary operations whose right-hand operand is misindented, and returns the offending range together with the column delta and the formatted message. Ruby supplies the flattened config (style + indentation widths) and applies the realignment via ‘AlignmentCorrector`. 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 }.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
23 |
# File 'lib/shirobai/cop/layout/multiline_operation_indentation.rb', line 23 def self.badge = RuboCop::Cop::Badge.parse("Layout/MultilineOperationIndentation") |
.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.
30 31 32 33 34 |
# File 'lib/shirobai/cop/layout/multiline_operation_indentation.rb', line 30 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
22 |
# File 'lib/shirobai/cop/layout/multiline_operation_indentation.rb', line 22 def self.cop_name = "Layout/MultilineOperationIndentation" |
Instance Method Details
#on_new_investigation ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/shirobai/cop/layout/multiline_operation_indentation.rb', line 46 def on_new_investigation buffer = processed_source.buffer offenses = Dispatch.offenses_for(processed_source, config, :multiline_operation) off = SourceOffsets.for(processed_source.raw_source) offenses.each do |start, fin, column_delta, | range = Parser::Source::Range.new(buffer, off[start], off[fin]) add_offense(range, message: ) do |corrector| RuboCop::Cop::AlignmentCorrector.correct(corrector, processed_source, range, column_delta) end end end |
#validate_config ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/shirobai/cop/layout/multiline_operation_indentation.rb', line 36 def validate_config return unless style == :aligned && cop_config["IndentationWidth"] raise RuboCop::ValidationError, "The `Layout/MultilineOperationIndentation` " \ "cop only accepts an `IndentationWidth` " \ "configuration parameter when " \ "`EnforcedStyle` is `indented`." end |