From 0039834084f3936af7223d7d0e4cbbf6cc34ca63 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Tue, 5 Oct 2021 07:07:11 +0900 Subject: [PATCH] Fix a false positive for `Style/StringLiterals` Follow up to https://github.com/rubocop/rubocop/commit/a7ef72aa8c35336b169c5d78e2925fc27d739fcb#r57503462. This PR fixes a false positive for `Style/StringLiterals` when using some meta characters (e.g. `'\s'`, `'\z'`) with `EnforcedStyle: double_quotes`. --- changelog/fix_false_positive_for_style_string_literals.md | 1 + lib/rubocop/cop/mixin/string_literals_help.rb | 2 +- spec/rubocop/cop/style/string_literals_spec.rb | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelog/fix_false_positive_for_style_string_literals.md diff --git a/changelog/fix_false_positive_for_style_string_literals.md b/changelog/fix_false_positive_for_style_string_literals.md new file mode 100644 index 00000000000..b79452f1d61 --- /dev/null +++ b/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][]) diff --git a/lib/rubocop/cop/mixin/string_literals_help.rb b/lib/rubocop/cop/mixin/string_literals_help.rb index b9d7677dec7..fba7dceaad0 100644 --- a/lib/rubocop/cop/mixin/string_literals_help.rb +++ b/lib/rubocop/cop/mixin/string_literals_help.rb @@ -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 - !/" | (?