Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions rules/directive-restrict.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down
40 changes: 0 additions & 40 deletions test/directive-restrict.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down