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

Mistake promise/prefer-await-to-callback #116

Closed
mathieug opened this issue Mar 7, 2018 · 4 comments · Fixed by #117
Closed

Mistake promise/prefer-await-to-callback #116

mathieug opened this issue Mar 7, 2018 · 4 comments · Fixed by #117

Comments

@mathieug
Copy link

mathieug commented Mar 7, 2018

How do I avoid an error with promise/prefer-await-to-callback for this following code which use events:

dbConn.on('error', (err) => logger.warn('MongoDB event `error`:', err));
@macklinu
Copy link
Contributor

macklinu commented Mar 8, 2018

For now, I would disable that rule for the line using:

// eslint-disable-next-line promise/prefer-await-to-callbacks
dbConn.on('error', (err) => logger.warn('MongoDB event `error`:', err));

This seems like a bug though. Perhaps that rule should ignore callbacks in an on() function (which indicates using events). That's not something we currently check for but should probably be considered. I'm not 100% sure how to accomplish that off the top of my head, but suggestions or PRs are welcome!

@macklinu
Copy link
Contributor

macklinu commented Mar 8, 2018

I think I found a fix for this - pushing up to #117.

@macklinu macklinu added the has pr label Mar 8, 2018
@macklinu macklinu self-assigned this Mar 8, 2018
@mathieug
Copy link
Author

mathieug commented Mar 9, 2018

Maybe this plugin can help you: eslint-plugin-unicorn, check the rule prefer-add-event-listener for example.

@alexilyaev
Copy link

alexilyaev commented Mar 10, 2018

Also the rule page is missing examples:
https://github.com/xjamundx/eslint-plugin-promise/blob/master/docs/rules/prefer-await-to-callbacks.md

Opened a ticket:
#118

macklinu added a commit that referenced this issue May 24, 2018
Resolves #116 

* test: add failing test for #116

* fix(rule): ignore reporting on event listener callbacks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants