Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style/StringLiterals: reports offense on \u0060 and \u0022 #3056

Closed
nijikon opened this issue Apr 18, 2016 · 2 comments
Closed

Style/StringLiterals: reports offense on \u0060 and \u0022 #3056

nijikon opened this issue Apr 18, 2016 · 2 comments

Comments

@nijikon
Copy link
Contributor

nijikon commented Apr 18, 2016

Expected behavior

Not to return error.

Actual behavior

$ rubocop text.rb
Inspecting 1 file
C

Offenses:

text.rb:1:25: C: Prefer single-quoted strings when you don't need string interpolation or special symbols.
OpenStruct.new(content: "\u0060")
                        ^^^^^^^^
text.rb:3:25: C: Prefer single-quoted strings when you don't need string interpolation or special symbols.
OpenStruct.new(content: "\u0022")
                        ^^^^^^^^

1 file inspected, 2 offenses detected

Steps to reproduce the problem

$ cat text.rb
OpenStruct.new(content: "\u0060")
OpenStruct.new(content: "\u00b4")
OpenStruct.new(content: "\u0022")
OpenStruct.new(content: "\u201d")

RuboCop version

$ rubocop -V
0.39.0 (using Parser 2.3.0.7, running on ruby 2.3.0 x86_64-darwin15)
@mikegee
Copy link
Contributor

mikegee commented Apr 18, 2016

I guess the cop is trying to tell you to switch those two. Autocorrect changes the two that it can:

rubocop master % ./bin/rubocop text.rb --only Style/StringLiterals --auto-correct
Inspecting 1 file
C

Offenses:

text.rb:1:25: C: [Corrected] Prefer single-quoted strings when you don't need string interpolation or special symbols.
OpenStruct.new(content: "\u0060")
                        ^^^^^^^^
text.rb:3:25: C: [Corrected] Prefer single-quoted strings when you don't need string interpolation or special symbols.
OpenStruct.new(content: "\u0022")
                        ^^^^^^^^

1 file inspected, 2 offenses detected, 2 offenses corrected
rubocop master % cat text.rb
OpenStruct.new(content: '`')
OpenStruct.new(content: "\u00b4")
OpenStruct.new(content: '"')
OpenStruct.new(content: "\u201d")

EDIT: Now I'm surprised the other two weren't changed.

pry(main)> "\u00b4" == '´'
true
pry(main)> "\u201d" == '”'
true

@alexdowad
Copy link
Contributor

Now I'm surprised the other two weren't changed.

The other 2 are not ASCII.

This is expected behavior. I suggest this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants