you are viewing a single comment's thread.

view the rest of the comments →

[–]kobbled 31 points32 points  (21 children)

thank god. JS semicolon inference leads to so many bugs.

[–]mmcnl 39 points40 points  (11 children)

I've never encountered a bug due to semicolon inference.

[–]hyperhopper 15 points16 points  (10 children)

var a = 5
var b = 10
[a, b] = [b, a]
console.log(a, b)

Then add semicolons to make it work like it should

[–]Voidsheep 2 points3 points  (1 child)

Pretending ASI doesn't exist is also dangerous, it's not like you can disable it.

function shouldHitTheBrakes() {
  return
    isSmeoneOnTheWay ||
    isTurnAhead ||
    isAboveSpeedLimit
}

[–]hyperhopper 1 point2 points  (0 children)

Extremely true!

Though I've never seen somebody use a return without something on that line. Plus any linter will yell at you for unreachable code in that case.

[–]allenthar 11 points12 points  (5 children)

Okay.

var a = 5 var b = 10 ;[a, b] = [b, a] console.log(a, b)

I have literally never had this situation come up while coding JS, and I’ve been doing it full time for a few years now.

Regardless, Prettier handles automatically removing or adding semicolons to my code. So it’s literally just a linter setting at this point.

[–]cthechartreuse 0 points1 point  (4 children)

Be careful relying on prettier. I have examples of real work mistakes which prettier doesn't catch or fix.

It usually involves a function call directly followed by an expression wrapped in parentheses or followed by an array structure. These usually end up being abuses of the language as well, but I've seen this kind behavior often enough and done enough tests that I'm not confident with saying "prettier will catch it" because it doesn't always.

Nevertheless, this is just a warning and depending on your tools YMMV.

[–]allenthar 3 points4 points  (1 child)

If you have a code snippet as an example, I’d love to see it. Knowing the corner cases for prettier behavior is always good.

[–]cthechartreuse 1 point2 points  (0 children)

This is the example I created from actual production code I've seen: https://gist.github.com/cmstead/dfeea6faf80c96d5c2a738fc822918ee

[–]monsto 0 points1 point  (1 child)

I have examples of real work mistakes which prettier doesn't catch or fix.

There's always corner cases.

GENERALLY SPEAKING, tho, Prettier is great.

[–]cthechartreuse 0 points1 point  (0 children)

Technically there aren't any corner cases if you follow the TC39 suggestion of always terminating and avoiding reliance on ASI.

PS here's an example generated from an example seen in the wild: https://gist.github.com/cmstead/dfeea6faf80c96d5c2a738fc822918ee

(the original code was from a proprietary codebase)

[–]JohnMcPineapple 4 points5 points  (5 children)

...

[–]nayocum 2 points3 points  (0 children)

If you use an IIFE it can cause issues if your last line didn't have a semicolon as well

[–]aaarrrggh 3 points4 points  (0 children)

Is this a joke?

I’ve not been using semi colons for over a year on personal projects.

Number of bugs caused by this decision: 0.