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

Enable eslint rule for missing jsx keys #2400

Merged
merged 1 commit into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@
"react/prefer-stateless-function": "off",
"react/jsx-indent-props": "off",
"react/jsx-closing-bracket-location": "off",
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/jsx-first-prop-new-line": "off",
"react/jsx-key": "error",
"react/no-string-refs": "error",
// FIXME: Deprecate use of findDOMNode https://github.com/mozilla/addons-frontend/issues/968
"react/no-find-dom-node": "off",
// FIXME: Switch using .jsx for jsx files https://github.com/mozilla/addons-frontend/issues/969.
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }]
},
"settings": {
"import/ignore": [
Expand Down
4 changes: 4 additions & 0 deletions src/admin/containers/AddonPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,22 @@ class AddonPage extends React.Component {
];
if (addon.homepage) {
items.push([
// eslint-disable-next-line react/jsx-key
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't these ones get keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's actually using data in the object to make the key later on. The eslint rule just sees any jsx in an array as needing a key so this is a false positive.

<a href={addon.homepage}
rel="external noopener noreferrer" target="_blank">{_('View homepage')}</a>,
'homepage',
]);
}
if (addon.support_email) {
items.push([
// eslint-disable-next-line react/jsx-key
<a href={`mailto:${addon.support_email}`}>{_('Email support')}</a>,
'support_email',
]);
}
if (addon.support_url) {
items.push([
// eslint-disable-next-line react/jsx-key
<a href={addon.support_url}
rel="external noopener noreferrer" target="_blank">{_('View support site')}</a>,
'support_url',
Expand Down Expand Up @@ -85,6 +88,7 @@ class AddonPage extends React.Component {
[file.status, 'status'],
[`${file.size} bytes`, 'size'],
[file.created, 'created'],
// eslint-disable-next-line react/jsx-key
[<a href={file.url}>{_('Download')}</a>, 'download'],
], 'file-info')}
</li>
Expand Down
2 changes: 1 addition & 1 deletion src/amo/components/Categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class CategoriesBase extends React.Component {
<ul className="Categories-list"
ref={(ref) => { this.categories = ref; }}>
{Object.values(categories).map((category) => (
<li className="Categories-list-item">
<li key={category.slug} className="Categories-list-item">
<Link className="Categories-link"
to={`/${visibleAddonType(addonType)}/${category.slug}/`}>
{category.name}
Expand Down
4 changes: 2 additions & 2 deletions src/amo/components/SearchSort/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export class SearchSortBase extends React.Component {
{i18n.gettext('Sort')}
</a>
<ul id="SearchSortOptions" className="SearchSort-list">
{this.sortOptions().map((option) => (
<li className="SearchSort-list-item">
{this.sortOptions().map((option, index) => (
<li key={`sort-${index}`} className="SearchSort-list-item">
<SearchSortLink currentSort={currentSort} filters={filters}
pathname={pathname} sort={option.sort}>
{option.text}
Expand Down
3 changes: 2 additions & 1 deletion src/core/components/Paginate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ export class PaginateBase extends React.Component {
page={currentPage - 1}
text={i18n.gettext('Previous')}
/>
{this.visiblePages({ pageCount }).map((page) =>
{this.visiblePages({ pageCount }).map((page, index) =>
<PaginatorLink
{...linkParams}
key={`page-${index}`}
page={page}
/>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/ErrorList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ErrorList extends React.Component {

return (
<ul className={classNames('ErrorList', className)}>
{items.map((item) => <li className="ErrorList-item">{item}</li>)}
{items.map((item, index) => <li className="ErrorList-item" key={`erroritem-${index}`}>{item}</li>)}
</ul>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/components/Rating/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class RatingBase extends React.Component {
}

return (
// eslint-disable-next-line react/jsx-key
Copy link
Contributor

Choose a reason for hiding this comment

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

Ugh. I was afraid of this. There is a key defined in the props object but it looks like the linter isn't able to recognize it. Could you file an upstream bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One was already filed here: jsx-eslint/eslint-plugin-react#613

<button
onClick={this.onSelectRating}
value={thisRating}
Expand Down
2 changes: 1 addition & 1 deletion tests/client/amo/containers/TestApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('App', () => {
return <p>The component</p>;
}
}
const root = render({ children: [<MyComponent />] });
const root = render({ children: [<MyComponent key="key" />] });
const rootNode = findDOMNode(root);
assert.equal(rootNode.tagName.toLowerCase(), 'div');
assert.equal(rootNode.querySelector('p').textContent, 'The component');
Expand Down