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

Support read-only props in Flow for no-unused-prop-types #1390

Merged

Conversation

jseminck
Copy link
Contributor

Fixes #1388

Added a more generic implementation that supports all prefixes, not just - and + like it was the case in the prop-types rule.

Additionally, made both rules implement the same logic. Although, as described in the other PR, the logic for detecting prop-types should really be extracted out to a separate file. I'd like to tackle that separately as well though.

@jseminck jseminck force-pushed the no-unused-prop-types-flow-read-only-v2 branch from 9944d30 to 2fcba06 Compare August 22, 2017 19:20
...SharedPropTypes // eslint-disable-line object-shorthand
};
`,
parser: 'babel-eslint'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reformatted this test - that's why it's in the PR...

* @param {string} the identifier to strip
*/
function stripQuotes(string) {
if (string[0] === '\'' || string[0] === '"' && string[0] === string[string.length - 1]) {
Copy link
Member

Choose a reason for hiding this comment

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

return string.replace(/^(["']).*($1)$/, '') or similar?

? tokens[1].value
: stripQuotes(tokens[0].value)
);
const tokens = context.getFirstTokens(node, {count: 1, filter: tokenNode => ['Identifier', 'String'].indexOf(tokenNode.type) >= 0});
Copy link
Member

Choose a reason for hiding this comment

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

why would we want to strip all prefixes? only + and - exist, as far as I know.

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 seems a much safer implementation for the future. If Flow would introduce a new prefix, it should be handled automatically. (assuming that the prefix token type is similar to the types it has now).

If you think keeping a list of prefixes is better then we can go with that approach as well...

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to have explicit support; I'd rather it not silently risk doing the wrong thing when an unanticipated prefix exists.

I definitely don't want the plugin to crash when a new prefix is found - but i might want it to warn on the prop.

@@ -333,10 +333,7 @@ module.exports = {
* @param {string} the identifier to strip
*/
function stripQuotes(string) {
Copy link
Member

Choose a reason for hiding this comment

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

can this repeated function be extracted out into a shared file?

Copy link
Contributor Author

@jseminck jseminck Aug 23, 2017

Choose a reason for hiding this comment

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

Yeah - that's what I mentioned in the other PR: prop-types and no-unused-prop-types on first sight seem to share quite a bit of logic that deals with extracting the declared prop types for a component. And currently, the logic is not in sync (e.g. props in TypedArgument for Flow is not supported at all for no-unused-prop-types.

I'll try to deal with extracting as much of the shared logic as possible this weekend. Created an issue: #1393

@yannickcr yannickcr merged commit 35eb3ce into jsx-eslint:master Sep 5, 2017
@jseminck jseminck deleted the no-unused-prop-types-flow-read-only-v2 branch November 19, 2017 07:53
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.

no-unused-prop-types fails on readonly flow types
3 participants