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.

Trailing comma added after comment in call expression

See original GitHub issue

This should be in the same general area of #530:

foo({}
  // Hi
);
foo(
  {}
  // Hi,
);

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
heyimalexcommented, Feb 2, 2017

Pretty sure this is the same issue, but with trailing commas enabled:

let example = [
  'FOO',
  'BAR',
  // 'BAZ',
];
let example = [
  "FOO",
  "BAR"
  // 'BAZ',,
];

I noticed when I saw a line that had fifteen trailing commas; on subsequent runs, prettier just keeps adding them 😂

0reactions
vjeuxcommented, Feb 3, 2017

The reason

var example = [
  "FOO", // example
  "BAR"
];

works is because // example has a special type “line-suffix” with special logic. Otherwise if you join(",", elements) it would put the , after the comment like it happens for the trailing comment here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Best practices for using trailing commas in JavaScript
A trailing comma, also known as a dangling or terminal comma, is a comma symbol that is typed after the last item of...
Read more >
Trailing comma in JavaScript function call - Stack Overflow
The rule on trailing commas for function call arguments states: 7.15 Functions with multiline signatures, or invocations, should be indented ...
Read more >
Trailing commas in all expression lists - Pitches - Swift Forums
The problem is that current Swift does not accept a comma after the last expression in an argument list. It is possible to...
Read more >
Code Syntax Style: Trailing Commas - JetBrains Rider
When multiple items are separated by the comma (object, array, and collection initializers, as well as enums and switch expressions) , C# allows ......
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