Given the following code:
def x
return if a == 1
y = a + b
c
end
Rubocop only flags a single issue:
Lint/UselessAssignment: Useless assignment to variable - 'y'
This can lead to subtle errors being raised when the above method is actually run.
Rubocop should flag that variables 'a', 'b', and 'c' are all undeclared.
Rubocop does not flag any undeclared variables
Using the following code:
def x
return if a == 1
y = a + b
c
end
$ [bundle exec] rubocop -V
0.71.0 (using Parser 2.6.3.0, running on ruby 2.6.0 x86_64-darwin18)
This is hard because variables are not declared in Ruby. In the example above, a, b, and c are parsed as method calls. And those methods could be inherited and therefore defined in some other source file, making this valid and error-free code.
You are correct. Thanks for the clarification.
Most helpful comment
This is hard because variables are not declared in Ruby. In the example above,
a,b, andcare parsed as method calls. And those methods could be inherited and therefore defined in some other source file, making this valid and error-free code.