Class: Shirobai::Cop::Style::LineEndConcatenation
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Style::LineEndConcatenation
- Extended by:
- RuboCop::Cop::AutoCorrector
- Defined in:
- lib/shirobai/cop/style/line_end_concatenation.rb
Overview
Drop-in Rust reimplementation of ‘Style/LineEndConcatenation`.
Rust detects string literal concatenations broken across lines with ‘+` or `<<` and computes the autocorrection range. Ruby reports the offense and replaces the operator (plus trailing whitespace) with ``. Offenses come from the per-file bundled run (`Shirobai::Dispatch`); the cop has no configuration, so it is always bundle-eligible.
Constant Summary collapse
- MSG =
"Use `\\` instead of `%<operator>s` to concatenate multiline strings."
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.autocorrect_incompatible_with ⇒ Object
21 22 23 |
# File 'lib/shirobai/cop/style/line_end_concatenation.rb', line 21 def self.autocorrect_incompatible_with [RuboCop::Cop::Style::RedundantInterpolation] end |
.badge ⇒ Object
19 |
# File 'lib/shirobai/cop/style/line_end_concatenation.rb', line 19 def self.badge = RuboCop::Cop::Badge.parse("Style/LineEndConcatenation") |
.cop_name ⇒ Object
18 |
# File 'lib/shirobai/cop/style/line_end_concatenation.rb', line 18 def self.cop_name = "Style/LineEndConcatenation" |
Instance Method Details
#on_new_investigation ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/shirobai/cop/style/line_end_concatenation.rb', line 25 def on_new_investigation buffer = processed_source.buffer offenses = Dispatch.offenses_for(processed_source, config, :line_end_concatenation) off = SourceOffsets.for(processed_source.raw_source) offenses.each do |op_start, op_end, operator, replace_start, replace_end| range = Parser::Source::Range.new(buffer, off[op_start], off[op_end]) = format(MSG, operator: operator) add_offense(range, message: ) do |corrector| replace_range = Parser::Source::Range.new(buffer, off[replace_start], off[replace_end]) corrector.replace(replace_range, "\\") end end end |