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.

Enum trailing commas get included on the same line as the semicolon ending the line

See original GitHub issue

Enums that get split across multiple lines can lead to the last enum in the series having a , ; on the last line. If a , is specified after the last enum value that should be used as an indicator to create another newline and to place the ; on that newline, or the , should be dropped entirely and it should just become a ; after the last enum value.

I could see arguments for either option, but I’d prefer placing the ; on a newline as this preserves version control history for the line with the previous enum value when a new value is eventually added.

Input:

enum MyEnum {
  AAAAAAAA("aaaaaa"),
  BBBBBBBBBBB("bbbbbbbbbb"),
  CCCCCCCCCC("ccccccccc"),
  DDDDDDDDD("ddddddddddddddddddddddddd"),
  EEEEEEE("eeeeeeeeee"), 
  ;
}

Output:

enum MyEnum {
  AAAAAAAA("aaaaaa"),
  BBBBBBBBBBB("bbbbbbbbbb"),
  CCCCCCCCCC("ccccccccc"),
  DDDDDDDDD("ddddddddddddddddddddddddd"),
  EEEEEEE("eeeeeeeeee"), ;
}

Expected Output:

enum MyEnum {
  AAAAAAAA("aaaaaa"),
  BBBBBBBBBBB("bbbbbbbbbb"),
  CCCCCCCCCC("ccccccccc"),
  DDDDDDDDD("ddddddddddddddddddddddddd"),
  EEEEEEE("eeeeeeeeee"),
  ;
}

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
clementdessoudecommented, Mar 27, 2020

Haha, I saw that too! The update to Prettier 2.0 will be in the next release, with the default to trailingComma=“always”

1reaction
clementdessoudecommented, Mar 27, 2020

Probably this weekend. I’d like to wrap a couple of things in it, but I could postpone them for a next release

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trailing comma after last line in object - Stack Overflow
When you add a new line to your object without the trailing comma, you will have to change the original last line by...
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. This...
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 >
Trailing comma in constructor initializer list - Google Groups
Yes, I have seen the workaround of putting commas on the next line, but this doesn't match some coding styles. class dword_table
Read more >
Use Punctuation, Comma, Semicolon in JavaScript
Omitting the semicolon means JavaScript is putting a semicolon automatically at the end of the line. “Automatic Semicolon Insertion” (ASI) is the name...
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