Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: 1tbs with allowSingleLine edge cases (refs #12284) #12314

Merged
merged 1 commit into from Dec 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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