Class: Shirobai::Cop::Style::HashEachMethods
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Style::HashEachMethods
- Extended by:
- RuboCop::Cop::AutoCorrector
- Defined in:
- lib/shirobai/cop/style/hash_each_methods.rb
Overview
Drop-in Rust reimplementation of ‘Style/HashEachMethods`.
Rust parses the source and replicates every stock pattern branch: ‘hash.keys.each` / `hash.values.each` blocks and `&:sym` block-pass forms (rewritten to `each_key` / `each_value`), and two-argument `each` blocks with an unused key/value argument (selector rename plus unused-argument removal), including the `handleable?` gates (array-converter receivers, hash mutation inside the block, literal receivers) and the `AllowedReceivers` receiver-name matching. Ruby supplies the `AllowedReceivers` list and applies the Rust-computed replacement/removal ranges. Offenses come from the per-file bundled run (`Shirobai::Dispatch`); the list is plain strings, so this cop is always bundle-eligible.
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[allowed_receivers]`, replicating `AllowedReceivers#allowed_receivers` stringified for Rust.
- .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
23 |
# File 'lib/shirobai/cop/style/hash_each_methods.rb', line 23 def self.badge = RuboCop::Cop::Badge.parse("Style/HashEachMethods") |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[allowed_receivers]`, replicating `AllowedReceivers#allowed_receivers` stringified for Rust.
27 28 29 |
# File 'lib/shirobai/cop/style/hash_each_methods.rb', line 27 def self.bundle_args(config) [Array(config.for_badge(badge)["AllowedReceivers"]).map(&:to_s)] end |
.cop_name ⇒ Object
22 |
# File 'lib/shirobai/cop/style/hash_each_methods.rb', line 22 def self.cop_name = "Style/HashEachMethods" |
Instance Method Details
#on_new_investigation ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/shirobai/cop/style/hash_each_methods.rb', line 31 def on_new_investigation buffer = processed_source.buffer offenses = Dispatch.offenses_for(processed_source, config, :hash_each_methods) off = SourceOffsets.for(processed_source.raw_source) offenses.each do |start, fin, , rep_start, rep_end, replacement, rem_start, rem_end| range = Parser::Source::Range.new(buffer, off[start], off[fin]) # Stock yields the corrector block for every offense. add_offense(range, message: ) do |corrector| corrector.replace(Parser::Source::Range.new(buffer, off[rep_start], off[rep_end]), replacement) if rem_end > rem_start corrector.remove(Parser::Source::Range.new(buffer, off[rem_start], off[rem_end])) end end end end |