Skip to main content

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

Why This Rule Exists

Trailing commas have advantages: Cleaner diffs:
Easier refactoring:
  • 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:
Correct:

"always"

Incorrect:
Correct:

"always-multiline"

Most popular option - requires trailing commas for multiline, forbids for single-line.
Incorrect:
Correct:

"only-multiline"

Allow but don’t require trailing commas when multiline. Incorrect:
Correct:

Functions

Function trailing commas require ES2017+.
Incorrect with {"functions": "never"}:
Correct:

Configuration Examples

When Not to Use It

Most teams now use Prettier for formatting. If you use Prettier, disable this rule.
Disable if:
  • You use Prettier or another formatter
  • You need IE8 compatibility (very rare now)
  • Your team hasn’t agreed on trailing comma style