Skip to content

Commit

Permalink
Fix: consistencies for blockstmt no-inner-fn (fix eslint#12222)
Browse files Browse the repository at this point in the history
  • Loading branch information
anikethsaha committed Mar 18, 2020
1 parent f3788af commit 83f83c5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-inner-declarations.js
Expand Up @@ -67,7 +67,7 @@ module.exports = {
function check(node) {
const body = nearestBody(),
valid = ((body.type === "Program" && body.distance === 1) ||
body.distance === 2);
(body.type !== "Program" && body.distance === 2));

if (!valid) {
context.report({
Expand Down
59 changes: 59 additions & 0 deletions tests/lib/rules/no-inner-declarations.js
Expand Up @@ -61,6 +61,65 @@ ruleTester.run("no-inner-declarations", rule, {
},
type: "FunctionDeclaration"
}]
}, {
code: "if (foo) var a; ",
options: ["both"],
errors: [{
messageId: "moveDeclToRoot",
data: {
type: "variable",
body: "program"
},
type: "VariableDeclaration"
}]
},
{
code: "if (foo) function f(){} ",
options: ["both"],
errors: [{
messageId: "moveDeclToRoot",
data: {
type: "function",
body: "program"
},
type: "FunctionDeclaration"
}]
},
{
code: "function bar() { if (foo) function f(){}; }",
options: ["both"],
errors: [{
messageId: "moveDeclToRoot",
data: {
type: "function",
body: "function body"
},
type: "FunctionDeclaration"
}]
},
{
code: "function bar() { if (foo) var a; }",
options: ["both"],
errors: [{
messageId: "moveDeclToRoot",
data: {
type: "variable",
body: "function body"
},
type: "VariableDeclaration"
}]
},
{
code: "if (foo){ var a; }",
options: ["both"],
errors: [{
messageId: "moveDeclToRoot",
data: {
type: "variable",
body: "program"
},
type: "VariableDeclaration"
}]
}, {
code: "function doSomething() { do { function somethingElse() { } } while (test); }",
errors: [{
Expand Down

0 comments on commit 83f83c5

Please sign in to comment.