-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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/ConditionalAssignment cop stop working with advanced assignment #3750
Comments
Digging into this example a little bit. Using a default configuration, the example is not registering an offense because the cop thinks that a correction would exceed the maximum configured line length. This appears to be a bug to me because as far as I can tell, a correction would not exceed 80 characters. I will have to do a bit more digging to figure out a solution. |
It looks like the bug is related to the hash being defined across multiple lines. The code we are using to check on the line length isn't properly checking for code across multiple lines. |
…s in ConditionalAssignment
Hello,
I'm an happy user of Rubocop. We use it at work to standardize the way we write our code and today I discovered an edge case where Rubocop fail to report an invalid style.
We like to have assignments before the conditional branches rather than duplicating it in each branch, this is the default behavior of Rubocop.
Expected behavior
Rubocop should report an Style/ConditionalAssignment offense for this code:
because
conditions
is assigned in the branches rather than before theif
.Actual behavior
Everything is ok for Rubocop:
Odd behavior
Rubocop catches the offense if you change unrelated stuff:
Just changed
entity_ids
tofoo_ids
then:There's other ways to get accurate detection:
Now I changed the interpolated string to a raw string:
So it seems like a parsing bug or something but it's really odd.
Steps to reproduce the problem
To reproduce the problem just create a file, paste the provided code in it then run rubocop command on it.
RuboCop version
Same things happen with recent version of Ruby:
Hope you'll have more clue than I have since it seems to be a really tricky bug to track.
The text was updated successfully, but these errors were encountered: