Skip to content

Commit

Permalink
Fix: brace-style crash with lone block statements (fixes #7908) (#7909)
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark authored and gyandeeps committed Jan 13, 2017
1 parent 5eb2e88 commit b3f2094
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/rules/brace-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ module.exports = {

return {
BlockStatement(node) {
validateCurlyPair(sourceCode.getFirstToken(node), sourceCode.getLastToken(node));
if (
node.parent.type !== "BlockStatement" &&
node.parent.type !== "SwitchCase" &&
node.parent.type !== "Program"
) {
validateCurlyPair(sourceCode.getFirstToken(node), sourceCode.getLastToken(node));
}
},
ClassBody(node) {
validateCurlyPair(sourceCode.getFirstToken(node), sourceCode.getLastToken(node));
Expand Down
33 changes: 32 additions & 1 deletion tests/lib/rules/brace-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,38 @@ ruleTester.run("brace-style", rule, {
{
code: "(class {})",
options: ["allman", { allowSingleLine: true }]
}
},

// https://github.com/eslint/eslint/issues/7908
"{}",
`
if (foo) {
}
{
}
`,
`
switch (foo) {
case bar:
baz();
{
qux();
}
}
`,
`
{
}
`,
`
{
{
}
}
`
],

invalid: [
Expand Down

0 comments on commit b3f2094

Please sign in to comment.