Class: Shirobai::Cop::Lint::Void
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Lint::Void
- Extended by:
- RuboCop::Cop::AutoCorrector
- Defined in:
- lib/shirobai/cop/lint/void.rb
Overview
Drop-in Rust reimplementation of ‘Lint/Void`.
Rust parses the source and replicates stock’s statement-position analysis: parser ‘begin`-equivalent sequences (multi-statement bodies, parentheses, keyword `begin`), single-expression block bodies (`on_block`) and ensure branches (`on_ensure`), with the `in_void_context?` parents (`initialize`/setter defs, `each`/`tap` blocks, `for` bodies, `ensure` branches) and the each-block operator suppression. Every offense category (operator / variable / constant / literal / `self` / `defined?` / lambda-or-proc / nonmutating method) carries its stock message and its correction as a Rust-computed replace + remove pair; the no-correction cases (conditional branch bodies, assignment-method defs) come back with both ranges empty so the corrector block still runs and stays empty, exactly like stock’s bail-out paths. Ruby supplies the ‘CheckForMethodsWithNoSideEffects` flag and applies the ranges. Offenses come from the per-file bundled run (`Shirobai::Dispatch`); the config is one boolean, so this cop is always bundle-eligible.
Constant Summary collapse
- BINARY_OPERATORS =
Referenced by the vendor spec (‘described_class::BINARY_OPERATORS`).
%i[* / % + - == === != < > <= >= <=>].freeze
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[check_for_methods_with_no_side_effects]`.
- .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
31 |
# File 'lib/shirobai/cop/lint/void.rb', line 31 def self.badge = RuboCop::Cop::Badge.parse("Lint/Void") |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[check_for_methods_with_no_side_effects]`.
34 35 36 |
# File 'lib/shirobai/cop/lint/void.rb', line 34 def self.bundle_args(config) [!!config.for_badge(badge)["CheckForMethodsWithNoSideEffects"]] end |
.cop_name ⇒ Object
30 |
# File 'lib/shirobai/cop/lint/void.rb', line 30 def self.cop_name = "Lint/Void" |
Instance Method Details
#on_new_investigation ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/shirobai/cop/lint/void.rb', line 38 def on_new_investigation buffer = processed_source.buffer offenses = Dispatch.offenses_for(processed_source, config, :void) 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 (the # uncorrectable cases simply leave it empty). add_offense(range, message: ) do |corrector| if rep_end > rep_start corrector.replace(Parser::Source::Range.new(buffer, off[rep_start], off[rep_end]), replacement) end if rem_end > rem_start corrector.remove(Parser::Source::Range.new(buffer, off[rem_start], off[rem_end])) end end end end |