From 84c68f7049c5c8fb83af9252a5b0458b05e15aca Mon Sep 17 00:00:00 2001 From: Mathias Schreck Date: Mon, 8 Jul 2019 15:51:59 +0200 Subject: [PATCH] Fix no-setup-in-describe to work with arrow functions Fixes: #158 --- lib/rules/no-setup-in-describe.js | 12 ++++++++---- test/rules/no-setup-in-describe.js | 8 ++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/rules/no-setup-in-describe.js b/lib/rules/no-setup-in-describe.js index d6aa739..3e80b98 100644 --- a/lib/rules/no-setup-in-describe.js +++ b/lib/rules/no-setup-in-describe.js @@ -49,6 +49,10 @@ module.exports = function noSetupInDescribe(context) { } } + function isParentDescribe(node) { + return astUtils.isDescribe(node.parent, additionalSuiteNames(settings)); + } + return { CallExpression(node) { const isDescribe = astUtils.isDescribe(node, additionalSuiteNames(settings)); @@ -86,13 +90,13 @@ module.exports = function noSetupInDescribe(context) { } }, - ArrowFunctionExpression() { - if (nesting.length) { + ArrowFunctionExpression(node) { + if (nesting.length && !isParentDescribe(node)) { nesting.push(FUNCTION); } }, - 'ArrowFunctionExpression:exit'() { - if (nesting.length) { + 'ArrowFunctionExpression:exit'(node) { + if (nesting.length && !isParentDescribe(node)) { nesting.pop(); } } diff --git a/test/rules/no-setup-in-describe.js b/test/rules/no-setup-in-describe.js index 6fcb229..986b5af 100644 --- a/test/rules/no-setup-in-describe.js +++ b/test/rules/no-setup-in-describe.js @@ -63,6 +63,14 @@ ruleTester.run('no-setup-in-describe', rule, { line: 1, column: 28 } ] + }, { + code: 'describe("", () => { a(); });', + parserOptions: { ecmaVersion: 2015 }, + errors: [ { + message: 'Unexpected function call in describe block.', + line: 1, + column: 22 + } ] }, { code: 'foo("", function () { a(); });', settings: {