sindresorhus/eslint-plugin-unicorn

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

Chiusa

#717 aperta il 4 mag 2020

 (8 commenti) (2 reazioni) (0 assegnatari)JavaScript (468 fork)user submission
enhancementhelp wanted

Metriche repository

Star
 (5022 stelle)
Metriche merge PR
 (Merge medio 1g 16h) (399 PR mergiate in 30 g)

Descrizione

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`

Guida contributor