Rubocop Lint/UselessAssignment offense not detected

41 Views Asked by At

With Ruby3.3.0 (rbenv global) and rubocop 1.60.2, I noticed that sometime 'useless assignements' are not detected. Below is an example where offense is detected for foo, but not for bar.

#!/usr/bin/env ruby
foo = 93
foo = 900
foo == 14

bar = 93
bar = 900
[].each do
  bar == 14
end
cop_test.rb:2:1: W: [Correctable] Lint/UselessAssignment: Useless assignment to variable - foo.
foo = 93
^^^
cop_test.rb:4:5: W: [Correctable] Lint/Void: Operator == used in void context.
foo == 14

The 'not detected' code seems to be linked to the test of bar inside a useless each. Note also that both test of foo/bar are useless but it is only detected for foo.

I do not get it,because I suppose that when variable are assigned several time in a row with no code between, it should be detected as an offense.

So, is it some kind of rubopop bug or I'm missing something.

0

There are 0 best solutions below