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

Eslint does not work if the jsx key is missed inconditions #3117

Closed
malikiz opened this issue Oct 28, 2021 · 6 comments · Fixed by #3320
Closed

Eslint does not work if the jsx key is missed inconditions #3117

malikiz opened this issue Oct 28, 2021 · 6 comments · Fixed by #3320

Comments

@malikiz
Copy link

malikiz commented Oct 28, 2021

Eslint does not work if the jsx key is missed in conditions

Screenshot:
image

Code:

const Test = (): React.ReactNode => {
  const list = [1, 2, 3, 4, 5];

  return (
    <div>
      {list.map(item => {
        if (item < 2) {
          /* The eslint error didn't work: */
          return <div>{item}</div>;
        }

        return <div />;
      })}
    </div>
  );
};
@ljharb
Copy link
Member

ljharb commented Oct 28, 2021

If you add the key to the second div, do you get a warning on the first one? If not, there's definitely a bug.

@malikiz
Copy link
Author

malikiz commented Oct 28, 2021

If you add the key to the second div, do you get a warning on the first one? If not, there's definitely a bug.

If I add a the key, the error/warning in the condition will not appear.

ljharb added a commit to ljharb/eslint-plugin-react that referenced this issue Feb 23, 2022
@TildaDares
Copy link
Contributor

I'd like to work on this!

@ljharb
Copy link
Member

ljharb commented Jul 3, 2022

Go for it!

@TildaDares
Copy link
Contributor

@ljharb Just to clarify, is the warning supposed to be displayed on both divs?

@ljharb
Copy link
Member

ljharb commented Jul 4, 2022

Correct.

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

Successfully merging a pull request may close this issue.

3 participants