eslint-plugin-angular icon indicating copy to clipboard operation
eslint-plugin-angular copied to clipboard

function-type on a string constant

Open lapo-luchini opened this issue 6 years ago • 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?

lapo-luchini avatar Jun 12 '18 09:06 lapo-luchini

Seems to be a bug. Maybe a work around is to call the function immediately. I'm guessing without testing.

xdjinnx avatar Jun 12 '18 10:06 xdjinnx

@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"]

miqh avatar Oct 07 '18 01:10 miqh

The problem I was referring to is that the parameter was a string, not a function. (named or otherwise)

lapo-luchini avatar Oct 08 '18 08:10 lapo-luchini