3 ms·
> Omitting semicolons actually has an effect in JavaScript, and there are many examples of that. The Google JavaScript coding standard advises specifically agai
by betenoire 10y ago
> Omitting semicolons actually has an effect in JavaScript, and there are many examples of that. The Google JavaScript coding standard advises specifically against it for good reasons.
I just gave Standard a try for the first time, kinda surprised I'd never seen it til now. Anyway, it seems to also check for those semi-colon gotchas. If I try to use no-semicolons incorrectly, it catches my mistake. (I tried by putting the return value on the next line)
- partycoder 10y agoHopefully one day you don't forget to run it and break production :) Usually good standards can be assimilated and make you code in a safer way, even if not enforced by a tool. You could argue that a script, version control hook or continuous integration script can take care of it, but those are lines of defense that can go away in certain circumstances and you are unnecessarily raising your odds for an incident. Sometimes people add a block comment to disable linting, and if you were relying on your linter to provide the fix to allow your bad habit of not using semicolons, then you are on your own.
- betenoire 10y agoPersonally, no semi colons is a deal breaker for me. It's like a period at the end of the sentence that means, "That's the entire statement". So, it's neat in the config-less way, but I won't be using it. (there is a semicolon version by the way https://github.com/Flet/semistandard https://github.com/Flet/semistandard )
- partycoder 10y agoStill with semicolons, many core problems remain: it's too permissive, and it's designed that way to maximize adoption. If StandardJS was a standard for dating, its only filter would be that your potential date is alive and is a mammal. Use that Standard and you will have a lot of potential dates! such a great standard.
- wolfgang42 10y agoThe solution to "forget to run it and break production" is to add the linter to your CI tests, or even as a precommit hook. I touch on this in my other comment, but it's entirely possible to forget a semicolon and break things no matter which style you prefer. Both semi:always and semi:never+no-unexpected-multiline enforce good standards which can be assimilated; like spaces vs tabs, they're just different standards that people tend to develop very strong opinions about.
- partycoder 10y agoAnother solution is to prevent ambiguity and just terminate your statements with a semicolon.
- feross 10y agoExcept using semicolons everywhere does not protect you from automatic semicolon insertion. You still need to know the rules. https://feross.org/never-use-semicolons/ https://feross.org/never-use-semicolons/