Class: Shirobai::Cop::Layout::FirstArrayElementIndentation
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::FirstArrayElementIndentation
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::Alignment
- Defined in:
- lib/shirobai/cop/layout/first_array_element_indentation.rb
Overview
Drop-in Rust reimplementation of ‘Layout/FirstArrayElementIndentation`.
Rust parses the source, walks every array literal (replicating the ‘each_argument_node` / `ignore_node` claiming of arrays by a method call’s left parenthesis), decides the alignment base for the configured ‘EnforcedStyle` (bracket / after-paren / parent hash key / start of line) and returns each misindented first element and hanging right bracket as an offense range plus its `column_delta` and message. Ruby supplies the flattened config and applies the realignment via `AlignmentCorrector` (the same division of labour as the other alignment cops). 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
- STYLES =
{ "special_inside_parentheses" => 0, "consistent" => 1, "align_brackets" => 2 }.freeze
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[style, indentation_width, enforce_fixed_indentation]`.
- .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
30 |
# File 'lib/shirobai/cop/layout/first_array_element_indentation.rb', line 30 def self.badge = RuboCop::Cop::Badge.parse("Layout/FirstArrayElementIndentation") |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[style, indentation_width, enforce_fixed_indentation]`. The enforce flag replicates `enforce_first_argument_with_fixed_indentation?`: the cop stands down (except in `consistent` style) when `Layout/ArrayAlignment` enforces `with_fixed_indentation`.
37 38 39 40 41 42 43 44 45 |
# File 'lib/shirobai/cop/layout/first_array_element_indentation.rb', line 37 def self.bundle_args(config) cop_config = config.for_badge(badge) array_alignment_config = config.for_enabled_cop("Layout/ArrayAlignment") [ STYLES.fetch(cop_config["EnforcedStyle"], 0), cop_config["IndentationWidth"] || config.for_cop("Layout/IndentationWidth")["Width"] || 2, array_alignment_config["EnforcedStyle"] == "with_fixed_indentation" ] end |
.cop_name ⇒ Object
29 |
# File 'lib/shirobai/cop/layout/first_array_element_indentation.rb', line 29 def self.cop_name = "Layout/FirstArrayElementIndentation" |
Instance Method Details
#on_new_investigation ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/shirobai/cop/layout/first_array_element_indentation.rb', line 47 def on_new_investigation buffer = processed_source.buffer offenses = Dispatch.offenses_for(processed_source, config, :first_array_element_indentation) off = SourceOffsets.for(processed_source.raw_source) offenses.each do |start, fin, column_delta, | range = Parser::Source::Range.new(buffer, off[start], off[fin]) # Stock yields the corrector block for every offense (no # per-offense gating), passing the first element NODE — so # `AlignmentCorrector` skips lines inside its string literals / # heredocs (`inside_string_ranges`) — but the right bracket RANGE. # Resolve the node by exact range to keep multiline-element # corrections identical; a `]` range never coincides with a node # and falls through to the range, exactly like stock. target = node_for(range) || range add_offense(range, message: ) do |corrector| RuboCop::Cop::AlignmentCorrector.correct( corrector, processed_source, target, column_delta ) end end end |