This repository was archived by the owner on Mar 7, 2019. It is now read-only.
This repository was archived by the owner on Mar 7, 2019. It is now read-only.
Proposal: Require trailing commas for multiline objects #12
Closed
Description
I propose that we start requiring trailing commas for multiline objects. Currently trailing commas are optional. Single-line object literals will not be affected by this change.
This rule can be auto-fixed by ESLint, therefore no manual changes are required in your code.
Current
const obj = {
first: 1,
second: 2 // Here, the comma is optional
}
New
const obj = {
first: 1,
second: 2, // Here, the comma is required
}
Why?
- Every time you want to add a new property to an object, you have to remember to put the trailing comma to the preceding property, otherwise you get a syntax error. Enforcing the comma to already be there, you mitigate this completely.
git diff
s will look more clean, because you now do not have to edit an unrelated line to introduce your changes.- It is easier to sort the object's properties with just
F5
or similar editor tool
Please vote 👍 or 👎 via reaction or leave a comment if you have questions or suggestions. Thanks!