Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4619

Rubocop Lint/UselessAssignment offense not detected

$
0
0

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 rubyfoo = 93foo = 900foo == 14bar = 93bar = 900[].each do  bar == 14end
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.


Viewing all articles
Browse latest Browse all 4619

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>