Skip to content

Commit ab912f0

Browse files
kardasisKai Cataldo
authored andcommitted
Docs: 1tbs with allowSingleLine edge cases (refs #12284) (#12314)
Add documentation and tests demonstrating iffy edge cases
1 parent dd1c30e commit ab912f0

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

docs/rules/brace-style.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,27 @@ if (foo) { bar(); }
129129
if (foo) { bar(); } else { baz(); }
130130

131131
try { somethingRisky(); } catch(e) { handleError(); }
132+
133+
if (foo) { baz(); } else {
134+
boom();
135+
}
136+
137+
if (foo) { baz(); } else if (bar) {
138+
boom();
139+
}
140+
141+
if (foo) { baz(); } else
142+
if (bar) {
143+
boom();
144+
}
145+
146+
if (foo) { baz); } else if (bar) {
147+
boom();
148+
}
149+
150+
try { somethingRisky(); } catch(e) {
151+
handleError();
152+
}
132153
```
133154

134155
### stroustrup

tests/lib/rules/brace-style.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ ruleTester.run("brace-style", rule, {
8282
{ code: "if (foo) {}\nelse {}", options: ["allman", { allowSingleLine: true }] },
8383
{ code: "try { bar(); }\ncatch (e) { baz(); }", options: ["allman", { allowSingleLine: true }] },
8484
{ code: "var foo = () => { return; }", options: ["allman", { allowSingleLine: true }], parserOptions: { ecmaVersion: 6 } },
85+
{
86+
code: "if (foo) { baz(); } else {\n boom();\n}",
87+
options: ["1tbs", { allowSingleLine: true }]
88+
},
89+
{
90+
code: "if (foo) { baz(); } else if (bar) {\n boom();\n}",
91+
options: ["1tbs", { allowSingleLine: true }]
92+
},
93+
{
94+
code: "if (foo) { baz(); } else\nif (bar) {\n boom();\n}",
95+
options: ["1tbs", { allowSingleLine: true }]
96+
},
97+
{
98+
code: "try { somethingRisky(); } catch(e) {\n handleError();\n}",
99+
options: ["1tbs", { allowSingleLine: true }]
100+
},
85101
{
86102
code: "if (tag === 1) fontstack.name = pbf.readString(); \nelse if (tag === 2) fontstack.range = pbf.readString(); \nelse if (tag === 3) {\n var glyph = pbf.readMessage(readGlyph, {});\n fontstack.glyphs[glyph.id] = glyph; \n}",
87103
options: ["1tbs"]

0 commit comments

Comments
 (0)