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

YodaCondition false positive on string interpolation #8185

Closed
DawidJanczak opened this issue Jun 22, 2020 · 0 comments · Fixed by #8186
Closed

YodaCondition false positive on string interpolation #8185

DawidJanczak opened this issue Jun 22, 2020 · 0 comments · Fixed by #8186

Comments

@DawidJanczak
Copy link

Yoda condition cop is fired in a situation where the left side is an interpolated string and right hand side is a constant. It works fine if string interpolation is removed.


Expected behavior

I expect YodaCondition not to be reported when comparing an interpolated string (left side) to a constant (right side).

Actual behavior

YodaCondition gets triggered.

Steps to reproduce the problem

The following triggers the cop: "/#{foo}" == CONSTANT and I don't think it should as the right hand side is constant and left hand side is not.

RuboCop version

0.85.1

koic added a commit to koic/rubocop that referenced this issue Jun 22, 2020
Fixes rubocop#8185.

This PR fixes a false positive for `Style/YodaCondition` when
interpolation is used on the left side.

String interpolation (and Regexp interpolation) contains variables,
I think it's acceptable to use it on the left hand side.
bbatsov pushed a commit that referenced this issue Jun 22, 2020
Fixes #8185.

This PR fixes a false positive for `Style/YodaCondition` when
interpolation is used on the left side.

String interpolation (and Regexp interpolation) contains variables,
I think it's acceptable to use it on the left hand side.
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

Successfully merging a pull request may close this issue.

1 participant