Skip to content

curly: multi-or-nest option reports an error for a single-statment block with a semicolon on the next line #12370

@cherryblossom000

Description

@cherryblossom000

Tell us about your environment

  • ESLint Version: 6.5.1
  • Node Version: 12.11.0
  • npm Version: 6.11.3

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

Configuration
{
  "rules": {
    "curly": [2, "multi-or-nest"]
  }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

I used the following code in file.js:

if (true) console.log('some statement')
;(function () {})()

The issue occurs whenever the statement in the if block (or any block) has the semicolon on the following line.

Then I linted it:

eslint file.js

What did you expect to happen?
No error would occur as there is only 1 statement in the if block.

What actually happened? Please include the actual, raw output from ESLint.
I got the following error:

file.js
  1:1  error  Expected { after 'if' condition  curly

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

When fixing it with eslint --fix file.js, it gets changed to

if (true) {console.log('some statement')
;}(function () {})()

which conflicts with the "semi": [2, "never"] rule as that would change it to:

if (true) {console.log('some statement')
}(function () {})()

which would cause curly to report Unnecessary { after 'if' condition.

Are you willing to submit a pull request to fix this bug?
Yes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    HacktoberfestRecommended issue for those participating in Hacktoberfest https://hacktoberfest.digitalocean.com/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 incorrectlyhelp wantedThe team would welcome a contribution from the community for this issueruleRelates 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