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 a false positive for Style/StringLiterals #10166

Merged
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_false_positive_for_style_string_literals.md
@@ -0,0 +1 @@
* [#10166](https://github.com/rubocop/rubocop/pull/10166): Fix a false positive for `Style/StringLiterals` when using some meta characters (e.g. `'\s'`, `'\z'`) with `EnforcedStyle: double_quotes`. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/string_literals_help.rb
Expand Up @@ -17,7 +17,7 @@ def wrong_quotes?(src_or_node)
# 1. It contains a double quote
# 2. It contains text that would become an escape sequence with double quotes
# 3. It contains text that would become an interpolation with double quotes
!/" | (?<!\\)\\[abcefMnrtuUx0-7] | \#[@{$]/x.match?(src)
!/" | (?<!\\)\\[aAbcdefkMnprsStuUxzZ0-7] | \#[@{$]/x.match?(src)
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/rubocop/cop/style/string_literals_spec.rb
Expand Up @@ -277,6 +277,8 @@
c = '#{x}'
d = '#@x'
e = '#$x'
f = '\s'
g = '\z'
RUBY
end

Expand Down