Skip to content

Commit

Permalink
Docs: 1tbs with allowSingleLine edge cases (refs eslint#12284)
Browse files Browse the repository at this point in the history
Add documentation and tests demonstrating iffy edge cases
  • Loading branch information
kardasis committed Sep 26, 2019
1 parent f5537b2 commit fe8721b
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 fe8721b

Please sign in to comment.