New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-no-empty-statement

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-no-empty-statement

disallow empty statement as the body of `if`, `for`, etc.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Why?

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.

Usage

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".

Keywords

FAQs

Package last updated on 01 Feb 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc