Unused local variables and functions should be removed
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.
Note:
_
because we regard it as intentionally unused.const
variable holdsthis
context because it is often used as boilerplate (e.g.const self = this;
).Noncompliant Code Example | Compliant Code Example | ||
---|---|---|---|
1 | function foo() { | 1 | function foo() { |
2 | function unusedFunction() { // UNUSED_DECL alarm because local variable 'unusedFunction' is not used. | ||
3 | } | ||
4 | let bar = 1; | 2 | let bar = 1; |
5 | let unusedVar; // UNUSED_DECL alarm because local variable 'unusedVar' is not used. | ||
6 | doSomething(bar); | 3 | doSomething(bar); |
7 | } | 4 | } |
function foo() { function unusedFunction() { // UNUSED_DECL alarm because local variable 'unusedFunction' is not used. } let bar = 1; let unusedVar; // UNUSED_DECL alarm because local variable 'unusedVar' is not used. doSomething(bar);}
function foo() { let bar = 1; doSomething(bar);}
This rule was introduced in DeepScan 1.0.0-alpha.