
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
eslint-plugin-no-empty-statement
Advanced tools
disallow empty statement as the body of `if`, `for`, etc.
It's possible that developers write these forms of code:
if (falseCondition);
{
console.log("It's not true.");
}
for (let i = 0; i < 3; i++);
{
doSomethingInLoop();
}
In the first example, the developer wants the if
body to be executed only if falseCondition
is met, but because he mistakenly typed a semicolon next to the parenthesis, the { ... }
block isn't treated as if
body, so it always gets executed.
In the second example, the developer wants doSomethingInLoop()
to be executed 3 times, but because he mistakenly typed a semicolon next to the parenthesis, the { ... }
block isn't treated as for
body, so it gets executed only once.
If the if
or for
body is simply a semicolon, this semicolon is an "empty statement". Note that this is not "empty block", which is {}
.
This rule disallows this form of semicolons.
In your eslint config file:
{
"plugins": ["no-empty-statement"],
"rules": {
"no-empty-statement/no-empty-statement": "error"
}
}
This rule has a string option:
"ignore-statement-list-item"
(default) allows "empty statement semicolons" in a container that can have multiple statements, for example an extra semicolon in the block { doSomething(); ; }
"all"
disallows all "empty statement semicolons".FAQs
disallow empty statement as the body of `if`, `for`, etc.
We found that eslint-plugin-no-empty-statement demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.