Class: Shirobai::Cop::Layout::SpaceInsideReferenceBrackets
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::SpaceInsideReferenceBrackets
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::RangeHelp, BundleEligible
- Defined in:
- lib/shirobai/cop/layout/space_inside_reference_brackets.rb
Overview
Drop-in Rust reimplementation of Layout/SpaceInsideReferenceBrackets.
Rust checks the bracket pair of every index reference (CallNode
[] / []= plus prism's Index*Write / IndexTarget assignment
forms, which legacy parser folds into send :[] / send :[]=),
reproducing stock's empty-brackets handling (before the multiline
guard), the legacy node extent for multiline?, and the [ \t]
space tests.
The result is [offenses, node_ops] (same shape as
SpaceInsideArrayLiteralBrackets):
- each offense is
[start, end, message_code, node, suppress];suppressmirrors stock'sautocorrect_with_disable_uncorrectable? && !start_okearly return on the right-bracket offense; node_ops[node]is the node's corrector program (SpaceCorrectorreduced to remove / insert-after / insert-before calls), applied on the node's first offense like stock'signore_nodegrouping.
Constant Summary collapse
- MESSAGES =
[ "Use space inside reference brackets.", "Do not use space inside reference brackets.", "Use one space inside empty reference brackets.", "Do not use space inside empty reference brackets." ].freeze
- STYLES =
{ "no_space" => 0, "space" => 1 }.freeze
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run:
[nums, lists]withnums = [EnforcedStyle, EnforcedStyleForEmptyBrackets == 'space']. - .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
40 |
# File 'lib/shirobai/cop/layout/space_inside_reference_brackets.rb', line 40 def self.badge = RuboCop::Cop::Badge.parse(cop_name) |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: [nums, lists] with
nums = [EnforcedStyle, EnforcedStyleForEmptyBrackets == 'space'].
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/shirobai/cop/layout/space_inside_reference_brackets.rb', line 44 def self.bundle_args(config) cop_config = config.for_badge(badge) [ [ STYLES.fetch(cop_config["EnforcedStyle"] || "no_space"), cop_config["EnforcedStyleForEmptyBrackets"] == "space" ? 1 : 0 ], [] ] end |
.cop_name ⇒ Object
39 |
# File 'lib/shirobai/cop/layout/space_inside_reference_brackets.rb', line 39 def self.cop_name = "Layout/SpaceInsideReferenceBrackets" |
Instance Method Details
#on_new_investigation ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/shirobai/cop/layout/space_inside_reference_brackets.rb', line 55 def on_new_investigation buffer = processed_source.buffer source = bundle_eligible? ? processed_source.raw_source : buffer.source off = SourceOffsets.for(source) offenses, node_ops = result_for_source drop_suppressed = autocorrect_with_disable_uncorrectable? corrected = {} offenses.each do |start, fin, code, node, suppress| next if suppress && drop_suppressed range = Parser::Source::Range.new(buffer, off[start], off[fin]) add_offense(range, message: MESSAGES.fetch(code)) do |corrector| unless corrected[node] apply_ops(corrector, buffer, off, node_ops.fetch(node)) end corrected[node] = true end end end |