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
Lint/BinaryOperatorWithIdenticalOperands makes no sense with bitwise shift operators #8478
Comments
Agreed, we could lookout for that exact case |
I've relaxed the checks for any integers and binary operators; I doubt there will be many invalid uses of |
…or mathematical operations Simplified one of the `basic_literal?`, since we'd only raise an offense if they are equal, in which case `basic_literal?` has the same result on both `lhs` and `rhs`...
Fixed. Thanks for raising this issue 👍 |
Thanks, @marcandre! |
same applies to rubocop now complains about |
I see @marcandre covered |
Right... Is this a theoretical issue or do you actually have such a need? I'm curious to use cases. |
it { expect( batch_job.reduce(0) { |val, item_val| val + item_val**item_val } ).to eq 287 } |
@marcandre maybe it isn't a bad thing that rubocop catch those and we can add them to our ignore list if it make sense. I'm sure happy to see |
Cool. I must admit I still have no idea what your |
true that, honestly, I didn't wrote it, its part of the code base I am maintaining. and you are probably right, maybe its worth trashing ;) |
Well, I guess this proves that the cop is helpful in its current form. 😉 |
- It was just added in 0.89.0 - It finds errors in simple math operations, has many errors reported, such as: - rubocop/rubocop#8482 - rubocop/rubocop#8478 It looks like the next version of rubocop may loosen it a bit, but let's just disable it for now.
Lint/BinaryOperatorWithIdenticalOperands reports an offense with the following code:
an offense is flagged in the line
is_constructor: (1 << 1),
.While for most binary operators, the result of
foo [op] foo
can be replaced by a constant orfoo
regardless of the value offoo
, this is not the case for the shift operators:1 << 1
has a completely different result from['a'] << ['a']
.Expected behavior
No offense is flagged in the above code
Actual behavior
RuboCop flags an offense, e.g.:
Steps to reproduce the problem
Put the code at the top in a ruby file and run rubocop on it.
RuboCop version
The text was updated successfully, but these errors were encountered: