Skip to content

Commit

Permalink
find directive block with context.getScope (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
tilmanschweitzer committed Dec 6, 2015
1 parent 6fd6346 commit 6964983
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
9 changes: 2 additions & 7 deletions rules/no-directive-replace.js
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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.');
}
}
Expand Down
15 changes: 0 additions & 15 deletions rules/utils/utils.js
Expand Up @@ -50,7 +50,6 @@ module.exports = {
isRouteDefinition: isRouteDefinition,
isUIRouterStateDefinition: isUIRouterStateDefinition,
findIdentiferInScope: findIdentiferInScope,
findNodeTypeInParents: findNodeTypeInParents,
getControllerDefinition: getControllerDefinition
};

Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 6964983

Please sign in to comment.