Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unicorn/no-fn-reference-in-iterator - wrong context #755

Closed
lagden opened this issue May 29, 2020 · 7 comments · Fixed by #756
Closed

unicorn/no-fn-reference-in-iterator - wrong context #755

lagden opened this issue May 29, 2020 · 7 comments · Fixed by #756
Labels

Comments

@lagden
Copy link

lagden commented May 29, 2020

The lint is claiming a MongoDB query (.find)

// Example
// error  Do not pass function `collection` directly to `.find(…)`  unicorn/no-fn-reference-in-iterator
const results = await collection
  .find({
    $and: [cursorQuery, params.query]
  }, {
    projection: params.projection
  })
  .sort($sort)
  .limit(params.limit + 1)
  .toArray()
@fisker
Copy link
Collaborator

fisker commented May 29, 2020

I can make a PR to ignore objects for now, but

const results = await collection
  .find(
   foo,  // <-- we  can't tell  what this  is
    {
    projection: params.projection
  })
  .sort($sort)
  .limit(params.limit + 1)
  .toArray()

still get reported.

@fisker
Copy link
Collaborator

fisker commented May 29, 2020

This message in issue description might misleading, the message is actually

error  Do not pass function directly to `.find(…)`  unicorn/no-fn-reference-in-iterator

@lagden
Copy link
Author

lagden commented May 29, 2020

The message is from eslint.

image

@fisker
Copy link
Collaborator

fisker commented May 29, 2020

- error  Do not pass function `collection` directly to `.find(…)`  unicorn/no-fn-reference-in-iterator
+ error  Do not pass function directly to `.find(…)`  unicorn/no-fn-reference-in-iterator

There is no function name in that message.

I thought that's also a bug, so I had to test it.

@lagden
Copy link
Author

lagden commented May 29, 2020

@fisker sorry!!

I copied error from other block!! my bad!

// error  eslint:unicorn/no-fn-reference-in-iterator  Do not pass function `collection` directly to `.find(…)`.
const collection = t.context.db.collection('test_paging')
let res = await paging.find(collection, {
  limit: 3
})

@fisker
Copy link
Collaborator

fisker commented May 29, 2020

No problem. As I comment above, if you use object in .find({}) , it will ignored in #756. But .find(foo) will still be a problem, you'll have to use //eslint-disable.

@aleksandr-omise
Copy link

With D3 delaunay error too.

const delaunay = Delaunay.from(
  valuesWithCoord,
  (el) => el.x,
  (el) => el.y
)

const nearestPointIndex = delaunay.find(x, y)

I guess nothing can do about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants