diff --git a/lib/rubocop/cop/style/redundant_string_escape.rb b/lib/rubocop/cop/style/redundant_string_escape.rb index 9f345be5f3c9..d148c41f28bd 100644 --- a/lib/rubocop/cop/style/redundant_string_escape.rb +++ b/lib/rubocop/cop/style/redundant_string_escape.rb @@ -50,7 +50,7 @@ def on_str(node) each_match_range(str_contents_range, /(\\.)/) do |range| next if allowed_escape?(node, range.resize(3)) - add_offense(range, message: format(MSG, char: range.source.chars.last)) do |corrector| + add_offense(range) do |corrector| corrector.remove_leading(range, 1) end end @@ -58,6 +58,10 @@ def on_str(node) private + def message(range) + format(MSG, char: range.source.chars.last) + end + def str_contents_range(node) if heredoc?(node) node.loc.heredoc_body