-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Rule Change: [no-loop-func] add an option to ignore IIFEs #16902
Comments
I support the proposal to ignore IIFEs, and I think there's no need for an option (the issue title suggests adding an option). However, named function expressions could be stored so perhaps we should additionally check if the function is referenced. let current = getStart();
const arr = [];
while (current) {
(function f() {
current;
arr.push(f); // <--
})();
current = current.upper;
} |
I think we should also keep reporting on IIFEs with async and generator functions, because their asynchronous state may become accessible from outside, even without a self-reference. let current = getStart();
const arr = [];
while (current) {
const p = (async () => {
await someDelay();
current;
})();
arr.push(p);
current = current.upper;
}
await Promise.all(arr); Other that this (and possibly other yet-to-be-discovered edge cases), I also like the proposal. |
Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update. |
In the 2023-03-23 TSC meeting we have agreed to:
Notes from this meeting will be published in this PR. |
Would love to work on this. |
Apparently, we should also ignore reporting for this rule, if the function is called (irrespective of its IIFE nature) anywhere inside the loop's scope. |
What rule do you want to change?
no-loop-func
What change to do you want to make?
Generate fewer warnings
How do you think the change should be implemented?
A new default behavior
Example code
What does the rule currently do for this code?
the rule will report for this code even though this code is provably safe because the function is immediately invoked.
What will the rule do after it's changed?
the rule will not report for this code as it is provably safe
Participation
Additional comments
Playground
Also worth noting that the rule's error message is wonky here. For the example code it reports the same ID many times:
The text was updated successfully, but these errors were encountered: