sindresorhus/eslint-plugin-unicorn

no-fn-reference-in-iterator: Ignore locally declared functions?

已關閉

#717 建立於 2020年5月4日

 (8 則留言) (2 個反應) (0 位負責人)JavaScript (468 個分叉)user submission
enhancementhelp wanted

倉庫指標

星標
 (5,022 顆星)
PR 合併指標
 (平均合併 4小時 30分鐘) (30 天內合併 26 個 PR)

描述

I would like the following to be ignored by no-fn-reference-in-iterator:

const fn = item => {
  // do stuff with iterator items
};

iter1.forEach(fn);
iter2.forEach(fn);
iter3.forEach(fn);

Since fn is locally declared and defined the purpose of no-fn-reference-in-iterator does not apply. I see value in the following situations being reported:

const mapper = require('unicorn-mapper');

function doStuff(iter, fn) {
  iter.forEach(fn); // error on `fn` provided by argument
}

[2, 3, 4].forEach(mapper); // error as `mapper` is from a `require`

貢獻者指南