You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@marcandre had a partial fix for this, but I was thinking that we'd encounter problems like the one you've described as well. I'm starting to think there was a reason we had constrained this check to comparison ops in the past. 😆
Catching math ops is nevertheless useful as it can catch bugs like foo(arg1) * foo(arg1), where it should be foo(arg1) * foo(arg2) or foo(arg1) * bar(arg1) or even if it is a heavy function call, should be extracted into a variable and then used as var * var.
I think we should change the cop to ignore cases where lhs and rhs of mathematical operations are simple lvar, ivar, etc.
So y = @x * @x or mentioned var * var or y = x * x * 2 will be ignored.
JustinAiken
added a commit
to usertesting/ut_rubocop
that referenced
this issue
Aug 26, 2020
- 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.
Steps to reproduce the problem
I'm thinking this case is out of scope of
Lint/BinaryOperatorWithIdenticalOperands
, just a simple math calculationThis code can be fixed by
But I don't think original code is bad
RuboCop version
Include the output of
rubocop -V
orbundle exec rubocop -V
if using Bundler. Here's an example:The text was updated successfully, but these errors were encountered: