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

[Fix] jsx-key not detecting missing keys in Array.from's mapping function #3369

Merged
merged 1 commit into from Aug 25, 2022

Conversation

sjarva
Copy link
Contributor

@sjarva sjarva commented Aug 25, 2022

Closes #3368

Now the jsx-key rule will catch these invalid cases:

Array.from([1, 2 ,3], function(x) { return <App /> });
Array.from([1, 2 ,3], (x => { return <App /> }));
Array.from([1, 2 ,3], (x => <App />));

and will allow these valid cases:

Array.from([1, 2, 3], function(x) { return <App key={x} /> });
Array.from([1, 2, 3], (x => <App key={x} />));
Array.from([1, 2, 3], (x => {return <App key={x} />}));
Array.from([1, 2, 3], someFn);
Array.from([1, 2, 3]);

In addition, I did some refactoring to keep the code DRY (the checking for keys in Array.prototype.map and Array.from had many repetitions).

@codecov
Copy link

codecov bot commented Aug 25, 2022

Codecov Report

Merging #3369 (d826522) into master (b0d0ca1) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head d826522 differs from pull request most recent head bb4d1b3. Consider uploading reports for the commit bb4d1b3 to get more accurate results

@@           Coverage Diff           @@
##           master    #3369   +/-   ##
=======================================
  Coverage   97.55%   97.55%           
=======================================
  Files         123      123           
  Lines        8918     8928   +10     
  Branches     3255     3256    +1     
=======================================
+ Hits         8700     8710   +10     
  Misses        218      218           
Impacted Files Coverage Δ
lib/rules/jsx-key.js 97.95% <100.00%> (+0.23%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@ljharb ljharb merged commit bb4d1b3 into jsx-eslint:master Aug 25, 2022
@sjarva sjarva deleted the jsx-key-in-array-from branch August 25, 2022 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

react/jsx-key doesn't detect Array.from
2 participants