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

False Positive: Lint/InterpolationCheck #5357

Closed
jfelchner opened this issue Dec 29, 2017 · 2 comments
Closed

False Positive: Lint/InterpolationCheck #5357

jfelchner opened this issue Dec 29, 2017 · 2 comments
Assignees
Labels

Comments

@jfelchner
Copy link
Contributor

jfelchner commented Dec 29, 2017

Expected behavior

The cop should understand matching things that look like string interpolations inside a Regex

Actual behavior

Matching \#{20} is matching 20 # in a row, not a string interpolation for a variable named 20

Steps to reproduce the problem

# baz.rb
class Foo
  def bar(qux)
    /\#{20}/
  end
end
> rubocop --only='Lint/InterpolationCheck' baz.rb

Output

Inspecting 1 file
W

Offenses:

baz.rb:3:6: W: Lint/InterpolationCheck: Interpolation in single quoted string detected. Use double quoted strings if you need interpolation.
    /\#{20}/
     ^^^^^^

1 file inspected, 1 offense detected

RuboCop version

$ rubocop -V
0.52.1 (using Parser 2.4.0.2, running on ruby 2.4.3 x86_64-darwin16)
@jfelchner jfelchner changed the title Lint/InterpolationCheck False Positives False Positive: Lint/InterpolationCheck Dec 29, 2017
@bbatsov bbatsov added the bug label Dec 30, 2017
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 30, 2017

I also notice that the message Interpolation in single quoted string detected. Use double quoted strings if you need interpolation. violates our policy to have a single-sentence cop messages. We should fix this as well.

@jamiemccarthy
Copy link

jamiemccarthy commented Jan 3, 2018

I'm seeing this too, also with an escaped # in a double-quoted string. My test case is:

Steps to reproduce the problem

root@ac560a15cb0c:/app# cat interp.rb
# frozen_string_literal: true

class Interp # :nodoc:
  my_string = "\#{msg}"
  puts my_string
end
root@ac560a15cb0c:/app# rubocop interp.rb

Output

Inspecting 1 file
W

Offenses:

interp.rb:4:15: W: Lint/InterpolationCheck: Interpolation in single quoted string detected. Use double quoted strings if you need interpolation.
  my_string = "\#{msg}"
              ^^^^^^^^^

1 file inspected, 1 offense detected

RuboCop version

root@ac560a15cb0c:/app# rubocop -V
0.52.1 (using Parser 2.4.0.2, running on ruby 2.3.5 x86_64-linux)

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

4 participants