Why is this an issue?

An unused local variable is a variable that has been declared but is not used anywhere in the block of code where it is defined. It is dead code, contributing to unnecessary complexity and leading to confusion when reading the code. Therefore, it should be removed from your code to maintain clarity and efficiency.

What is the potential impact?

Having unused local variables in your code can lead to several issues:

In summary, unused local variables can make your code less readable, more confusing, and harder to maintain, and they can potentially lead to bugs or inefficient memory use. Therefore, it is best to remove them.

How to fix it

The fix for this issue is straightforward. Once you ensure the unused variable is not part of an incomplete implementation leading to bugs, you just need to remove it.

Code examples

Noncompliant code example

def number_of_minutes(hours)
  seconds = 0 # Noncompliant - seconds is unused
  hours * 60
end

Compliant solution

def number_of_minutes(hours)
  hours * 60
end