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

Dangling commas #10

Closed
jhnns opened this issue Mar 13, 2017 · 7 comments
Closed

Dangling commas #10

jhnns opened this issue Mar 13, 2017 · 7 comments

Comments

@jhnns
Copy link
Member

jhnns commented Mar 13, 2017

I would like to change our linting rules to enforce dangling commas in multiline literals, likes this:

{
    a: 1,
    b: 2,
}

[
    1,
    2,
]

import {
    a,
    b,
} from "bla";

Why?

  1. Moving items up and down becomes easier, because we don't need to care about adding or removing commas
  2. Cleaner diffs
  3. Valid ES3 syntax (!). The only reason why people didn't do it is because IE8 threw a SyntaxError
  4. Community support: The Airbnb linting rules do also enforce it
  5. Easy update via --fix

Why not optional?

Because we should stick to one style. We wouldn't really have benefit 1. and 2. if it is optional.

The rule would be configured like this:

        "comma-dangle": ["error", {
            arrays: "always-multiline",
            exports: "always-multiline",
            functions: "ignore",
            imports: "always-multiline",
            objects: "always-multiline",
        }],

Any objections? @peerigon/everyone

@acidicX
Copy link
Contributor

acidicX commented Mar 13, 2017

Moving items up and down becomes easier, because we don't need to care about adding or removing commas

👍

@meaku
Copy link
Member

meaku commented Mar 13, 2017

I already told you my option -> TW!
I think it looks ugly and prefer removing/adding commas whenever moving elements :)

@jhnns
Copy link
Member Author

jhnns commented Mar 13, 2017

I think it looks ugly

Very subjective. It looks unusual and there is a small learning curve (how many items has an array literal with dangling commas? 😉), but I think the benefits outweigh subjective feelings like "it's ugly".

@meaku
Copy link
Member

meaku commented Mar 13, 2017

Very subjective.

True. But code-style imposes "style" which is always subjective 😉

how many items has an array literal with dangling commas? 😉

It does not change the length. So you mean the visual impact?

@flootr
Copy link

flootr commented Mar 13, 2017

I think this rule has some advantages which are, in my sense, rather objective (point 1. and 2.) and outweigh subjective "ugliness".

@jhnns
Copy link
Member Author

jhnns commented Mar 13, 2017

But code-style imposes "style" which is always subjective

Style is not always subjective, because there are also typographic rules. But style tends to be subjective, that is true.

It does not change the length. So you mean the visual impact?

You could think that the array has one more, undefined item. That's the only counter-argument I can think of.

@meaku
Copy link
Member

meaku commented Mar 13, 2017

You're right. Objective reasons are always more important than personal taste. With the diff enhancement, the objective reasons overweights my personal taste.

jhnns added a commit that referenced this issue Mar 29, 2017
jhnns added a commit that referenced this issue Mar 31, 2017
@jhnns jhnns closed this as completed Jun 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants