Skip to content

Commit edb762e

Browse files
Merge pull request #597 from jfgreffier/fix/449
fix: avoid false positive on function-type rule
2 parents 4078df4 + f13d57f commit edb762e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

docs/rules/function-type.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Anonymous or named functions inside AngularJS components.
66
The first parameter sets which type of function is required and can be 'named' or 'anonymous'.
77
The second parameter is an optional list of angular object names.
8+
The third parameter is an optional list of reserved callee object name, default value is ['_'] to avoid false positive with lodash.
89

910
**Rule based on Angular 1.x**
1011

rules/function-type.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = {
3434
},
3535
create: function(context) {
3636
var angularObjectList = ['animation', 'config', 'constant', 'controller', 'directive', 'factory', 'filter', 'provider', 'service', 'value', 'decorator'];
37+
var reservedNameList = ['_'];
3738
var configType = context.options[0] || 'named';
3839
var messageByConfigType = {
3940
anonymous: 'Use anonymous functions instead of named function',
@@ -45,6 +46,10 @@ module.exports = {
4546
angularObjectList = context.options[1];
4647
}
4748

49+
if (context.options[2]) {
50+
reservedNameList = context.options[2];
51+
}
52+
4853
function checkType(arg) {
4954
return utils.isCallExpression(arg) ||
5055
(configType === 'named' && (utils.isIdentifierType(arg) || utils.isNamedInlineFunction(arg))) ||
@@ -59,6 +64,10 @@ module.exports = {
5964
var firstArgument = node.arguments[1];
6065

6166
if (utils.isAngularComponent(node) && callee.type === 'MemberExpression' && angularObjectList.indexOf(angularObjectName) >= 0) {
67+
if (reservedNameList.indexOf(callee.object.name) !== -1) {
68+
return;
69+
}
70+
6271
if (checkType(firstArgument)) {
6372
return;
6473
}

0 commit comments

Comments
 (0)