Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #11089] Fix an error for Style/RedundantStringEscape when using character literals (e.g. ?a) #11090

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_fix_an_error_for_redundant_string_escape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11089](https://github.com/rubocop/rubocop/issues/11089): Fix an error for `Style/RedundantStringEscape` when using character literals (e.g. `?a`). ([@ydah][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/redundant_string_escape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def message(range)
def str_contents_range(node)
if heredoc?(node)
node.loc.heredoc_body
elsif begin_loc_present?(node)
elsif begin_loc_present?(node) && node.loc.end
contents_range(node)
else
node.loc.expression
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/style/redundant_string_escape_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@ def wrap(contents)
end
end

context 'when using character literals (e.g. `?a`)' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
?a
RUBY
end
end

context 'with an interpolation-enabled HEREDOC' do
include_examples 'common no offenses', "<<~MYHEREDOC\n", "\nMYHEREDOC"

Expand Down