diff --git a/changelog/fix_a_false_positive_for_style_string_literals.md b/changelog/fix_a_false_positive_for_style_string_literals.md new file mode 100644 index 00000000000..5d634e80531 --- /dev/null +++ b/changelog/fix_a_false_positive_for_style_string_literals.md @@ -0,0 +1 @@ +* [#10229](https://github.com/rubocop/rubocop/pull/10229): Fix a false positive for `Style/StringLiterals` when `EnforcedStyle: double_quotes` and using single quoted string with backslash. ([@koic][]) diff --git a/lib/rubocop/cop/mixin/string_literals_help.rb b/lib/rubocop/cop/mixin/string_literals_help.rb index fba7dceaad0..c43c08dc176 100644 --- a/lib/rubocop/cop/mixin/string_literals_help.rb +++ b/lib/rubocop/cop/mixin/string_literals_help.rb @@ -13,11 +13,7 @@ def wrong_quotes?(src_or_node) if style == :single_quotes !double_quotes_required?(src) else - # The string needs single quotes if: - # 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 - !/" | (?