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

Re-insert semi-colons #55

Open
MarcelCutts opened this issue May 19, 2018 · 3 comments
Open

Re-insert semi-colons #55

MarcelCutts opened this issue May 19, 2018 · 3 comments
Labels
debt Non-feature work to improve the codebase

Comments

@MarcelCutts
Copy link
Owner

MarcelCutts commented May 19, 2018

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.

@MarcelCutts MarcelCutts added the debt Non-feature work to improve the codebase label May 19, 2018
@ds300
Copy link
Collaborator

ds300 commented May 19, 2018

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.

@MarcelCutts
Copy link
Owner Author

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

One example of an ambiguous case can be seen here.

@ds300
Copy link
Collaborator

ds300 commented May 20, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debt Non-feature work to improve the codebase
Projects
None yet
Development

No branches or pull requests

2 participants