comma-spacing
Configuration
Enforce consistent spacing before and after commas.
Rule Details
This rule normalizes the whitespace around the , separator in variable declarations, array literals, array destructuring patterns, object literals, object destructuring patterns, function parameter lists, function call arguments, sequence expressions, and TypeScript-specific list-shaped syntax (type arguments, type parameters, tuple types, enum members, import / export specifiers, heritage clauses).
The rule does not apply between:
- Two consecutive commas (
[1, , 2]— the comma terminating the null slot is exempt) - A comma and the immediately following
),], or}(delegated to dedicated bracket-spacing rules) - A comma and the immediately following line comment when the option forbids a space after — removing the space would fuse the comma into
//
Examples of incorrect code for this rule with the default { "before": false, "after": true } option:
Examples of correct code for this rule with the default { "before": false, "after": true } option:
Options
This rule has an object option:
"before": false(default) forbids a space before the comma. Set totrueto require one."after": true(default) requires a space after the comma. Set tofalseto forbid one.
Either key may be omitted; a missing key falls back to its default.
before
Examples of incorrect code for this rule with the { "before": true } option:
Examples of correct code for this rule with the { "before": true } option:
after
Examples of incorrect code for this rule with the { "after": false } option:
Examples of correct code for this rule with the { "after": false } option: