Skip to main content

comma-dangle

Deprecated

Formatting rules now live in eslint-stylistic. @stylistic/ts/comma-dangle is the replacement for this rule.
See Deprecating Formatting Rules for more information.

Require or disallow trailing commas.

🔧

Some problems reported by this rule are automatically fixable by the --fix ESLint command line option.

This rule extends the base eslint/comma-dangle rule. It adds support for TypeScript syntax.

See the ESLint documentation for more details on the comma-dangle rule.

How to Use

.eslintrc.cjs
module.exports = {
"rules": {
// Note: you must disable the base rule as it can report incorrect errors
"comma-dangle": "off",
"@typescript-eslint/comma-dangle": "error"
}
};

Try this rule in the playground ↗

Options

See eslint/comma-dangle options.

In addition to the options supported by the comma-dangle rule in ESLint core, the rule adds the following options:

  • "enums" is for trailing comma in enum. (e.g. enum Foo = {Bar,})
  • "generics" is for trailing comma in generic. (e.g. function foo<T,>() {})
  • "tuples" is for trailing comma in tuple. (e.g. type Foo = [string,])

Resources

Taken with ❤️ from ESLint core.