Class: Shirobai::Cop::Layout::SpaceInsideArrayLiteralBrackets
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::SpaceInsideArrayLiteralBrackets
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::RangeHelp
- Defined in:
- lib/shirobai/cop/layout/space_inside_array_literal_brackets.rb
Overview
Drop-in Rust reimplementation of Layout/SpaceInsideArrayLiteralBrackets.
Rust walks the AST once, replicating stock's on_array /
on_array_pattern over square-bracket array literals and array
patterns (percent arrays and reference brackets never fire), including
stock's find_node_with_brackets redirect of array patterns to their
nearest constant pattern and its first/last bracket-token pair.
The result is [offenses, node_ops]:
- each offense is
[start, end, message_code, node, suppress];suppressmirrors stock'sautocorrect_with_disable_uncorrectable? && !start_okearly return, so the offense is dropped when that mode is active; node_ops[node]is the node's corrector program (SpaceCorrector/compact_correctionsreduced 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 array brackets.", "Do not use space inside array brackets.", "Use one space inside empty array brackets.", "Do not use space inside empty array brackets." ].freeze
- STYLES =
{ "no_space" => 0, "space" => 1, "compact" => 2 }.freeze
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run:
[nums, lists]withnums = [EnforcedStyle, EnforcedStyleForEmptyBrackets == 'space']and no lists. - .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
38 |
# File 'lib/shirobai/cop/layout/space_inside_array_literal_brackets.rb', line 38 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']
and no lists.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/shirobai/cop/layout/space_inside_array_literal_brackets.rb', line 43 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
37 |
# File 'lib/shirobai/cop/layout/space_inside_array_literal_brackets.rb', line 37 def self.cop_name = "Layout/SpaceInsideArrayLiteralBrackets" |
Instance Method Details
#on_new_investigation ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/shirobai/cop/layout/space_inside_array_literal_brackets.rb', line 54 def on_new_investigation buffer = processed_source.buffer off = SourceOffsets.for(processed_source.raw_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 |