Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upRespect "Commas first" rule #464
Comments
This comment has been minimized.
This comment has been minimized.
|
Thanks for opening this issue. The reply here is similar as on #400
I would be against loosening this rule too, as I find comma-first particularly hard to read. Perhaps others would disagree, but in this case we've picked something and gone with it. If this is a deal breaker, then perhaps |
yoshuawuyts
closed this
Mar 20, 2016
yoshuawuyts
added
the
i disagree
label
Mar 20, 2016
This comment has been minimized.
This comment has been minimized.
|
I also think that this is not too good to read. But. There is one but: More clear diffs. When default comma-last rule used, we have this in diffs:
But in comma-first case this will be more clear and just one line changes:
And we clearly see, that |
This comment has been minimized.
This comment has been minimized.
|
@garex You have only moved the problem to the first line instead of the last though. Another option would be to allow trailing comma, it doesn't look nearly as bad and handle diffs very nice as well... |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
No it isn't. I think that what @feross means is that the error of missing a comma will be caught by standard. The only place it isn't allowed is in arguments to a function, but there is a proposal up to start allowing that... |
This comment has been minimized.
This comment has been minimized.
@LinusU Are you sure? In which popular browsers this is not error? |
This comment has been minimized.
This comment has been minimized.
var arr = [
1,
2,
]
var obj = {
a: 1,
b: 2,
}This works in Node.js, Safari and Chrome; and probably all other browsers/runtimes as well. |
This comment has been minimized.
This comment has been minimized.
|
@LinusU see these nice answers: http://stackoverflow.com/questions/7246618/trailing-commas-in-javascript TL;DR If you are dont' care about compatibility before js5-browsers, then trailing commas are ok for you. |
This comment has been minimized.
This comment has been minimized.
matthew-dean
commented
Oct 7, 2016
•
|
Comma-first looks odd at first to the human brain when you're used to something else, but pretty quickly it's advantages become obvious when using it. (Or did to me.) Mostly, I stopped making as many missing-comma errors. Pretty much not at all, since missing commas are impossible not to spot. See: https://gist.github.com/isaacs/357981 The logic about cleanliness in omitting semi-colons at the end of statements applies here too. Namely, it feels weird at first, but the code appears cleaner and is easier to use. I wouldn't just argue it should be allowed. I would say this should be the standard. The advantages are many, and the only disadvantage for the individual developer is "it's not what i'm used to". But there may be many items in this standard that an individual dev is not used to. Try comma-first for a while! You won't go back. As to this:
Not sure why this was quoted, since that's true for #400 but completely false here. |
garex commentedMar 20, 2016
@see https://docs.npmjs.com/misc/coding-style#comma-first