question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unicorn/no-fn-reference-in-iterator mistaking .find method?

See original GitHub issue

I’m using a third-party API that contains a method called find. It is not find as in the collection find, but rather their own find. It expects a scalar value (id) and then does its thing.

XO is throwing the following error:

✖   82:41  Do not pass function directly to .find(…).  unicorn/no-fn-reference-in-iterator

Given that the parameter is scalar, how could this happen? Sample code:

const clientId = 20
const client = await oidc.Client.find(clientId)

If this is still a valid application of the rule, what would the correct code look like? The rule doc explains the code could be wrapped in an arrow function, which does pass the text. But, is this right?

const clientId = 20
const client = await oidc.Client.find(() => clientId)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
sindresorhuscommented, Aug 31, 2020

I think we can exclude any await’ed expression.

2reactions
fiskercommented, Sep 1, 2020

One second, what if

const promises = [p1, p2, p3];

const isP2 = p => p === p2;

const foo = await promises.find(isP2)

?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is Java's Iterator not an Iterable? - Stack Overflow
An iterator is stateful. The idea is that if you call Iterable.iterator() twice you'll get independent iterators - for most iterables, anyway.
Read more >
@cling/eslint-config - npm
... reference directly to iterator methods. ( unicorn/no-array-callback-reference ); Disallow using the this argument in array methods.
Read more >
sindresorhus/eslint-plugin-unicorn (Raised $2856.00)
unicorn /no-fn-reference-in-iterator mistaking .find method? Unfunded#813created byRobertoMachorro. $0.00. Rule proposal: Collapsible if-statements.
Read more >
Iterator - CPlusPlus.com
An iterator is any object that, pointing to some element in a range of elements (such as an array or a container), has...
Read more >
Lab 9: Sets in the Java Collection Framework For this week's lab
In your main program, when you find a word that is not in the set of legal words, pass that word to this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found