Skip to content
Permalink
Browse files

Fix: curly `multi` reports single lexical declarations (fixes #11908) (

  • Loading branch information
mdjermanovic authored and kaicataldo committed Nov 4, 2019
1 parent ac60621 commit bb556d5fd735ad2dcea322082edcc07a58105ce9
Showing with 68 additions and 1 deletion.
  1. +1 −1 lib/rules/curly.js
  2. +67 −0 tests/lib/rules/curly.js
@@ -245,7 +245,7 @@ module.exports = {
if (node.type === "IfStatement" && node.consequent === body && requiresBraceOfConsequent(node)) {
expected = true;
} else if (multiOnly) {
if (hasBlock && body.body.length === 1) {
if (hasBlock && body.body.length === 1 && !isLexicalDeclaration(body.body[0])) {
expected = false;
}
} else if (multiLine) {
@@ -164,6 +164,35 @@ ruleTester.run("curly", rule, {
options: ["multi-or-nest"],
parserOptions: { ecmaVersion: 6 }
},
{
code: "if (foo) { const bar = 'baz'; }",
options: ["multi"],
parserOptions: { ecmaVersion: 6 }
},
{
code: "while (foo) { let bar = 'baz'; }",
options: ["multi"],
parserOptions: { ecmaVersion: 6 }
},
{
code: "for(;;) { function foo() {} }",
options: ["multi"]
},
{
code: "for (foo in bar) { class Baz {} }",
options: ["multi"],
parserOptions: { ecmaVersion: 6 }
},
{
code: "if (foo) { let bar; } else { baz(); }",
options: ["multi", "consistent"],
parserOptions: { ecmaVersion: 6 }
},
{
code: "if (foo) { bar(); } else { const baz = 'quux'; }",
options: ["multi", "consistent"],
parserOptions: { ecmaVersion: 6 }
},
{
code: "if (foo) { \n const bar = 'baz'; \n }",
options: ["multi-or-nest"],
@@ -692,6 +721,44 @@ ruleTester.run("curly", rule, {
}
]
},
{
code: "if (foo) { var bar = 'baz'; }",
output: "if (foo) var bar = 'baz'; ",
options: ["multi"],
errors: [
{
messageId: "unexpectedCurlyAfterCondition",
data: { name: "if" },
type: "IfStatement"
}
]
},
{
code: "if (foo) { let bar; } else baz();",
output: "if (foo) { let bar; } else {baz();}",
options: ["multi", "consistent"],
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingCurlyAfter",
data: { name: "else" },
type: "IfStatement"
}
]
},
{
code: "if (foo) bar(); else { const baz = 'quux' }",
output: "if (foo) {bar();} else { const baz = 'quux' }",
options: ["multi", "consistent"],
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingCurlyAfterCondition",
data: { name: "if" },
type: "IfStatement"
}
]
},
{
code: "if (foo) { \n var bar = 'baz'; \n }",
output: "if (foo) \n var bar = 'baz'; \n ",

0 comments on commit bb556d5

Please sign in to comment.
You can’t perform that action at this time.