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" should warning when iterate element with optional chaining syntax #2594

Closed
JonathanLee-LX opened this issue Mar 16, 2020 · 9 comments

Comments

@JonathanLee-LX
Copy link
Contributor

JonathanLee-LX commented Mar 16, 2020

Iterate jsx element with optional chaining syntax, react/jsx-key rule don't show warnings.

Just like this

new-react-jsx

@JonathanLee-LX JonathanLee-LX changed the title "jsx-key" should warning when iterate element with optional chaining syntax BUG "jsx-key" should warning when iterate element with optional chaining syntax Mar 16, 2020
@JonathanLee-LX
Copy link
Contributor Author

Maybe this example will be more accurate
no-react-key

@ljharb
Copy link
Member

ljharb commented Mar 19, 2020

(in general, please post code samples as text; images of text are not accessible, can't be copy-pasted, and difficult to read in many circumstances)

That second example would never happen in real code, of course, but yes, I agree that in that case it should show a warning.

@JonathanLee-LX
Copy link
Contributor Author

Thank you first, yes, in the second example, the initial value of arr is normally set to [] instead of undefined, so this rule is generally not a problem.

@JonathanLee-LX
Copy link
Contributor Author

JonathanLee-LX commented Mar 20, 2020

I cloned this repository, and try to add a test case like below
{ code: '[1, 2, 3]?.map(x => <App />)', parser: parsers.TYPESCRIPT_ESLINT, errors: [{message: 'Missing "key" prop for element in array.'}] }
This test case will fail, if add key in App, this case will pass。
So,TYPESCRIPT_ESLINT parser has already implemented this use case?

@ljharb
Copy link
Member

ljharb commented Mar 23, 2020

perhaps - is that the parser you're using? only the typescript parser, and babel-eslint, currently support optional chaining.

@JonathanLee-LX
Copy link
Contributor Author

I'm using @typescript-eslint/parser, the version is ^2.7.0.

@ljharb
Copy link
Member

ljharb commented Mar 26, 2020

TYPESCRIPT_ESLINT is the old parser; you'll need '@TYPESCRIPT_ESLINT' for your failing test case. Want to make a PR with it?

@JonathanLee-LX
Copy link
Contributor Author

Yes, I want, but I can't make this use case pass the test with @typescript-eslint/parser.

@ljharb
Copy link
Member

ljharb commented Mar 29, 2020

That’s fine, a PR with a failing test is still much easier for me to work with than issue comments :-)

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