Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

cherryblossom000 opened this issue Oct 4, 2019 · 3 comments · May be fixed by rsumner868/librealsense2.1#1, rsumner868/librealsense#4, O330oei/node#4 or O330oei/node#11


Copy link

@cherryblossom000 cherryblossom000 commented Oct 4, 2019

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:

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

  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?

@cherryblossom000 cherryblossom000 changed the title curly: multi-or-nest option reports an error for a single-statment block with no braces before a line beginning with a semicolon curly: multi-or-nest option reports an error for a single-statment block with a semicolon on the next line Oct 4, 2019
Copy link
Contributor Author

@cherryblossom000 cherryblossom000 commented Oct 4, 2019

I think the issue is here:


Lines 99 to 104 in c47fa0d

function isOneLiner(node) {
const first = sourceCode.getFirstToken(node),
last = sourceCode.getLastToken(node);
return first.loc.start.line === last.loc.end.line;

last would be the semicolon, which is on a different line to the first token in

console.log('some statement')
Copy link

@kaicataldo kaicataldo commented Oct 4, 2019

Verified using our demo. Nice find! Definitely seems like we should use the previous token for this check in this case.

Copy link
Contributor Author

@cherryblossom000 cherryblossom000 commented Oct 5, 2019

I fixed it in #12378.

kaicataldo added a commit that referenced this issue Nov 1, 2019

* Update: Curly multi-or-nest flagging semis on next line (fixes #12370)

* Chore: Add more tests to the multi-or-nest option for curly

Check that multi-or-nest it fixes cases like
if (foo) {

and that it ignores cases with an empty statement like
if (foo)
@eslint eslint bot locked and limited conversation to collaborators May 1, 2020
@eslint eslint bot added the archived due to age label May 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.