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

Only accept functions in then/catch #60

Open
friday opened this issue May 21, 2017 · 2 comments
Open

Only accept functions in then/catch #60

friday opened this issue May 21, 2017 · 2 comments

Comments

@friday
Copy link

friday commented May 21, 2017

Similar to: http://bluebirdjs.com/docs/warning-explanations.html

Examples:

Promise.resolve(1)
  .then(Promise.resolve(2)) // This is ignored, probably not what the developer intended
  .then(console.log) // 1
const errorHandler = console.warn;
Promise.reject('Catch me if you can').catch(errorHandler()) // should have been `errorHandler` without parenthesis 

It wouldn't be possible to cover this completely with static code analysis I guess (we would have to know that console.warn isn't a function that returns another function), but the first example should be detectable at least?

@macklinu
Copy link
Contributor

macklinu commented Feb 5, 2018

I'm not 100% sure if this is possible without exploring a little bit (fairly new to ESLint plugin development), but I think this would be a great thing to consider and weave into #47. 👍

@friday
Copy link
Author

friday commented Feb 5, 2018

As I read #47, that one seems to be limited to the number of arguments, which I think is much easier. I'm also not sure this issue is actually possible since references or function calls could be valid if they return other functions, and I'm not sure how much can be done with static code analysis.

Good luck either way, and thank you for the effort!

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

2 participants