javascript-style-guide icon indicating copy to clipboard operation
javascript-style-guide copied to clipboard

Dangling comma and related errors

Open devdrops opened this issue 8 years ago • 5 comments
trafficstars

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 avatar Jun 30 '17 19:06 devdrops

@devdrops this may help: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas

mccraveiro avatar Jun 30 '17 19:06 mccraveiro

@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 avatar Jul 25 '17 18:07 thalesmello

@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 avatar Jul 25 '17 19:07 mccraveiro

@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.

thalesmello avatar Jul 26 '17 15:07 thalesmello

Related issue:

#12

thalesmello avatar Jul 26 '17 17:07 thalesmello