Skip to content

Commit

Permalink
Fix a false positive for Style/StringLiterals
Browse files Browse the repository at this point in the history
Follow up to a7ef72a#r57503462.

This PR fixes a false positive for `Style/StringLiterals` when using
some meta characters (e.g. `'\s'`, `'\z'`) with `EnforcedStyle: double_quotes`.
  • Loading branch information
koic committed Oct 20, 2021
1 parent 5b27789 commit 0039834
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
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

0 comments on commit 0039834

Please sign in to comment.