javascript-style-guide
javascript-style-guide copied to clipboard
Dangling comma and related errors
Hi!
Dangling comma may cause weird errors when used on functions, you should avoid it.
Could you please elaborate this problem? Maybe this isn't an issue with this repository itself but I'd like to understand what exactly may happen (the biblical Armageddon?) if js newbs like me don't pay attention to this subject.
Thanks!
@devdrops this may help: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas
@mccraveiro Actually, what's weird about this?
Just don't use a trailing comma when you have a spread operator.
In fact, dangling comma is now part of the ES2017 specification, so it is now a legal.
@thalesmello It's now part of the spec. However we are not using the latest version of node on all projects therefore comma dangle on functions will break them. For example, projects using AWS lambda are limited to node 6.10.
@mccraveiro I understand. In my opinion we could either keep this issue open to remind us to change it when it is possible to use the latest node version in every project, or (even better), forbid splitting function calls into multiple lines altogether.
The exception would be if the multiple lines are either because of a lambda or an object.
Related issue:
#12