Class: Shirobai::Cop::Lint::SelfAssignment
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Lint::SelfAssignment
- Defined in:
- lib/shirobai/cop/lint/self_assignment.rb
Overview
Drop-in Rust reimplementation of ‘Lint/SelfAssignment`.
The detection (lvasgn/ivasgn/cvasgn/gvasgn/casgn rhs equals lhs name, masgn pair-wise self-assignment, or_asgn/and_asgn, attribute setter and ‘[]=` self-assignment) happens entirely in Rust. Ruby only:
-
Turns byte offsets into offenses.
-
Filters by ‘AllowRBSInlineAnnotation` when that config is `true` — using stock’s exact code path (‘processed_source.ast_with_comments`), keyed off the anchor node Rust returned per offense. When the config is the default `false` we skip the lookup entirely so the common case stays fast.
Constant Summary collapse
- MSG =
"Self-assignment detected."
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(_config) ⇒ Object
Config is fully handled on the Ruby side (RBS lookup needs ‘processed_source.ast_with_comments`, only available here), so the bundle takes no per-cop args.
- .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
22 |
# File 'lib/shirobai/cop/lint/self_assignment.rb', line 22 def self.badge = RuboCop::Cop::Badge.parse("Lint/SelfAssignment") |
.bundle_args(_config) ⇒ Object
Config is fully handled on the Ruby side (RBS lookup needs ‘processed_source.ast_with_comments`, only available here), so the bundle takes no per-cop args.
27 |
# File 'lib/shirobai/cop/lint/self_assignment.rb', line 27 def self.bundle_args(_config) = [] |
.cop_name ⇒ Object
21 |
# File 'lib/shirobai/cop/lint/self_assignment.rb', line 21 def self.cop_name = "Lint/SelfAssignment" |
Instance Method Details
#on_new_investigation ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/shirobai/cop/lint/self_assignment.rb', line 29 def on_new_investigation offenses = Dispatch.offenses_for(processed_source, config, :self_assignment) return if offenses.empty? off = SourceOffsets.for(processed_source.raw_source) buffer = processed_source.buffer allow_rbs = !!cop_config["AllowRBSInlineAnnotation"] anchor_index = allow_rbs ? build_anchor_index : nil offenses.each do |start_offset, end_offset, anchor_offset| if allow_rbs && rbs_annotation_at?(anchor_index, anchor_offset) next end range = Parser::Source::Range.new(buffer, off[start_offset], off[end_offset]) add_offense(range) end end |