Skip to content

Commit

Permalink
Update: fix brace-style false negative on multiline node (fixes #7493
Browse files Browse the repository at this point in the history
…) (#7496)
  • Loading branch information
not-an-aardvark authored and nzakas committed Nov 3, 2016
1 parent 3798aea commit af1fde1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/brace-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ module.exports = {
});
}

if (curlyTokenEnd.loc.start.line === block.body[block.body.length - 1].loc.start.line) {
if (curlyTokenEnd.loc.start.line === block.body[block.body.length - 1].loc.end.line) {
context.report({
node: block.body[block.body.length - 1],
message: CLOSE_MESSAGE_SINGLE,
Expand Down
31 changes: 30 additions & 1 deletion tests/lib/rules/brace-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,35 @@ ruleTester.run("brace-style", rule, {
code: "if (foo) // comment \n{\nbar();\n}",
output: "if (foo) // comment \n{\nbar();\n}",
errors: [{ message: OPEN_MESSAGE, type: "IfStatement" }]
}
},

// https://github.com/eslint/eslint/issues/7493
{
code: "if (foo) {\n bar\n.baz }",
output: "if (foo) {\n bar\n.baz \n}",
errors: [{ message: CLOSE_MESSAGE_SINGLE, type: "ExpressionStatement" }]
},
{
code: "if (foo)\n{\n bar\n.baz }",
output: "if (foo)\n{\n bar\n.baz \n}",
options: ["allman"],
errors: [{ message: CLOSE_MESSAGE_SINGLE, type: "ExpressionStatement" }]
},
{
code: "if (foo) { bar\n.baz }",
output: "if (foo) {\n bar\n.baz \n}",
options: ["1tbs", { allowSingleLine: true }],
errors: [{ message: BODY_MESSAGE, type: "ExpressionStatement" }, { message: CLOSE_MESSAGE_SINGLE, type: "ExpressionStatement" }]
},
{
code: "if (foo) { bar\n.baz }",
output: "if (foo) \n{\n bar\n.baz \n}",
options: ["allman", { allowSingleLine: true }],
errors: [
{ message: OPEN_MESSAGE_ALLMAN, type: "IfStatement" },
{ message: BODY_MESSAGE, type: "ExpressionStatement" },
{ message: CLOSE_MESSAGE_SINGLE, type: "ExpressionStatement" }
]
},
]
});

0 comments on commit af1fde1

Please sign in to comment.