Enforce Trailing Commas by Default
See original GitHub issueI 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:
- Created 7 years ago
- Reactions:233
- Comments:53 (13 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Minimal git diffs are good for humans, and consistency is good for readability.