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

feat(no-callback-in-promise): add timeoutsErr option #514

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

brettz9
Copy link
Member

@brettz9 brettz9 commented Jul 25, 2024

What is the purpose of this pull request?

  • Bug fix
  • Changes an existing rule

What changes did you make? (Give an overview)

Copy link

codecov bot commented Jul 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (bbcfcbf) to head (cee71eb).
Report is 39 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #514   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        26    +1     
  Lines          649       711   +62     
  Branches       250       277   +27     
=========================================
+ Hits           649       711   +62     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@scagood
Copy link
Contributor

scagood commented Jul 29, 2024

I think the approach here may not be right, as we're looking for the timer functions with callbacks, not just timer functions.

eg if we use the node:timers/promises api, then timers are fine:

import { setImmediate } from 'timers/promises';

whatever.then((err) => setImmediate('value'))

@brettz9
Copy link
Member Author

brettz9 commented Jul 29, 2024

Ah, good catch. Do you have a suggested way of catching those? Just introspecting on the imports for known promise APIs and failing otherwise?

@scagood
Copy link
Contributor

scagood commented Jul 29, 2024

The first way that comes to mind is using the ReferenceTracker from our eslint-utils.

But I think that it is going about things the wrong way round


Maybe the check could be as simple as checking the scope of the variable and if it's got declarations?

@brettz9
Copy link
Member Author

brettz9 commented Jul 29, 2024

The first way that comes to mind is using the ReferenceTracker from our eslint-utils.

But I think that it is going about things the wrong way round

Maybe the check could be as simple as checking the scope of the variable and if it's got declarations?

You mean because a declaration would itself imply a potentially Promise-based library import as opposed to the built-ins?

…t-community#167

Also:
- fix(`no-callback-in-promise`): ensure timeouts do not err (by default); fixes eslint-community#220
@brettz9 brettz9 force-pushed the no-callback-in-promise-timeouts branch from 6b3dce6 to cee71eb Compare July 30, 2024 03:03
@brettz9
Copy link
Member Author

brettz9 commented Aug 1, 2024

I think the approach here may not be right, as we're looking for the timer functions with callbacks, not just timer functions.

eg if we use the node:timers/promises api, then timers are fine:

import { setImmediate } from 'timers/promises';

whatever.then((err) => setImmediate('value'))

Actually, the code is only checking for timers with callbacks. Your example currently passes with the PR.

The main idea with the timeouts in this PR is to permit them unless the option timeoutsErr: true is set, and then, to only fail with them if the contain a callback (not to fail with their presence).

I was thinking you were suggesting that the following could be more acceptable with the option set:

import { setImmediate } from 'timers/promises';
whatever.then((err) => setImmediate(cb))

...but I'm not sure that it is, as it is still passing around a callback inside of a promise.

@scagood
Copy link
Contributor

scagood commented Aug 2, 2024

Actually, the code is only checking for timers with callbacks. Your example currently passes with the PR.

Ah, that makes sense!

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

Successfully merging this pull request may close these issues.

no-callback-in-promise use cases no-callback-in-promise misses callback passed as argument
2 participants