From fed7ed02f2adbe1ff54c1f1ae46636474bb2f218 Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Wed, 16 Aug 2017 15:07:02 +0200 Subject: [PATCH] Revert "Enhance directive restrict rule to allow split statement for directive registration" --- rules/directive-restrict.js | 46 ------------------------------------- test/directive-restrict.js | 40 -------------------------------- 2 files changed, 86 deletions(-) diff --git a/rules/directive-restrict.js b/rules/directive-restrict.js index 66268fbd..7311e6c6 100644 --- a/rules/directive-restrict.js +++ b/rules/directive-restrict.js @@ -53,24 +53,6 @@ module.exports = { return true; } }); - - if (!directiveNode) { - // Try to find an ancestor function used as definition for one of the found directives - context.getAncestors().some(function(ancestor) { - if (isFunctionDeclaration(ancestor)) { - var fnName = ancestor.id.name; - - var correspondingDirective = foundDirectives.find(function(directive) { - var directiveFnName = getDirectiveFunctionName(directive); - return directiveFnName === fnName; - }); - - directiveNode = correspondingDirective; - return true; - } - }); - } - // The restrict property was not defined inside of a directive. if (!directiveNode) { return; @@ -89,34 +71,6 @@ module.exports = { checkedDirectives.push(directiveNode); } - function isFunctionDeclaration(node) { - return node.type === 'FunctionDeclaration'; - } - - function getDirectiveFunctionName(node) { - var directiveArg = node.arguments[1]; - - // Three ways of creating a directive function: function expression, - // variable name that references a function, and an array with a function - // as the last item - if (utils.isFunctionType(directiveArg)) { - return directiveArg.id.name; - } - - if (utils.isArrayType(directiveArg)) { - directiveArg = directiveArg.elements[directiveArg.elements.length - 1]; - - if (utils.isIdentifierType(directiveArg)) { - return directiveArg.name; - } - return directiveArg.id.name; - } - - if (utils.isIdentifierType(directiveArg)) { - return directiveArg.name; - } - } - return { CallExpression: function(node) { if (utils.isAngularDirectiveDeclaration(node)) { diff --git a/test/directive-restrict.js b/test/directive-restrict.js index f26d7194..669e5b69 100644 --- a/test/directive-restrict.js +++ b/test/directive-restrict.js @@ -40,25 +40,6 @@ eslintTester.run('directive-restrict', rule, { }, { code: 'app.directive("", function() {return {restrict:"E"}})', options: [{restrict: 'EA'}] - }, { - code: `app.directive("snapContainer", ['$scope', myDirective]); - function myDirective($scope) { - return { - restrict: "A" - } - } - `, - options: [{restrict: 'A'}] - }, { - code: `app.directive("snapContainer", myDirective); - /* @ngInject */ - function myDirective($rootScope) { - return { - restrict: "A" - } - } - `, - options: [{restrict: 'A'}] }, // Allowed with explicit restrict { @@ -106,27 +87,6 @@ eslintTester.run('directive-restrict', rule, { code: 'app.directive("", function() {return {restrict:"E"}})', options: [{restrict: 'A'}], errors: [{message: 'Disallowed directive restriction. It must be one of A in that order'}] - }, { - code: `app.directive("snapContainer", ['$scope', myDirective]); - function myDirective($scope) { - return { - restrict: "A" - } - } - `, - options: [{restrict: 'E'}], - errors: [{message: 'Disallowed directive restriction. It must be one of E in that order'}] - }, { - code: `app.directive("snapContainer", myDirective); - /* @ngInject */ - function myDirective($rootScope) { - return { - restrict: "A" - } - } - `, - options: [{restrict: 'E'}], - errors: [{message: 'Disallowed directive restriction. It must be one of E in that order'}] }, // Disallowed with wrong order {