no-unused-expressions
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"no-unused-expressions": "error",
},
},
];0
if(0) 0
{0}
f(0), {}
a && b()
a, b()
c = a, b;
a() && function namedFunctionInExpressionContext () {f();}
(function anIncompleteIIFE () {});
injectGlobal`body{ color: red; }`doSomething();
"use strict"; // this isn't in a directive prologue, because there is a non-directive statement before it
function foo() {
"bar" + 1;
}
class Foo {
static {
"use strict"; // class static blocks do not have directive prologues
}
}a || b{} // In this context, this is a block statement, not an object literal
{ myLabel: foo() } // In this context, this is a block statement with a label and expression, not an object literal
function namedFunctionDeclaration () {}
(function aGenuineIIFE () {}());
f()
a = 0
new C
delete a.b
void a"use strict";
"use asm"
"use stricter";
"use babel"
"any other strings like this in the directive prologue";
"this is still the directive prologue";
function foo() {
"bar";
}
class Foo {
someMethod() {
"use strict";
}
}a && b()
a() || (b = c)Examples from the ESLint documentation.
no-unused-expressions
eslint
export default [
{
rules: {
"no-unused-expressions": "error",
},
},
];no-unused-expressions
eslint plugin · correctness
{
"rules": {
"no-unused-expressions": "error"
}
}suspicious/noUnusedExpressions
suspicious · since 2.2.5
{
"linter": {
"rules": {
"suspicious": {
"noUnusedExpressions": "error"
}
}
}
}Disallow the use of the __iterator__ property
Disallow comparisons where both sides are exactly the same
Disallow octal escape sequences in string literals