Skip to content

Commit

Permalink
[Fix rubocop#3037] StringLiterals understands that '#' is the same as…
Browse files Browse the repository at this point in the history
… "#"
  • Loading branch information
alexdowad authored and Neodelf committed Oct 15, 2016
1 parent 69e35de commit 7cedbad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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][])
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/string_literals_help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions spec/rubocop/cop/style/string_literals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7cedbad

Please sign in to comment.