diff --git a/rules/no-directive-replace.js b/rules/no-directive-replace.js index 83305668..16e8e5e4 100644 --- a/rules/no-directive-replace.js +++ b/rules/no-directive-replace.js @@ -21,11 +21,6 @@ module.exports = function(context) { return fnExpression.parent.type === 'CallExpression' && utils.isAngularDirectiveDeclaration(fnExpression.parent); } - function inDirectiveBody(node) { - var block = utils.findNodeTypeInParents(node, 'BlockStatement'); - return block && isDirectiveDefinitionFunction(block.parent); - } - var reportedNodesByName = {}; function addPotentialReplaceNode(variableName, node) { @@ -34,7 +29,7 @@ module.exports = function(context) { var report = { name: variableName, node: node, - block: utils.findNodeTypeInParents(node, 'BlockStatement') + block: context.getScope().block.body }; nodeList.push(report); @@ -90,7 +85,7 @@ module.exports = function(context) { } // report directly if object is part of a return statement and inside a directive body - if (objectExpressionParent.type === 'ReturnStatement' && inDirectiveBody(objectExpressionParent)) { + if (objectExpressionParent.type === 'ReturnStatement' && isDirectiveDefinitionFunction(context.getScope().block)) { context.report(node, 'Directive definition property replace is deprecated.'); } } diff --git a/rules/utils/utils.js b/rules/utils/utils.js index 96ea18fd..f5d74deb 100644 --- a/rules/utils/utils.js +++ b/rules/utils/utils.js @@ -50,7 +50,6 @@ module.exports = { isRouteDefinition: isRouteDefinition, isUIRouterStateDefinition: isUIRouterStateDefinition, findIdentiferInScope: findIdentiferInScope, - findNodeTypeInParents: findNodeTypeInParents, getControllerDefinition: getControllerDefinition }; @@ -468,20 +467,6 @@ function findIdentiferInScope(context, identifier) { return identifierNode; } -/** - * Find the closest parent node with the specified nodeType. - * - * @param {Object} node The node to start the search. - * @param {String} nodeType The node type (e.g. 'BlockStatement') - * @returns {Object} The first parent node with the specified nodeType or undefined; - */ -function findNodeTypeInParents(node, nodeType) { - if (!node || node.type === nodeType) { - return node; - } - return findNodeTypeInParents(node.parent, nodeType); -} - /** * Find the function definition of a controller in the current context. *