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

Conversation

muffinresearch
Copy link
Contributor

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

r+wc

This will be helpful, thanks. It's a shame that it missed a key sent via object spread but, oh well, still better than nothing.

.eslintrc Outdated
@@ -83,12 +83,13 @@
"react/prefer-stateless-function": "off",
"react/jsx-indent-props": "off",
"react/jsx-closing-bracket-location": "off",
// FIXME: Switch using .jsx for jsx files https://github.com/mozilla/addons-frontend/issues/969.
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this was copied from the old code and I don't think it's relevant. Can it be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -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.

@@ -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

@@ -92,6 +92,7 @@ describe('App', () => {
return <p>The component</p>;
}
}
// eslint-disable-next-line react/jsx-key
const root = render({ children: [<MyComponent />] });
Copy link
Contributor

Choose a reason for hiding this comment

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

You could also just add key="key" here.

@muffinresearch muffinresearch force-pushed the lint-for-missing-keys branch from a1c3fc9 to 8ca7274 Compare May 22, 2017 09:07
@muffinresearch muffinresearch merged commit f04f7d6 into mozilla:master May 22, 2017
@muffinresearch muffinresearch deleted the lint-for-missing-keys branch May 22, 2017 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fail early if keys are missing from an array of JSX elements
2 participants