Skip to content

Commit

Permalink
Merge pull request #4003 from aparajita/fix-allman-switch
Browse files Browse the repository at this point in the history
Fix: brace-style rule incorrectly flagging switch (fixes #4002)
  • Loading branch information
ilyavolodin committed Oct 2, 2015
2 parents 3029787 + 70db573 commit 42f6329
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions lib/rules/brace-style.js
Expand Up @@ -182,11 +182,9 @@ module.exports = function(context) {
tokens = context.getLastTokens(node, 3);
}

if (style === "1tbs") {
if (tokens[0].loc.start.line !== tokens[1].loc.start.line) {
context.report(node, OPEN_MESSAGE);
}
} else if (tokens[0].loc.start.line === tokens[1].loc.start.line) {
if (style !== "allman" && tokens[0].loc.start.line !== tokens[1].loc.start.line) {
context.report(node, OPEN_MESSAGE);
} else if (style === "allman" && tokens[0].loc.start.line === tokens[1].loc.start.line) {
context.report(node, OPEN_MESSAGE_ALLMAN);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/brace-style.js
Expand Up @@ -112,7 +112,7 @@ ruleTester.run("brace-style", rule, {
{ message: OPEN_MESSAGE_ALLMAN, type: "TryStatement", line: 1},
{ message: OPEN_MESSAGE_ALLMAN, type: "CatchClause", line: 4}
] },
{ code: "switch(x) { \n case 1: \nbar(); \n }\n ", options: ["allman"], errors: [
{ code: "switch(x) { case 1: \nbar(); }\n ", options: ["allman"], errors: [
{ message: OPEN_MESSAGE_ALLMAN, type: "SwitchStatement", line: 1}
] },
{ code: "if (a) { \nb();\n } else { \nc();\n }", options: ["allman"], errors: [
Expand Down

0 comments on commit 42f6329

Please sign in to comment.