9 - https://en.wikipedia.org/wiki/Indent_style
14 Brace style is closely related to [indent style](https://en.wikipedia.org/wiki/Indent_style) in programming and describes the placement of braces relative to their control statement and body. There are probably a dozen, if not more, brace styles in the world.
16 The *one true brace style* is one of the most common brace styles in JavaScript, in which the opening brace of a block is placed on the same line as its corresponding statement or declaration. For example:
26 One common variant of one true brace style is called Stroustrup, in which the `else` statements in an `if-else` construct, as well as `catch` and `finally`, must be on its own line after the preceding closing brace. For example:
37 Another style is called [Allman](https://en.wikipedia.org/wiki/Indent_style#Allman_style), in which all the braces are expected to be on their own lines without any extra indentation. For example:
50 While no style is considered better than the other, most developers agree that having a consistent style throughout a project is important for its long-term maintainability.
54 This rule enforces consistent brace style for blocks.
58 This rule has a string option:
60 * `"1tbs"` (default) enforces one true brace style
61 * `"stroustrup"` enforces Stroustrup style
62 * `"allman"` enforces Allman style
64 This rule has an object option for an exception:
66 * `"allowSingleLine": true` (default `false`) allows the opening and closing braces for a block to be on the *same* line
70 Examples of **incorrect** code for this rule with the default `"1tbs"` option:
75 /*eslint brace-style: "error"*/
113 Examples of **correct** code for this rule with the default `"1tbs"` option:
118 /*eslint brace-style: "error"*/
146 // when there are no braces, there are no problems
148 else if (baz) boom();
153 Examples of **correct** code for this rule with the `"1tbs", { "allowSingleLine": true }` options:
158 /*eslint brace-style: ["error", "1tbs", { "allowSingleLine": true }]*/
160 function nop() { return; }
164 if (foo) { bar(); } else { baz(); }
166 try { somethingRisky(); } catch(e) { handleError(); }
168 if (foo) { baz(); } else {
172 if (foo) { baz(); } else if (bar) {
176 if (foo) { baz(); } else
181 if (foo) { baz(); } else if (bar) {
185 try { somethingRisky(); } catch(e) {
193 class D { static { foo(); } }
200 Examples of **incorrect** code for this rule with the `"stroustrup"` option:
205 /*eslint brace-style: ["error", "stroustrup"]*/
242 Examples of **correct** code for this rule with the `"stroustrup"` option:
247 /*eslint brace-style: ["error", "stroustrup"]*/
277 // when there are no braces, there are no problems
279 else if (baz) boom();
284 Examples of **correct** code for this rule with the `"stroustrup", { "allowSingleLine": true }` options:
289 /*eslint brace-style: ["error", "stroustrup", { "allowSingleLine": true }]*/
291 function nop() { return; }
298 try { somethingRisky(); }
299 catch(e) { handleError(); }
305 class D { static { foo(); } }
312 Examples of **incorrect** code for this rule with the `"allman"` option:
317 /*eslint brace-style: ["error", "allman"]*/
350 Examples of **correct** code for this rule with the `"allman"` option:
355 /*eslint brace-style: ["error", "allman"]*/
393 // when there are no braces, there are no problems
395 else if (baz) boom();
400 Examples of **correct** code for this rule with the `"allman", { "allowSingleLine": true }` options:
405 /*eslint brace-style: ["error", "allman", { "allowSingleLine": true }]*/
407 function nop() { return; }
414 try { somethingRisky(); }
415 catch(e) { handleError(); }
425 class D { static { foo(); } }
430 ## When Not To Use It
432 If you don't want to enforce a particular brace style, don't enable this rule.