Unused local variables and functions should be removed

  • UNUSED_DECL
  • Code Quality
  • Low
  • No tags

This rule applies when local variables and functions are declared but not used.

For maintainability, it is recommended to remove unused code. Also, it might be a mistake that a programmer forgets to use declared variables and functions.

Noncompliant Code Example

function foo() {
    function unusedFunction() { // UNUSED_DECL alarm because local variable 'unusedFunction' is not used.
    }
    var bar = 1;
    var unused_var; // UNUSED_DECL alarm because local variable 'unused_var' is not used.
    doSomething(bar);
}

function doSomethinng(bar) {
}

Compliant Code Example

function foo() {
    var bar = 1;
    doSomething(bar);
}

function doSomethinng(bar) {
}

Version

This rule was introduced in DeepScan 1.0.0-alpha.