# comma-spacing

Rule `eslint/comma-spacing`. Enforce consistent spacing before and after commas

- Source: eslint
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Deprecated: yes
- Reach: 13.7M weekly downloads of presets that enable it
- Trend: +5.1% last quarter
- Rank: #691 by reach, #1497 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `comma-spacing` | no | safe | package `eslint` | [docs](https://eslint.org/docs/latest/rules/comma-spacing) |

## Code examples

### Incorrect: the rule reports this

```js
var foo = 1 ,bar = 2;
var arr = [1 , 2];
var obj = {"foo": "bar" ,"baz": "qur"};
foo(a ,b);
new Foo(a ,b);
function baz(a ,b){}
a ,b
```

```js
var foo = 1, bar = 2;
var arr = [1 , 2];
var obj = {"foo": "bar", "baz": "qur"};
new Foo(a,b);
function baz(a,b){}
a, b
```

### Correct: the rule accepts this

```js
var foo = 1, bar = 2
    , baz = 3;
var arr = [1, 2];
var arr = [1,, 3]
var obj = {"foo": "bar", "baz": "qur"};
foo(a, b);
new Foo(a, b);
function qur(a, b){}
a, b
```

```js
// this rule does not enforce spacing between two commas
var arr = [
    ,,
    , ,
];

// this rule does not enforce spacing after `[` and before `]`
var arr = [,];
var arr = [ , ];
var arr = [a, b,];
[,] = arr;
[ , ] = arr;
[a, b,] = arr;

// this rule does not enforce spacing before `}`
var obj = {x, y,};
var {z, q,} = obj;
import {foo, bar,} from "mod";

// this rule does not enforce spacing before `)`
foo(a, b,)
```

```js
var foo = 1 ,bar = 2 ,
    baz = true;
var arr = [1 ,2];
var arr = [1 ,,3]
var obj = {"foo": "bar" ,"baz": "qur"};
foo(a ,b);
new Foo(a ,b);
function qur(a ,b){}
a ,b
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "comma-spacing": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Airbnb base](https://lintradar.dev/presets/airbnb-base.md) | ESLint | `eslint-config-airbnb-base` | 241 | 6.5M | +2.1% |
| [Airbnb](https://lintradar.dev/presets/airbnb.md) | ESLint | `eslint-config-airbnb` | 346 | 3.4M | +2.3% |
| [JavaScript Standard Style](https://lintradar.dev/presets/standard.md) | ESLint | `eslint-config-standard` | 161 | 3.1M | +12.9% |
| [Google](https://lintradar.dev/presets/google.md) | ESLint | `eslint-config-google` | 60 | 646.4K | +18.9% |

## Related rules

- [vue/comma-spacing](https://lintradar.dev/rules/vue/comma-spacing.md): Enforce consistent spacing before and after commas in `<template>`
- [unicorn/comma-spacing](https://lintradar.dev/rules/unicorn/comma-spacing.md): Enforce consistent spacing before and after commas in JSON and SOML.
- [eslint/block-scoped-var](https://lintradar.dev/rules/eslint/block-scoped-var.md): Enforce the use of variables within the scope they are defined
- [eslint/no-alert](https://lintradar.dev/rules/eslint/no-alert.md): Disallow the use of `alert`, `confirm`, and `prompt`
- [eslint/no-restricted-syntax](https://lintradar.dev/rules/eslint/no-restricted-syntax.md): Disallow specified syntax
- [eslint/camelcase](https://lintradar.dev/rules/eslint/camelcase.md): Enforce camelcase naming convention

---

Web page: https://lintradar.dev/rules/eslint/comma-spacing. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
