brace-style
Configuration
Enforce consistent brace style for blocks.
Rule Details
This rule enforces a consistent brace style across block-bearing constructs — function bodies, control-flow blocks (if, else, for, while, do, try, catch, finally), class bodies, switch bodies, class static blocks, and TypeScript namespace / module bodies.
The three supported styles place the opening curly differently relative to the controlling statement, and treat the closing curly's relationship to a following keyword (else, catch, finally) differently.
Options
This rule has a string option:
"1tbs"(default) — "one true brace style". Opening brace on the same line as the controlling statement; closing brace on the same line as the following keyword (else,catch,finally)."stroustrup"— like"1tbs", but the closing brace must be on its own line beforeelse/catch/finally."allman"— opening brace on a new line by itself; closing brace also on its own line.
This rule has an object option:
"allowSingleLine": true(defaultfalse) — allows the opening and closing braces for a block to be on the same line.
1tbs
Examples of incorrect code for this rule with the default "1tbs" option:
Examples of correct code for this rule with the default "1tbs" option:
stroustrup
Examples of incorrect code for this rule with the "stroustrup" option:
Examples of correct code for this rule with the "stroustrup" option:
allman
Examples of incorrect code for this rule with the "allman" option:
Examples of correct code for this rule with the "allman" option:
allowSingleLine
Examples of correct code for this rule with the { "allowSingleLine": true } option: