Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function-type on a string constant #549

Open
lapo-luchini opened this issue Jun 12, 2018 · 3 comments
Open

function-type on a string constant #549

lapo-luchini opened this issue Jun 12, 2018 · 3 comments

Comments

@lapo-luchini
Copy link

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?

@xdjinnx
Copy link
Collaborator

xdjinnx commented Jun 12, 2018

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

@miqh
Copy link
Contributor

miqh commented Oct 7, 2018

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

@lapo-luchini
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants