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

Strong arguments for dangling commas #907

Closed
lohfu opened this issue Jun 1, 2017 · 8 comments

Comments

@lohfu
Copy link

commented Jun 1, 2017

Hi,

I chose standard to avoid bikeshedding, and decided to force myself to use it for a few weeks before even considering changing a rule. Most rules are aesthetic anyway and easy to learn to live with. However, there is one rule that after a few weeks still seems very counter productive; namely forcing the omission of dangling commas.

The (strong and, in my opinion, objective) cases for using dangling commas are:

  1. Resorting an array will never require adding and/or removing a dangling comma.
  2. Adding an item to the end of an array does not require adding a dangling comma to the previous line.
  3. Removing the last item in an array does not require removing the dangling comma from the previous line.
  4. Commenting out the last item of an array does not require the dangling comma of the previous line to be removed.
  5. There are no redundant diffs in version control systems relating to added or removed dangling commas.

Is there any possibility of a rule being reconsidered? I don't really see this as bikeshedding as it actually has strong benefits.

EDIT: Added 4th point & made it make sense

@ematipico

This comment has been minimized.

Copy link
Contributor

commented Jun 5, 2017

And I thought the argument was about the semicolons...

I think those arguments are just for comfort. I mean, your code doesn't break if you have or if you not. Although, personally, I doesn't seem right to have a comma at the end of a listing.

It personally appears as an error, like when something deleted the last item of the object/array and forgot to remove it

@Flet

This comment has been minimized.

Copy link
Member

commented Jun 8, 2017

Some previous related issues:
#787
#586
#240
#159

@lohfu

This comment has been minimized.

Copy link
Author

commented Jun 21, 2017

@Flet

hmmm, thought i had searched through the closed issues as well. apparently i had not. or did it miserably.

i still stand fast by the point this is a real productivity booster (or hassle reducer, depending on how you want to see it). just like semi-colon omission, it is one of those things you just never want to ditch once you have taken the plunge.

@feross

This comment has been minimized.

Copy link
Member

commented Jun 21, 2017

I appreciate the arguments for dangling commas but I think they are very confusing to beginners. A dangling comma arguably looks like an error -- did the programmer intend to add another item to the list?

One thing I can suggest that alleviates points 3-4 in your list is to run standard --fix as a pre-commit hook. This will remove extra dangling commas automatically and save you the extra typing.

@feross feross added the question label Jun 21, 2017

@tunnckoCore

This comment has been minimized.

Copy link

commented Aug 4, 2017

Yea, i'm agree too. Fix is an option, really, i always use fix on save, so i never think for such things, but i have preferences to enable it for "where is allowed in es5", because really, it will be ugly to force including commas in the function arguments (i'm agree to require comma there, but only if there are multiline arguments).

@mmieluch

This comment has been minimized.

Copy link

commented Aug 14, 2017

Just my three cents. I myself am a big proponent of enforcing dangling commas in multiline arrays, objects and arguments lists, and all of my co-workers agree with me on this. I find it very convenient not having to go to the previous line just to remove a coma.

Also - and I realise this is purely aesthetic and personal - it gives code this nice symmetry. But that may be just my OCD :)

I agree with @SirRade that this rule would enforce better code. The only browsers that would be incompatible with this would be IE8 and below, as stated on the ESLint rule page:

Trailing commas in object literals are valid according to the ECMAScript 5 (and ECMAScript 3!) spec. However, IE8 (when not in IE8 document mode) and below will throw an error when it encounters trailing commas in JavaScript.

Anyway, if there was any vote on this, I'd give a big +1 in a heartbeat. This is mainly the reason we don't use standard standard, but override the ruleset with always-multiline option for dangling commas.

@yoshuawuyts

This comment has been minimized.

Copy link
Contributor

commented Aug 15, 2017

As per #907 (comment), this topic has been widely discussed already, and there's little chance of this happening now, if ever.

Thanks everyone for chiming in!

@yoshuawuyts

This comment has been minimized.

Copy link
Contributor

commented Aug 27, 2017

@SirRade Any form of discrimination against for race, religion, or otherwise isn't welcome in the StandardJS project. Using a known white supremacist symbol as an avatar (knowingly, or otherwise) will not be tolerated.

Locking this thread, because as per #907 (comment) the topic in this thread has been exhausted, and further discussion only adds noise.

@standard standard deleted a comment from jnferner Aug 27, 2017

@standard standard deleted a comment from jnferner Aug 27, 2017

@standard standard locked and limited conversation to collaborators Aug 27, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
8 participants
You can’t perform that action at this time.