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 prop-types desctructuring with properties as string. #124

Merged
merged 1 commit into from
Jun 19, 2015

Conversation

Cellule
Copy link
Contributor

@Cellule Cellule commented Jun 19, 2015

Fixes #118
I saw that destructuring were not correctly detected when the first key was a string and also those were not handled properly.

' render() {',
' var { ',
' propX,',
' "aria-controls": ariaControls, ',
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 😄

@AlexKVal
Copy link
Contributor

It works. Very nice ! 👍 🎉 🌈
Thank you 🍒

return key.name;
}
return key.value;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why not

return (key.type === 'Identifier') ? key.name : key.value;

here https://github.com/yannickcr/eslint-plugin-react/pull/123/files#diff-6149d4075a6f3125f18ce8c87bb253cbR39 you've done it like that:

return node.key.type === 'Identifier' ? node.key.name : node.key.value;

Of course it is just a matter of taste 🍒

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The difference is that in jsx-sort-prop-types it only checks the propTypes declaration and not its uses.
I was thinking (though I didn't implement it yet) that when checking the uses, you could have the case const aria = this.props["aria-controls"];. Right now, this is ignored by the rule because it's a "computed" property. However, I could easily inspect that property, realize it's a literal string value and add the check (there are other implications which is why I haven't done it yet, mostly with case this.props["some.thing"] and name.split(".") in the rule).
Therefore, I left it with that structure to make it easy to add more checks.
Note that it's possible, but make no sense to do propType: {["aria-controls"]: React.PropTypes.string}; So they are deliberately ignored in the other rule.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, there is really a lot of different ways to declare/use propTypes, it become hard to check all of them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the explanation 🍒 😃

yannickcr added a commit that referenced this pull request Jun 19, 2015
Fix `prop-types` desctructuring with properties as string (fixes #118)
@yannickcr yannickcr merged commit 9583f81 into jsx-eslint:master Jun 19, 2015
@yannickcr
Copy link
Member

Awesome! Thanks!

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.

3 participants