Skip to content

Commit

Permalink
Fix: Curly rule doesn't account for leading comment (fixes eslint#7538)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen committed Nov 5, 2016
1 parent f5764ee commit 1bf8a2c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/rules/curly.md
Expand Up @@ -183,6 +183,11 @@ while (true) {
for (var i = 0; foo; i++) {
doSomething();
}

if (foo) {
// some comment
bar();
}
```

Examples of **correct** code for the `"multi-or-nest"` option:
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/curly.js
Expand Up @@ -290,7 +290,7 @@ module.exports = {
}
} else if (multiOrNest) {
if (hasBlock && body.body.length === 1 && isOneLiner(body.body[0])) {
expected = false;
expected = !!(body.body[0].leadingComments && body.body[0].leadingComments.length);
} else if (!isOneLiner(body)) {
expected = true;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/curly.js
Expand Up @@ -126,6 +126,14 @@ ruleTester.run("curly", rule, {
code: "if (foo) \n quz = true;",
options: ["multi-or-nest"]
},
{
code: "if (foo) { \n // line of comment \n quz = true; \n }",
options: ["multi-or-nest"]
},
{
code: "// line of comment \n if (foo) \n quz = true; \n",
options: ["multi-or-nest"]
},
{
code: "while (true) \n doSomething();",
options: ["multi-or-nest"]
Expand Down

0 comments on commit 1bf8a2c

Please sign in to comment.