From df1776e52e78f9e8282b6724b29a634d702973b4 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Wed, 28 Sep 2022 22:45:13 +0100 Subject: [PATCH] fixup! fixup! [Fixes #10439] Add Style/RedundantStringEscape --- lib/rubocop/cop/style/redundant_string_escape.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/rubocop/cop/style/redundant_string_escape.rb b/lib/rubocop/cop/style/redundant_string_escape.rb index 9f345be5f3c..d148c41f28b 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