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.
Note:
- Not applied when the name of a
const
variable consists of just_
or containsignore
orfake
because it could be a programmer's intention that the initialized value is not to be used. - Not applied when the value of a
const
variable holdsthis
context because it is often used as boilerplate (e.g.const self = this;
). - Not applied at test case code because unused declarations are usually harmless at tests and tend to occur more. Currently, BDD, TDD and QUnit style test cases are recognized.
Noncompliant Code Example
View with compliant examples side by sidefunction foo() {
function unusedFunction() { // UNUSED_DECL alarm because local variable 'unusedFunction' is not used.
}
var bar = 1;
var unusedVar; // UNUSED_DECL alarm because local variable 'unusedVar' is not used.
doSomething(bar);
}
Compliant Code Example
View with noncompliant examples side by sidefunction foo() {
var bar = 1;
doSomething(bar);
}
Version
This rule was introduced in DeepScan 1.0.0-alpha.