An unused local variable or function can be leftover code, or a sign that the wrong identifier is being used. Remove it when it is no longer needed; otherwise, restore its intended use. This makes it clear which code contributes to the result.
Remove a declaration that has no effect on the calculation.
function numberOfMinutes(hours) {
const seconds = 0; // Noncompliant: "seconds" is never used
return hours * 60;
}
function numberOfMinutes(hours) {
return hours * 60;
}
When destructuring an array, keep the position of the values you use. An empty slot skips a value without declaring a variable.
function getQuery(url) {
const [path, query] = url.split("?"); // Noncompliant: "path" is never used
return query;
}
function getQuery(url) {
const [, query] = url.split("?");
return query;
}
An unused variable’s initializer still runs. Before deleting its declaration, check whether that expression performs required work. For example,
replace const result = saveChanges(); with saveChanges(); if the call is needed but its return value is not.