1 # Enforces spacing around commas (comma-spacing)
3 Spacing around commas improves readability of a list of items. Although most of the style guidelines for languages prescribe adding a space after a comma and not before it, it is subjective to the preferences of a project.
12 This rule enforces consistent spacing before and after commas in variable declarations, array literals, object literals, function parameters, and sequences.
14 This rule does not apply in an `ArrayExpression` or `ArrayPattern` in either of the following cases:
16 * adjacent null elements
17 * an initial null element, to avoid conflicts with the [`array-bracket-spacing`](array-bracket-spacing.md) rule
21 This rule has an object option:
23 * `"before": false` (default) disallows spaces before commas
24 * `"before": true` requires one or more spaces before commas
25 * `"after": true` (default) requires one or more spaces after commas
26 * `"after": false` disallows spaces after commas
30 Examples of **incorrect** code for this rule with the default `{ "before": false, "after": true }` options:
33 /*eslint comma-spacing: ["error", { "before": false, "after": true }]*/
37 var obj = {"foo": "bar" ,"baz": "qur"};
44 Examples of **correct** code for this rule with the default `{ "before": false, "after": true }` options:
47 /*eslint comma-spacing: ["error", { "before": false, "after": true }]*/
53 var obj = {"foo": "bar", "baz": "qur"};
60 Example of **correct** code for this rule with initial null element for the default `{ "before": false, "after": true }` options:
63 /*eslint comma-spacing: ["error", { "before": false, "after": true }]*/
64 /*eslint array-bracket-spacing: ["error", "always"]*/
71 Examples of **incorrect** code for this rule with the `{ "before": true, "after": false }` options:
74 /*eslint comma-spacing: ["error", { "before": true, "after": false }]*/
78 var obj = {"foo": "bar", "baz": "qur"};
84 Examples of **correct** code for this rule with the `{ "before": true, "after": false }` options:
87 /*eslint comma-spacing: ["error", { "before": true, "after": false }]*/
89 var foo = 1 ,bar = 2 ,
93 var obj = {"foo": "bar" ,"baz": "qur"};
100 Examples of **correct** code for this rule with initial null element for the `{ "before": true, "after": false }` options:
103 /*eslint comma-spacing: ["error", { "before": true, "after": false }]*/
104 /*eslint array-bracket-spacing: ["error", "never"]*/
109 ## When Not To Use It
111 If your project will not be following a consistent comma-spacing pattern, turn this rule off.
116 * [JavaScript](http://javascript.crockford.com/code.html)
117 * [Dojo Style Guide](https://dojotoolkit.org/reference-guide/1.9/developer/styleguide.html)
122 * [array-bracket-spacing](array-bracket-spacing.md)
123 * [comma-style](comma-style.md)
124 * [space-in-brackets](space-in-brackets.md) (deprecated)
125 * [space-in-parens](space-in-parens.md)
126 * [space-infix-ops](space-infix-ops.md)
127 * [space-after-keywords](space-after-keywords.md)
128 * [space-unary-ops](space-unary-ops.md)
129 * [space-return-throw-case](space-return-throw-case.md)