sindresorhus / eslint-plugin-unicorn

More than 100 powerful ESLint rules
MIT License
4.27k stars 367 forks source link

`no-array-for-each`: False positive with non-arrays #1788

Open RebeccaStevens opened 2 years ago

RebeccaStevens commented 2 years ago

Here CB is an object with a bunch of functions on it. The forEach function has nothing to do arrays but gets flagged.

import * as CB from "strict-callbag-basics";

CB.pipe(
  CB.interval(1000),
  CB.map(x => x + 1),
  CB.filter(x => x % 2),
  CB.take(5),
  CB.forEach(x => console.log(x))
);
fisker commented 2 years ago

Would you like to send a PR add CB to this list?

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/0034e6938a95600288c44a10963506c7bd0cb464/rules/no-array-for-each.js#L373-L379

RebeccaStevens commented 2 years ago

Should it also be made so that this list is configurable by the user via an option?

fisker commented 2 years ago

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/59218e3cd653fdf9ad7e7f5d2666e8c2fa775601/rules/utils/is-node-matches.js#L46

Should it also be made so that this list is configurable by the user via an option?

Fine, we can use this https://github.com/sindresorhus/eslint-plugin-unicorn/blob/59218e3cd653fdf9ad7e7f5d2666e8c2fa775601/rules/utils/is-node-matches.js#L46

fregante commented 2 months ago

Related, but in that case the issue is just the autofix: