Class: Shirobai::Cop::Performance::EndWith
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Performance::EndWith
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::RegexpMetacharacter, BundleEligible
- Defined in:
- lib/shirobai/cop/performance/end_with.rb
Overview
Drop-in Rust reimplementation of Performance/EndWith
(rubocop-performance 1.26.1).
Rust replicates the stock pattern union (regexp argument first,
then regexp receiver; &. only on the argument side) with the
literal_at_end? gate: content is LITERAL_REGEX-only and anchored
with \z (or $ when SafeMultiline is false). The wrapper
rebuilds the replacement exactly like stock — with the
rubocop-performance RegexpMetacharacter mixin's
drop_end_metacharacter and RuboCop's own
interpret_string_escapes / to_string_literal — so anchor
dropping, escape interpretation and quote selection cannot drift.
Constant Summary collapse
- MSG =
"Use `String#end_with?` instead of a regex match anchored " \ "to the end of the string."
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run:
[safe_multiline](0/1). - .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
27 |
# File 'lib/shirobai/cop/performance/end_with.rb', line 27 def self.badge = RuboCop::Cop::Badge.parse(cop_name) |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: [safe_multiline] (0/1).
30 31 32 |
# File 'lib/shirobai/cop/performance/end_with.rb', line 30 def self.bundle_args(config) [config.for_badge(badge).fetch("SafeMultiline", true) ? 1 : 0] end |
.cop_name ⇒ Object
26 |
# File 'lib/shirobai/cop/performance/end_with.rb', line 26 def self.cop_name = "Performance/EndWith" |
Instance Method Details
#on_new_investigation ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/shirobai/cop/performance/end_with.rb', line 34 def on_new_investigation buffer = processed_source.buffer source = bundle_eligible? ? processed_source.raw_source : buffer.source off = SourceOffsets.for(source) resolved_offenses.each do |start, fin, recv_start, recv_end, dot, content| range = Parser::Source::Range.new(buffer, off[start], off[fin]) add_offense(range) do |corrector| receiver_source = Parser::Source::Range.new(buffer, off[recv_start], off[recv_end]).source literal = to_string_literal( interpret_string_escapes((content)) ) corrector.replace(range, "#{receiver_source}#{dot}end_with?(#{literal})") end end end |