diff --git a/rules/consistent-function-scoping.js b/rules/consistent-function-scoping.js
index 25cc381b86..fa3f0d732c 100644
--- a/rules/consistent-function-scoping.js
+++ b/rules/consistent-function-scoping.js
@@ -153,17 +153,21 @@ const create = context => {
const {scopeManager} = sourceCode;
const functions = [];
- let hasJsx = false;
return {
- 'ArrowFunctionExpression, FunctionDeclaration': node => functions.push(node),
+ 'ArrowFunctionExpression, FunctionDeclaration': () => {
+ functions.push(false);
+ },
JSXElement: () => {
// Turn off this rule if we see a JSX element because scope
// references does not include JSXElement nodes.
- hasJsx = true;
+ if (functions.length !== 0) {
+ functions[functions.length - 1] = true;
+ }
},
':matches(ArrowFunctionExpression, FunctionDeclaration):exit': node => {
- if (!hasJsx && !checkNode(node, scopeManager)) {
+ const currentFunctionHasJsx = functions.pop();
+ if (!currentFunctionHasJsx && !checkNode(node, scopeManager)) {
context.report({
node,
loc: getFunctionHeadLocation(node, sourceCode),
@@ -173,11 +177,6 @@ const create = context => {
}
});
}
-
- functions.pop();
- if (functions.length === 0) {
- hasJsx = false;
- }
}
};
};
diff --git a/test/consistent-function-scoping.js b/test/consistent-function-scoping.js
index 2e91394c8d..2b2c9a9a72 100644
--- a/test/consistent-function-scoping.js
+++ b/test/consistent-function-scoping.js
@@ -192,6 +192,32 @@ ruleTester.run('consistent-function-scoping', rule, {
return Bar;
};
`,
+ outdent`
+ const foo =