comma-dangle
Trailing commas in object and array literals are valid in ES5 (and ES3). This rule enforces consistent use.Rule Type: Layout
Fixable: Yes (automatically fixable)
Deprecated: Consider using Prettier
Fixable: Yes (automatically fixable)
Deprecated: Consider using Prettier
Why This Rule Exists
Trailing commas have advantages: Cleaner diffs:- Add/remove items by editing one line
- Less chance of syntax errors
Rule Details
This rule enforces consistent trailing comma usage.Options
String Option
"never"(default) - Disallow trailing commas"always"- Require trailing commas"always-multiline"- Require when last element is on different line"only-multiline"- Allow but don’t require when multiline
Object Option
Configure for each syntax type:Examples
"never"
Incorrect:
"always"
Incorrect:
"always-multiline"
Incorrect:
"only-multiline"
Allow but don’t require trailing commas when multiline.
Incorrect:
Functions
Incorrect with{"functions": "never"}:
Configuration Examples
When Not to Use It
Disable if:- You use Prettier or another formatter
- You need IE8 compatibility (very rare now)
- Your team hasn’t agreed on trailing comma style