Class: Shirobai::Cop::Style::RedundantSelf
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Style::RedundantSelf
- Extended by:
- RuboCop::Cop::AutoCorrector
- Defined in:
- lib/shirobai/cop/style/redundant_self.rb
Overview
Drop-in Rust reimplementation of ‘Style/RedundantSelf`.
Rust walks the AST, tracks local-variable scopes and reports the ‘self` receiver of redundant `self.foo` sends, returning the byte range of `self` plus the `.` operator so Ruby can remove both. Offenses come from the per-file bundled run (`Shirobai::Dispatch`); the allow-list is a load-time constant, so this cop is always bundle-eligible.
Constant Summary collapse
- MSG =
"Redundant `self` detected."- KERNEL_METHODS =
Same timing as stock (‘KERNEL_METHODS = Kernel.methods(false)`): snapshot once at load, not per investigation.
Kernel.methods(false).map(&:to_s).freeze
Class Method Summary collapse
- .autocorrect_incompatible_with ⇒ Object
- .badge ⇒ Object
-
.bundle_args(_config) ⇒ Object
Packed args for the bundled run: ‘[kernel_methods]`.
- .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.autocorrect_incompatible_with ⇒ Object
25 26 27 |
# File 'lib/shirobai/cop/style/redundant_self.rb', line 25 def self.autocorrect_incompatible_with [RuboCop::Cop::Style::ColonMethodCall, RuboCop::Cop::Layout::DotPosition] end |
.badge ⇒ Object
23 |
# File 'lib/shirobai/cop/style/redundant_self.rb', line 23 def self.badge = RuboCop::Cop::Badge.parse("Style/RedundantSelf") |
.bundle_args(_config) ⇒ Object
Packed args for the bundled run: ‘[kernel_methods]`.
30 31 32 |
# File 'lib/shirobai/cop/style/redundant_self.rb', line 30 def self.bundle_args(_config) [KERNEL_METHODS] end |
.cop_name ⇒ Object
22 |
# File 'lib/shirobai/cop/style/redundant_self.rb', line 22 def self.cop_name = "Style/RedundantSelf" |
Instance Method Details
#on_new_investigation ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/shirobai/cop/style/redundant_self.rb', line 34 def on_new_investigation buffer = processed_source.buffer offenses = Dispatch.offenses_for(processed_source, config, :redundant_self) off = SourceOffsets.for(processed_source.raw_source) offenses.each do |self_start, self_end, dot_start, dot_end| range = Parser::Source::Range.new(buffer, off[self_start], off[self_end]) add_offense(range) do |corrector| corrector.remove(range) corrector.remove(Parser::Source::Range.new(buffer, off[dot_start], off[dot_end])) end end end |