From df73870513bad27198631281eec2fe560f18654b Mon Sep 17 00:00:00 2001 From: Mathias Schreck Date: Wed, 26 May 2021 16:45:56 +0200 Subject: [PATCH] Improve no-hooks-for-single-case performance --- lib/rules/no-hooks-for-single-case.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/rules/no-hooks-for-single-case.js b/lib/rules/no-hooks-for-single-case.js index 0dd6e12..ebe25a9 100644 --- a/lib/rules/no-hooks-for-single-case.js +++ b/lib/rules/no-hooks-for-single-case.js @@ -32,6 +32,9 @@ module.exports = { }, create(context) { const astUtils = createAstUtils(context.settings); + const isTestCase = astUtils.buildIsTestCaseAnswerer(); + const isDescribe = astUtils.buildIsDescribeAnswerer(); + const options = context.options[0] || {}; const allowedHooks = options.allow || []; let layers = []; @@ -57,7 +60,7 @@ module.exports = { .forEach(function (hookNode) { context.report({ node: hookNode, - message: `Unexpected use of Mocha \`${ hookNode.name }\` hook for a single test case` + message: `Unexpected use of Mocha \`${hookNode.name}\` hook for a single test case` }); }); } @@ -71,13 +74,13 @@ module.exports = { }, CallExpression(node) { - if (astUtils.isDescribe(node)) { + if (isDescribe(node)) { increaseTestCount(); layers.push(newDescribeLayer(node)); return; } - if (astUtils.isTestCase(node)) { + if (isTestCase(node)) { increaseTestCount(); }