MarcelCutts/pride-london-web-gatsby

Re-insert semi-colons

Opened this issue ยท 3 comments

Prettier has a option to toggle semicolons, which should nearly always be set to "have semi colons".

The now defunct "Standard JS" lint style espoused not having them for conciseness but unfortunately they aren't truly optional. The way most engines figure out if a semi colon is needed is by throwing an exception, seeing if a semi colon put in the exception location fixes it, then carrying on.

As you might imagine this can lead to slower compiles and some truly devilish bugs.

ds300 commented

What kind of bugs are you imagining? I've built JS apps without semicolons for over two years and literally never had an issue.

Also

The way most engines figure out if a semi colon is needed is by throwing an exception, seeing if a semi colon put in the exception location fixes it, then carrying on.

Source? As a lapsed compiler geek this sounds unlikely, but maybe I'm underestimating the complexity of JS ๐Ÿ˜…

Also, semicolons get inserted during minification so this shouldn't matter anyway.

I got that insight from Douglas Crockford during a talk of his.

One example of an ambiguous case can be seen here.

ds300 commented

That was an interesting talk ๐Ÿ‘ Luckily ambiguous syntax can be avoided with an eslint rule: https://eslint.org/docs/rules/semi#options โ€“ and prettier will respect using semicolons in those (extremely rare) situations too. So it's completely safe to not use semicolons ๐ŸŽ‰ yay, tooling!