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/UnneededPercentQ complaining about dynamic string that's using double quote #2413

Closed
DMA57361 opened this issue Nov 10, 2015 · 2 comments
Assignees
Labels

Comments

@DMA57361
Copy link

We're using %Q() to wrap a piece of text with double quotes like so %Q("#{text}"), but Style/UnneededPercentQ is telling me this is not acceptable.

The cop states "Use %Q only for strings that ... or for dynamic strings that contain double quotes." so, if I've understood correctly, shouldn't this usage - a dynamic string including double quotes - be acceptable?

Example file:

text = 'something'
result = %Q("#{text}")

Result:

$ rubocop example.rb --only Style/UnneededPercentQ
C

Offenses:

example.rb:2:6: C: Style/UnneededPercentQ: Use %Q only for strings that contain both single quotes and double quotes, or for dynamic strings that contain double quotes.
result = %Q("#{text}")
         ^^^^^^^^^^^^^

1 file inspected, 1 offense detected
@mikegee
Copy link
Contributor

mikegee commented Nov 10, 2015

I confirmed this as a bug. Also, auto-correct changes that line to result = '"#{text}"'.

Besides the point, but the issue can be worked around with: result = text.inspect

@jonas054 jonas054 self-assigned this Nov 11, 2015
@jonas054 jonas054 added the bug label Nov 11, 2015
@alexdowad
Copy link
Contributor

On HEAD, this produces the following warning:

Use % instead of %Q.

...which is correct. Autocorrection also works. Therefore, this issue can be closed.

@bbatsov bbatsov closed this as completed Dec 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants