-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Rule proposal: warn against unused array iterator method return values #2509
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
Comments
I have seen people do weird things like use I think that this would be better as a separate rule that's more generalised (for example #1314) |
Now you mention it, I also saw So I could imaging, that on #1314 we can control that normal return values functions are ignored, but that predefined list of function names are errors (which again could be extended or shortened, e.g. to cover |
Configuring a rule like this is rather difficult, as it is with any type-aware lint rule. This is why I usually don't allow simple ignore lists in type-aware lint rules. As an aside, my only problem with rules like this (which is why I've never bothered to implement them myself) is that they are going to be super expensive to run. TS types are lazily computed, so the more that a rule inspects, the slower that the rule runs. We already see this in rules like It's a high price to pay for a rarer bug vector. |
Yes, since this is type-aware it should not be mixed with #1314, but be a seperate rule. How should expensive functions handled? Flagged as expensive or moved to a seperate plugin? |
We can flag it in the readme for the rule for sure. |
I like this 👍 If you think about it, there are a crazy amount of ways to have floating expressions. function iContainFloatingEpressions() {
'foo';
550;
[].slice(0);
[].splice(0);
(new Date()).getHours();
(() => { console.log() });
} |
This should be part of https://typescript-eslint.io/rules/no-unused-expressions/, no? We are essentially special-casing a subset of call expressions to be flagged. |
It could be - it's just that it's quite a deviation from the rule. There's space here to track all function calls and report if the return value is unused. |
Yes, I don't think there's a way to generically check function calls, but conceptually, this is using some prior knowledge of built-in methods to assume their purity. I'm not sure if putting it as an option makes the most sense— |
I would say that this still belongs as a separate rule for two reasons: first it would require types and thus would be a breaking change to introduce it into second I think we want to leave |
Uh oh!
There was an error while loading. Please reload this page.
There are some function calls where the return value should not be ignored (like some, indexOf, concat, map, etc.) or the function call doesn't make sense. Would be nice to cover this with the no-unused-expressions lint. I did test the snippets below on current master, they both don't fail.
The text was updated successfully, but these errors were encountered: