Class: Shirobai::Cop::Style::RedundantFreeze
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Style::RedundantFreeze
- Extended by:
- RuboCop::Cop::AutoCorrector
- Defined in:
- lib/shirobai/cop/style/redundant_freeze.rb
Overview
Drop-in Rust reimplementation of Style/RedundantFreeze.
Detection and autocorrect both happen in Rust; Ruby turns each tuple
into an offense on the send node and two corrector.remove calls (the
. and the freeze selector), matching stock's
corrector.remove(node.loc.dot) + corrector.remove(node.loc.selector).
The Rust side reproduces the FrozenStringLiteral mixin's
frozen_string_literals_enabled? on raw bytes, so this cop no longer
needs the parser token stream the mixin's leading_comment_lines would
otherwise build.
bundle_args carries the two config-derived booleans the cop depends on
(AllCops/TargetRubyVersion >= 3.0 and whether
AllCops/StringLiteralsFrozenByDefault is literally true); everything
else is decided from the source, so the bundle path is always taken.
Constant Summary collapse
- MSG =
"Do not freeze immutable objects, as freezing them has no effect."
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed config nums:
[target_ruby_30_plus, string_literals_frozen_by_default]. - .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
28 |
# File 'lib/shirobai/cop/style/redundant_freeze.rb', line 28 def self.badge = RuboCop::Cop::Badge.parse("Style/RedundantFreeze") |
.bundle_args(config) ⇒ Object
Packed config nums: [target_ruby_30_plus, string_literals_frozen_by_default].
string_literals_frozen_by_default? may be nil/false/true; only
a literal true enables the fallback (nil and false both mean "not
frozen by default"), so we pass a plain boolean.
34 35 36 37 38 39 |
# File 'lib/shirobai/cop/style/redundant_freeze.rb', line 34 def self.bundle_args(config) [[ config.target_ruby_version >= 3.0 ? 1 : 0, config.string_literals_frozen_by_default? == true ? 1 : 0 ]] end |
.cop_name ⇒ Object
27 |
# File 'lib/shirobai/cop/style/redundant_freeze.rb', line 27 def self.cop_name = "Style/RedundantFreeze" |
Instance Method Details
#bundle_eligible? ⇒ Boolean
41 42 43 |
# File 'lib/shirobai/cop/style/redundant_freeze.rb', line 41 def bundle_eligible? true end |
#on_new_investigation ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/shirobai/cop/style/redundant_freeze.rb', line 45 def on_new_investigation buffer = processed_source.buffer off = SourceOffsets.for(processed_source.raw_source) fetch_offenses.each do |off_start, off_end, dot_start, dot_end, sel_start, sel_end| range = Parser::Source::Range.new(buffer, off[off_start], off[off_end]) add_offense(range) do |corrector| dot = Parser::Source::Range.new(buffer, off[dot_start], off[dot_end]) selector = Parser::Source::Range.new(buffer, off[sel_start], off[sel_end]) corrector.remove(dot) corrector.remove(selector) end end end |