-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
no-fn-reference-in-iterator
false positives on non-array methods
#568
Comments
I'm willing to take a stab at this, but I'm not sure where to start. Is it even possible to determine if |
Hi @himynameisdave, may I give a suggestion? One thing that seems quite unexpected to me is that:
The reason for my surprise is that my first guess for a cause of this bug would be the rule implementation just looking for So my first suggestion to you would be to generate several examples and see which ones really generate a false positive, in an attempt to have a better feeling of why this problem is happening, before diving into what you said:
|
Maybe we should just disable auto-fix on this rule #418 (comment) |
@fisker I agree that a 'more urgent' action is to disable the auto-fix, but we don't want the rule mistakenly reporting errors anyway. |
I Don't think this is bug, and the auto-fix will be removed in #666 |
I also have the issue with the following code:
where |
We can't know So... I guess you'll have to use const response = await source.find("some uid"); // In this way we know argument is not a function |
Hmmm, but if the lint rule gives so many false positives like this, should it really exist? |
I tried really hard to rewrite this rule , and you can see it did catch a lot of problems in #666 . Big problem is we can't know if callee is an |
It's not |
Which problems? You mean like the following? - const superExpression = constructorBody.find(isSuperExpression);
+ const superExpression = constructorBody.find(body => isSuperExpression(body)); This was not a problem; I think one could argue the new version is more readable, but that's debatable... |
That is exactly why this rule exists, it is problem. |
Are you sure? The The real problem is something like |
No , it's not about binding, it's about function parameter changes . see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-fn-reference-in-iterator.md |
We don't even support |
Oh, of course 🤦♂️ I had some headaches in the past due to the function losing its binding context, that I forgot to think about the parameter changes. Sorry about that. You're right. |
You mean set it to warn? I don't think so... Error is good... The problem is false positives, setting to warn would still make it annoying I think... Is there a good way to let users know that some false positives are expected and encourage usage of |
In my case, the 'error' occurred while I was updating my Not sure how to fix the 'false' positive, but as long as it's not auto fixed, I'd assume the developers would know when or if this rule is worth keeping as an error in their codebase 🤔 |
What if the linting error itself provides a hint such as:
|
Good idea, PR welcome. |
Nice! I don't have time to do it though, sorry about that. |
This rule also triggers for most Bluebird.js use cases. (Bluebird.map, Bluebird.filter, etc). Obviously I'll just disable to the rule globally in my case, but it seems like this rule has really a lot of false positives and may not be great to have enabled (neither warn nor error) by default. Just my 2 cents. |
Anyone using MongoDB and Mongoose? const filterModel = {};
const windows = await Tour.find(filterModel); because it thought Mongo
My object Make me so confuse @@ |
no-fn-reference-in-iterator
false positives on non-array methods
.filter
is not an iterator here. I think the rule confuses it withArray.prototype.filter
and the false-positive seems specifically triggered by aCallExpression
argument.The autofix produces broken code for this case.
The text was updated successfully, but these errors were encountered: