Result of expressions should be used
- UNUSED_EXPR
- Code Quality
- Medium, Low
- cwe
This rule applies when the result of expression is not used.
Unused expression is dead so that it might imply a mistake or unnecessary code.
Note:
- Not applied for the code in
try
statement because unused expression is often used to check an exception, e.g.try { opener.document; } catch (e) {}
. - Not applied for
void
expression because it could be a programmer's intention that the value of the expression is not to be used. - Not applied for property or variable accesses appearing as separate statements because they are usually harmless and often intended for various purposes.
Noncompliant Code Example
View with compliant examples side by sidefunction example1(x) {
x + 1; // UNUSED_EXPR alarm
}
function example2(x, y) {
x.p == y.p; // UNUSED_EXPR alarm
}
Compliant Code Example
View with noncompliant examples side by sidefunction example1(x) {
return x + 1;
}
function example2(x, y) {
x.p = y.p;
}
Version
This rule was introduced in DeepScan 1.0.0-alpha.