Skip to content

Commit

Permalink
Docs: 1tbs with allowSingleLine edge cases (refs #12284) (#12314)
Browse files Browse the repository at this point in the history
Add documentation and tests demonstrating iffy edge cases
  • Loading branch information
kardasis authored and kaicataldo committed Dec 14, 2019
1 parent dd1c30e commit ab912f0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/rules/brace-style.md
Expand Up @@ -129,6 +129,27 @@ if (foo) { bar(); }
if (foo) { bar(); } else { baz(); }

try { somethingRisky(); } catch(e) { handleError(); }

if (foo) { baz(); } else {
boom();
}

if (foo) { baz(); } else if (bar) {
boom();
}

if (foo) { baz(); } else
if (bar) {
boom();
}

if (foo) { baz); } else if (bar) {
boom();
}

try { somethingRisky(); } catch(e) {
handleError();
}
```

### stroustrup
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/brace-style.js
Expand Up @@ -82,6 +82,22 @@ ruleTester.run("brace-style", rule, {
{ code: "if (foo) {}\nelse {}", options: ["allman", { allowSingleLine: true }] },
{ code: "try { bar(); }\ncatch (e) { baz(); }", options: ["allman", { allowSingleLine: true }] },
{ code: "var foo = () => { return; }", options: ["allman", { allowSingleLine: true }], parserOptions: { ecmaVersion: 6 } },
{
code: "if (foo) { baz(); } else {\n boom();\n}",
options: ["1tbs", { allowSingleLine: true }]
},
{
code: "if (foo) { baz(); } else if (bar) {\n boom();\n}",
options: ["1tbs", { allowSingleLine: true }]
},
{
code: "if (foo) { baz(); } else\nif (bar) {\n boom();\n}",
options: ["1tbs", { allowSingleLine: true }]
},
{
code: "try { somethingRisky(); } catch(e) {\n handleError();\n}",
options: ["1tbs", { allowSingleLine: true }]
},
{
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}",
options: ["1tbs"]
Expand Down

0 comments on commit ab912f0

Please sign in to comment.