Unused assignments are unnecessary and can be removed. In case the declaration is intentional, you can prefix _
before the variable name.
This issue is autofixable, and the behavior of the autofix is tweakable by using the FixType
switch, which accepts either of Replace
or Remove
. The default is to remove the unused assignment.
# Lint/UselessAssignment:
# FixType: Remove
def some_method
some_var = 1
do_something
end
# Lint/UselessAssignment:
# FixType: Remove
def some_method
do_something
end
# Lint/UselessAssignment:
# FixType: Replace
def some_method
some_var = 1
do_something
end
# Lint/UselessAssignment:
# FixType: Replace
def some_method
_some_var = 1
do_something
end