Class: Shirobai::Cop::Style::MutableConstant
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Style::MutableConstant
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::ConfigurableEnforcedStyle, RuboCop::Cop::FrozenStringLiteral
- Defined in:
- lib/shirobai/cop/style/mutable_constant.rb
Overview
Drop-in Rust-accelerated reimplementation of Style/MutableConstant.
Style/MutableConstant is almost entirely AST work: the on_casgn
value-mutability check (literal_check / strict_check), the
shareable_constant_value magic-comment scope scan (which reads
processed_source.lines, NOT the token stream), and the .freeze
autocorrect with all its branches (splat expansion, array bracketing,
range / send parenthesizing, recursive nested freezing). That part is
stock's, copied verbatim from
vendor/rubocop/lib/rubocop/cop/style/mutable_constant.rb, so detection
and -A bytes match stock exactly.
The ONE place stock reaches the parser-gem token stream (the "toucher"
cost) is FrozenStringLiteral#frozen_string_literals_enabled?, via
leading_comment_lines -> processed_source.tokens. This wrapper
replaces ONLY that method with the token-free Rust leading-comment scan
(shared with Lint/DuplicateMagicComment /
Style/FrozenStringLiteralComment / Style/EmptyLiteral). Everything
else, including the whole FrozenStringLiteral mixin around it, stays
stock.
Constant Summary collapse
- MSG =
"Freeze mutable objects assigned to constants."
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(_config) ⇒ Object
Not a bundled cop (it dispatches
on_casgnnormally); the only Rust call is the token-freefrozen_string_literals_enabled?helper. - .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
70 |
# File 'lib/shirobai/cop/style/mutable_constant.rb', line 70 def self.badge = RuboCop::Cop::Badge.parse(cop_name) |
.bundle_args(_config) ⇒ Object
Not a bundled cop (it dispatches on_casgn normally); the only Rust
call is the token-free frozen_string_literals_enabled? helper. Kept
for the 4+1 single-source-of-config convention.
75 76 77 |
# File 'lib/shirobai/cop/style/mutable_constant.rb', line 75 def self.bundle_args(_config) [] end |
.cop_name ⇒ Object
69 |
# File 'lib/shirobai/cop/style/mutable_constant.rb', line 69 def self.cop_name = "Style/MutableConstant" |
Instance Method Details
#on_casgn(node) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/shirobai/cop/style/mutable_constant.rb', line 79 def on_casgn(node) if node.expression.nil? # This is only the case for `CONST += ...` or similar parent = node.parent return unless parent.or_asgn_type? # We only care about `CONST ||= ...` on_assignment(parent.children.last) else on_assignment(node.expression) end end |