Skip to content

no-extra-semi advice is ill on loops without a body #3075

@silverwind

Description

@silverwind
for (var i = 0; i <= 5; console.log(i++));

Real life example

While I agree this is hardly readable and should be refactored, extra-semi does incorrectly advice to remove the semicolon here, which would lead to the next line being considered the body of the loop, changing behaviour. The same issue can happen on a while loop:

var i;
while (i++ <= 5);

Real life example

A do while is unaffected because the curly braces are required there. This is on v24.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionbugESLint is working incorrectlyruleRelates to ESLint's core rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions