EmmanuelDemey / EmmanuelDemey/eslint-plugin-angular

Faulty check for angular/function-type

Open
#449 16 comments 1 reaction 0 assignees View on GitHub
Bug Hacktoberfest
Dominant language
JavaScript
Stars
620
Forks
127
PR merge metrics
No merged PRs in 30d

Description

The fule angular/function-type fails when using specific function names and argument patterns. More specific, the reserved names are defined in the rule as
`var angularObjectList = ['animation', 'config', 'constant', 'controller', 'directive', 'factory', 'filter', 'provider', 'service', 'value', 'decorator'];`

When any of those predefined functions are seen and the parameters match the rule specification , the rule is enforced.

I've created a minimal example here, which shows a function named filter, which should probably not be checked by the rule.

`(function () {
'use strict';

angular
.module('bugModule')
.controller('BugController', BugController);

BugController.$inject = [];

/* @ngInject */
function BugController() {
/* jshint validthis:true */
var vm = this;

var _ = {
filter: function (arr, fn) {
var res = [];
for (var i = 0; i < arr.length; ++i) {
if (fn(arr[i])) {
res.push(arr[i]);
}
}
return res;
}
};
vm.global = [1, 2, 3, 4];

activate();

// -------------------------------------------------------------------------

function activate() {
// global vm variable: OK
_.filter(vm.global, function (n) { return n % 2 === 0; });

// function: OK
_.filter(getGlobal(), function (n) { return n % 2 === 0; });

// inlined: OK
_.filter([1, 2, 3, 4], function (n) { return n % 2 === 0; });

// local: FAIL
var local = [1, 2, 3, 4];
_.filter(local, function (n) { return n % 2 === 0; });

doFilter(local);
}

function doFilter(arr) {
// parameter: same as local: FAIL
return _.filter(arr, function (n) { return n % 2 === 0; });
}

function getGlobal() {
return vm.global;
}
}
})();
`

It seems it is the argument checking that fails in this case, since it works when using functions or global variables. Only local variables (and as function parameters) are affected.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.