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

[Bug]: jsx-key could not be triggered when using a custom mapping function #3541

Open
2 tasks done
meteorlxy opened this issue Mar 2, 2023 · 3 comments
Open
2 tasks done

Comments

@meteorlxy
Copy link

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

When using a custom array mapping function like lodash.map, the jsx-key rule won't be triggered

import map from 'lodash/map';

// not triggered
const Comp1 = () => {
  return map([1, 2, 3], (item) => {
    return <div>{item}</div>;
  });
};

// triggered
const Comp2 = () => {
  return [1, 2, 3].map((item) => {
    return <div>{item}</div>;
  });
};

Expected Behavior

Is it possible to add a config to support custom mapping function?

eslint-plugin-react version

v7.32.2

eslint version

v8.35.0

node version

v18.14.0

@meteorlxy meteorlxy added the bug label Mar 2, 2023
@ljharb
Copy link
Member

ljharb commented Mar 2, 2023

No, because there's no way to statically know what kind of function it is.

(Why would you use lodash map anyways when mapping functions have existed in the language for over a decade?)

@meteorlxy
Copy link
Author

meteorlxy commented Mar 14, 2023

A project convention asks contibutors to always use lodash utils if possible. (I have no idea about the original reason. I never use them like this in my personal projects 🤔 )

Thus, I found there are tons of FN of this rule in that project, and it seems that other contributors do not care about the runtime warnings about duplicate keys. (which is really annoying for me...)

If it's difficult to implement it for this eslint rule, I think I'd better ask for updating the project convention.

@ljharb
Copy link
Member

ljharb commented Mar 14, 2023

I suspect that's the easiest approach, given that the vast majority of lodash is in the language now.

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

No branches or pull requests

2 participants