From 7cedbad0113e8df7589e27f920a0547002554c65 Mon Sep 17 00:00:00 2001 From: Alex Dowad Date: Tue, 31 May 2016 20:40:21 +0200 Subject: [PATCH] [Fix #3037] StringLiterals understands that '#' is the same as "#" --- CHANGELOG.md | 1 + lib/rubocop/cop/mixin/string_literals_help.rb | 2 +- spec/rubocop/cop/style/string_literals_spec.rb | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e0a456f4cd6..dc244577930a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ ### Bug fixes +* [#3037](https://github.com/bbatsov/rubocop/issues/3037): `Style/StringLiterals` understands that a bare '#', not '#@variable' or '#{interpolation}', does not require double quotes. ([@alexdowad][]) * [#2722](https://github.com/bbatsov/rubocop/issues/2722): `Style/ExtraSpacing` does not attempt to align an equals sign in an argument list with one in an assignment statement. ([@alexdowad][]) * [#3133](https://github.com/bbatsov/rubocop/issues/3133): `Style/MultilineMethodCallBraceLayout` does not register offenses for single-line calls. ([@alexdowad][]) * [#3170](https://github.com/bbatsov/rubocop/issues/3170): `Style/MutableConstant` does not infinite-loop when correcting an array with no brackets. ([@alexdowad][]) diff --git a/lib/rubocop/cop/mixin/string_literals_help.rb b/lib/rubocop/cop/mixin/string_literals_help.rb index 4ff2600888ec..60c29b1de45f 100644 --- a/lib/rubocop/cop/mixin/string_literals_help.rb +++ b/lib/rubocop/cop/mixin/string_literals_help.rb @@ -13,7 +13,7 @@ def wrong_quotes?(node) if style == :single_quotes src !~ /'/ && !double_quotes_acceptable?(node.str_content) else - src !~ /" | \\ | \#/x + src !~ /" | \\ | \#(@|\{)/x end end diff --git a/spec/rubocop/cop/style/string_literals_spec.rb b/spec/rubocop/cop/style/string_literals_spec.rb index 445bc67def40..64f72800d07f 100644 --- a/spec/rubocop/cop/style/string_literals_spec.rb +++ b/spec/rubocop/cop/style/string_literals_spec.rb @@ -212,6 +212,11 @@ expect(cop.offenses).to be_empty end + it 'flags single quotes with plain # (not #@var or #{interpolation}' do + inspect_source(cop, "a = 'blah #'") + expect(cop.offenses.size).to be 1 + end + it 'accepts single quotes at the start of regexp literals' do inspect_source(cop, "s = /'((?:[^\\']|\\.)*)'/") expect(cop.offenses).to be_empty