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.

Enforce Trailing Commas by Default

See original GitHub issue

I propose that trailing commas should be enabled by default. IE8 is a non issue for most, and this will provide better diffing.

const arr = [
  'multi',
  'line'
]

should be formatted as:

const arr = [
  'multi',
  'line',
]

I would also suggest not enabling it for function arguments, considering that this is not in the official spec yet and won’t be fully supported without a transpiler like babel. e.g.:

foo(
  arg1,
  arg2,
)

should be formatted as:

foo(
  arg1,
  arg2
)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:233
  • Comments:53 (13 by maintainers)

github_iconTop GitHub Comments

108reactions
Pomaxcommented, Jan 10, 2017

I’ll represent the other camp: clean, readable code does not need the trailing commas, as commas are separators, not prefix/postfix operators, and there’s nothing following that comma. Injecting commas in this case would be a reason for me to not want to use this formatter.

34reactions
ljharbcommented, Jan 11, 2017

Minimal git diffs are good for humans, and consistency is good for readability.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trailing Commas Are Just The Beginning – Pursuit Of Laziness
Trailing commas, also known as dangling commas, are a formatting strategy that's grown in popularity over time.
Read more >
Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >
Code Syntax Style: Trailing Commas - JetBrains Rider
Enforce preferences for trailing commas. By default, JetBrains Rider highlights trailing commas as redundant and helps removing them:.
Read more >
comma-dangle - ESLint - Pluggable JavaScript Linter
"never" (default) disallows trailing commas · "always" requires trailing commas · "always-multiline" requires trailing commas when the last element or property is ...
Read more >
How to Allow Trailing Commas (Comma-Dangle) With ...
Allowing comma-dangle in TypeScript requires two configurations in your ESLint setup. At first, you must turn off ESLint's default comma-dangle ...
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