function-type on a string constant
lapo-luchini opened this issue · 3 comments
var server = (…) ? 'http://test/' : 'http://production/';
angular.module('myMod', […]).constant('server', server);
gives me a Use anonymous functions instead of named function angular/function-type
.
I tried with:
angular.module('myMod', […]).constant('server', function () {
return (…) ? 'http://test/' : 'http://production/';
});
but that returns the literal function, not the value.
What's the suggested approach here?
Seems to be a bug. Maybe a work around is to call the function immediately. I'm guessing without testing.
@lapo-luchini, if you're still stuck on this, have you checked that the angular/function-type
rule that's applying is using the named
option?
If you haven't overridden anything, both plugin:angular/johnpapa
and plugin:angular/bestpractices
will use anonymous
as the default option for the rule, which causes the lint you're seeing.
That is, they'll be equivalent to have the rule:
"angular/function-type": [2, "anonymous"]
The problem I was referring to is that the parameter was a string, not a function. (named or otherwise)