Skip to content

Commit

Permalink
issue #443 angular/di-unused: does not work with arrow function decla…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
EmmanuelDemey committed Apr 10, 2017
1 parent 9d99535 commit b9429e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rules/utils/angular-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function angularRule(ruleDefinition) {
if (node.type === 'ArrayExpression') {
node = node.elements[node.elements.length - 1] || {};
}
if (node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration') {
if (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression' || node.type === 'FunctionDeclaration') {
return node;
}
if (node.type !== 'Identifier') {
Expand Down
19 changes: 19 additions & 0 deletions test/di-unused.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ eslintTester.run('di-unused', rule, {
code: 'angular.module("").controller("", fn); function fn($q) {}',
errors: [{message: 'Unused injected value $q'}]
},
{
code: 'angular.module("").controller("", ["$q", ($q) => {}]);',
parserOptions: {ecmaVersion: 6},
errors: [{message: 'Unused injected value $q'}]
},
{
code: 'angular.module("").controller("", ($q) => {});',
parserOptions: {ecmaVersion: 6},
errors: [{message: 'Unused injected value $q'}]
},
// directive
{
code: 'angular.module("").directive("", function($q) {});',
Expand All @@ -96,9 +106,18 @@ eslintTester.run('di-unused', rule, {
{
code: 'angular.module("").factory("", function($q) {});',
errors: [{message: 'Unused injected value $q'}]
},
{
code: 'angular.module("").factory("", $q => {});',
errors: [{message: 'Unused injected value $q'}],
parserOptions: {ecmaVersion: 6}
}, {
code: 'angular.module("").factory("", ["q", function($q) {}]);',
errors: [{message: 'Unused injected value $q'}]
}, {
code: 'angular.module("").factory("", ["q", $q => {}]);',
errors: [{message: 'Unused injected value $q'}],
parserOptions: {ecmaVersion: 6}
}, {
code: 'var app = angular.module(""); app.factory("", function($q) {});',
errors: [{message: 'Unused injected value $q'}]
Expand Down

0 comments on commit b9429e7

Please sign in to comment.