eslint-plugin-unicorn: `no-fn-reference-in-iterator` false positives on non-array methods
const obj = {filter: () => {}};
obj.filter([].join()); // error: Do not pass a function reference directly to an iterator method
.filter is not an iterator here. I think the rule confuses it with Array.prototype.filter and the false-positive seems specifically triggered by a CallExpression argument.
The autofix produces broken code for this case.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 1
- Comments: 24 (1 by maintainers)
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.
@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.
Anyone using MongoDB and Mongoose?
because it thought Mongo
db.collection.find()MongooseModel.find()as normal JSfind()and raise the false positive!My object
fileterModeldoes not look like a function at all,Make me so confuse @@
Good idea, PR welcome.
What if the linting error itself provides a hint such as:
Maybe we should just disable auto-fix on this rule https://github.com/sindresorhus/eslint-plugin-unicorn/issues/418#issuecomment-542207903