Skip to content

[jsx-key] Improve and fix false-positives #332

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

Merged
merged 1 commit into from
Dec 22, 2015

Conversation

silvenon
Copy link
Contributor

Currently only failing tests because I'm new to developing ESLint rules, so it'll take me a couple of days.

I was planning to do it by detecting if the calling method is map. This would apply to Array.prototype.map as well as React.Children.map. Are there any other cases where the rule should be looking for key?

Will fix #320.

@yannickcr
Copy link
Member

Currently only failing tests because I'm new to developing ESLint rules, so it'll take me a couple of days.

No problem :)

I was planning to do it by detecting if the calling method is map.

Seems to be a good solution. Right now I don't see any other cases, but I prefer to miss some edge cases than having some false errors.

@benmosher
Copy link
Contributor

I wondered if this would come up. Couldn't imagine any cases for arrow functions in non-iterators when I wrote the rule, but the examples from #320 make sense.

@silvenon silvenon changed the title [jsx-key] Fix false positives [jsx-key] Improve and fix false-positives Dec 22, 2015
@silvenon
Copy link
Contributor Author

Updated! Sorry for being insanely late 😅

Valid cases:

  • [<App key={0} />, <App key={1} />];
  • [1, 2, 3].map(function(x) { return <App key={x} /> });
  • [1, 2, 3].map(x => <App key={x} />);
  • [1, 2, 3].map(x => { return <App key={x} /> });
  • var App = () => <div />;

Invalid cases:

  • [<App />];
  • [<App {...key} />];
  • [<App key={0}/>, <App />];
  • [1, 2 ,3].map(function(x) { return <App /> });
  • [1, 2 ,3].map(x => <App />);
  • [1, 2 ,3].map(x => { return <App /> });

@silvenon
Copy link
Contributor Author

Note sure why coverage fell, it seems to have fallen in /lib/rules/jsx-pascal-case.js for some reason.

@yannickcr
Copy link
Member

Seems due to a missing test for a case in jsx-key https://coveralls.io/files/1701759218#L50

(for jsx-pascal-case, it already had a bad coverage, my fault!)

- fix false-positives in stateless components
- check in regular functions, not just arrow functions
- check arrow functions with block statements
@silvenon
Copy link
Contributor Author

Done 😃

yannickcr added a commit that referenced this pull request Dec 22, 2015
Fix jsx-key false-positives (fixes #320)
@yannickcr yannickcr merged commit b0ff6be into jsx-eslint:master Dec 22, 2015
@yannickcr
Copy link
Member

Merged, thanks :)

@silvenon silvenon deleted the jsx-key branch December 22, 2015 23:33
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.

False Missing "key" prop for element in iterator from jsx-key
3 participants