Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upExpected { after 'if' condition even with single lines #718
Comments
This comment has been minimized.
This comment has been minimized.
|
I think this is intentional, I at least prefer this behaviour |
This comment has been minimized.
This comment has been minimized.
|
The error says If I add the curly brackets like this: const test = false
if (test) {
console.log(false)
}
else {
console.log(true)
}It says there's an unnecessary { after if (due to being a single line) This is confusing to say the least. What do you do then when you have a single line after an if condition that is too long and you want to put it on the next line? |
This comment has been minimized.
This comment has been minimized.
|
I think that it's like so, single line: if (thisIsAll) onOneLine()multiple lines: if (thisIsActually)
twoLine()
You put brackets around it |
This comment has been minimized.
This comment has been minimized.
|
Single line const test = false
if (test) console.log(false)
else console.log(true)Multi line const test = false
if (test) {
console.log(false)
} else {
console.log(true)
}As you pointed out, other [non-standard] formatting of these statements will throw respective errors. |
dcousens
closed this
Dec 13, 2016
dcousens
added
the
question
label
Dec 13, 2016
This comment has been minimized.
This comment has been minimized.
|
Ok, I guess that rule changed than? I remember that const test = false
if (test) {
console.log(false)
} else {
console.log(true)
}Gave Thanks for clarifying |
jonaswindey commentedDec 13, 2016
•
edited
Using
standard@8.6.0, the following code fails:Error:
whereas this one works:
Could be related to #664 , but the issue has been closed and this issue still exists
This makes it difficult to use single-line
ifblocks when they are too long to fit on the same line.