6 - array-bracket-spacing
8 - computed-property-spacing
13 Some style guides require or disallow spaces inside of parentheses:
17 var x = ( 1 + 2 ) * 3;
25 This rule will enforce consistent spacing directly inside of parentheses, by disallowing or requiring one or more spaces to the right of `(` and to the left of `)`.
27 As long as you do not explicitly disallow empty parentheses using the `"empty"` exception , `()` will be allowed.
31 There are two options for this rule:
33 * `"never"` (default) enforces zero spaces inside of parentheses
34 * `"always"` enforces a space inside of parentheses
36 Depending on your coding conventions, you can choose either option by specifying it in your configuration:
39 "space-in-parens": ["error", "always"]
44 Examples of **incorrect** code for this rule with the default `"never"` option:
49 /*eslint space-in-parens: ["error", "never"]*/
59 var foo = ( 1 + 2 ) * 3;
60 ( function () { return 'bar'; }() );
65 Examples of **correct** code for this rule with the default `"never"` option:
70 /*eslint space-in-parens: ["error", "never"]*/
78 var foo = (1 + 2) * 3;
79 (function () { return 'bar'; }());
86 Examples of **incorrect** code for this rule with the `"always"` option:
91 /*eslint space-in-parens: ["error", "always"]*/
99 var foo = (1 + 2) * 3;
100 (function () { return 'bar'; }());
105 Examples of **correct** code for this rule with the `"always"` option:
110 /*eslint space-in-parens: ["error", "always"]*/
119 var foo = ( 1 + 2 ) * 3;
120 ( function () { return 'bar'; }() );
127 An object literal may be used as a third array item to specify exceptions, with the key `"exceptions"` and an array as the value. These exceptions work in the context of the first option. That is, if `"always"` is set to enforce spacing, then any "exception" will *disallow* spacing. Conversely, if `"never"` is set to disallow spacing, then any "exception" will *enforce* spacing.
129 Note that this rule only enforces spacing within parentheses; it does not check spacing within curly or square brackets, but will enforce or disallow spacing of those brackets if and only if they are adjacent to an opening or closing parenthesis.
131 The following exceptions are available: `["{}", "[]", "()", "empty"]`.
135 Empty parens exception and behavior:
137 * `always` allows for both `()` and `( )`
138 * `never` (default) requires `()`
139 * `always` excepting `empty` requires `()`
140 * `never` excepting `empty` requires `( )` (empty parens without a space is here forbidden)
144 Examples of **incorrect** code for this rule with the `"never", { "exceptions": ["{}"] }` option:
149 /*eslint space-in-parens: ["error", "never", { "exceptions": ["{}"] }]*/
152 foo(1, {bar: 'baz'});
157 Examples of **correct** code for this rule with the `"never", { "exceptions": ["{}"] }` option:
162 /*eslint space-in-parens: ["error", "never", { "exceptions": ["{}"] }]*/
165 foo(1, {bar: 'baz'} );
170 Examples of **incorrect** code for this rule with the `"always", { "exceptions": ["{}"] }` option:
175 /*eslint space-in-parens: ["error", "always", { "exceptions": ["{}"] }]*/
178 foo( 1, {bar: 'baz'} );
183 Examples of **correct** code for this rule with the `"always", { "exceptions": ["{}"] }` option:
188 /*eslint space-in-parens: ["error", "always", { "exceptions": ["{}"] }]*/
191 foo( 1, {bar: 'baz'});
196 Examples of **incorrect** code for this rule with the `"never", { "exceptions": ["[]"] }` option:
201 /*eslint space-in-parens: ["error", "never", { "exceptions": ["[]"] }]*/
209 Examples of **correct** code for this rule with the `"never", { "exceptions": ["[]"] }` option:
214 /*eslint space-in-parens: ["error", "never", { "exceptions": ["[]"] }]*/
222 Examples of **incorrect** code for this rule with the `"always", { "exceptions": ["[]"] }` option:
227 /*eslint space-in-parens: ["error", "always", { "exceptions": ["[]"] }]*/
230 foo( [bar, baz], 1 );
235 Examples of **correct** code for this rule with the `"always", { "exceptions": ["[]"] }` option:
240 /*eslint space-in-parens: ["error", "always", { "exceptions": ["[]"] }]*/
248 Examples of **incorrect** code for this rule with the `"never", { "exceptions": ["()"] }]` option:
253 /*eslint space-in-parens: ["error", "never", { "exceptions": ["()"] }]*/
262 Examples of **correct** code for this rule with the `"never", { "exceptions": ["()"] }]` option:
267 /*eslint space-in-parens: ["error", "never", { "exceptions": ["()"] }]*/
276 Examples of **incorrect** code for this rule with the `"always", { "exceptions": ["()"] }]` option:
281 /*eslint space-in-parens: ["error", "always", { "exceptions": ["()"] }]*/
289 Examples of **correct** code for this rule with the `"always", { "exceptions": ["()"] }]` option:
294 /*eslint space-in-parens: ["error", "always", { "exceptions": ["()"] }]*/
302 The `"empty"` exception concerns empty parentheses, and works the same way as the other exceptions, inverting the first option.
304 Example of **incorrect** code for this rule with the `"never", { "exceptions": ["empty"] }]` option:
309 /*eslint space-in-parens: ["error", "never", { "exceptions": ["empty"] }]*/
316 Example of **correct** code for this rule with the `"never", { "exceptions": ["empty"] }]` option:
321 /*eslint space-in-parens: ["error", "never", { "exceptions": ["empty"] }]*/
328 Example of **incorrect** code for this rule with the `"always", { "exceptions": ["empty"] }]` option:
333 /*eslint space-in-parens: ["error", "always", { "exceptions": ["empty"] }]*/
340 Example of **correct** code for this rule with the `"always", { "exceptions": ["empty"] }]` option:
345 /*eslint space-in-parens: ["error", "always", { "exceptions": ["empty"] }]*/
352 You can include multiple entries in the `"exceptions"` array.
354 Examples of **incorrect** code for this rule with the `"always", { "exceptions": ["{}", "[]"] }]` option:
359 /*eslint space-in-parens: ["error", "always", { "exceptions": ["{}", "[]"] }]*/
363 foo( {bar: 'baz'}, [1, 2] );
368 Examples of **correct** code for this rule with the `"always", { "exceptions": ["{}", "[]"] }]` option:
373 /*eslint space-in-parens: ["error", "always", { "exceptions": ["{}", "[]"] }]*/
377 foo({bar: 'baz'}, [1, 2]);
382 ## When Not To Use It
384 You can turn this rule off if you are not concerned with the consistency of spacing between parentheses.