question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESLint 3.0.0 just disabled this rule in their recommended config:

comma-dangle used to be recommended because Internet Explorer 8 and earlier threw a syntax error when it found a dangling comma on object literal properties. However, Internet Explorer 8 was end-of-lifed in January 2016 and all other active browsers allow dangling commas. As such, we consider dangling commas to now be a stylistic issue instead of a possible error.

I’d suggest to follow suit and drop the error. Dangling commas are supported in arrays, object, and hopefully soon even in function parameters. They also make git diffs smaller:

[
    "one"
]

add “two”:

[
-   "one"
+   "one",
+   "two",
]

but with a dangling comma:

[
    "one",
]

becomes:

[
    "one",
+   "two",
]

For this reason I’d prefer the option ["error", "always-multiline"] but ["error", "only-multiline"] would be lax enough.

Edit: more reasons below

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

10reactions
fregantecommented, Sep 19, 2017

@kevva the point of this issue is to change your opinion on whether you should use the dangle or not.

Besides git, this is also what you can do:

  • move items freely

move

  • remove items freely

remove

  • Consistently edit multiple lines at once

multi-line actions

Many practical reasons to use dangling commas, yet we’re stuck with “I don’t like the way it looks”

7reactions
fregantecommented, Jul 21, 2016

Dangling commas might look a bit weird at first, it’s true, but I thought of this: (forget code style preconceptions for a moment)

// pardon the lack of spaces
[0,0,0,0]

^ No dangling comma. Looks beautiful, commas are symmetrical and natural.

[0,0,0,0,]

^ hmmm. So-so.

[
    0
]

^ Multiline, single element. You wouldn’t do that but it’s still beautiful, symmetrical and it’s valid in xo.

[
    0,
    0,
    0,
    0,
    0
]

^ Multiline, multiple elements, no dangle. That final element feels off. It doesn’t match the lines above. It looks like you forgot the period at the end of a sentence or the semicolon at the end of a line.

[
    0,
    0,
    0,
    0,
    0,
]

^ Read them line by line and forget the brackets. Finally they all match! 🎉

So:

// ❌
[0,0,0,0,]

// ✅
[
    0,
    0,
    0,
    0,
    0,
]

Now, always-multiline means that this also needs a comma:

[
    0,
]

So maybe I’d go for only-multiline or perhaps suggest an option like always-multiline-multielements to eslint

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lax comma-dangle #369 - Issuehunt
comma-dangle used to be recommended because Internet Explorer 8 and earlier threw a syntax error when it found a dangling comma on object...
Read more >
Developers - Lax comma-dangle - - Bountysource
Coming soon: A brand new website interface for an even better experience!
Read more >
LAX Official Site | Welcome to Los Angeles International Airport
LAX Official Website | Live flight times and updates, arrivals and departures, news, advice, maps, traffic and parking | Los Angeles International Airport....
Read more >
@codeyourfuture/eslint-config-standard - npm
A standard ESLint configuration for all CYF examples/projects.. Latest version: 3.0.3, last published: a year ago.
Read more >
Diff - plugins/checks - Google Git
... + "timed-out": "^4.0.0", + "url-parse-lax": "^1.0.0", + "url-to-options": "^1.0.1" + } + } + } + }, + "github-username": { + "version":...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found