Skip to content

fix #884 #914

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

Closed

Conversation

marcgrr
Copy link

@marcgrr marcgrr commented Oct 17, 2016

The most straightforward way of fixing #884 would be to add a third condition to isPropTypesUsage that checks if it's a nextProps or prevProps in a lifecycle method. If I did this, then I'd also have to add nextProps and prevProps to DIRECT_PROPS_REGEX. I didn't want to do that because it duplicates logic between DIRECT_PROPS_REGEX and isPropAttributeName.

So this PR removes the need for DIRECT_PROPS_REGEX.

The main idea is that before this PR, the MemberExpression callback caught direct access (props.foo) and ThisExpression access (this.props.foo) at different "levels" in the AST. This meant that getPropertyName had to have some logic to fix them up to be on the same level. I added a Identifer callback that catches direct access at the same level as MemberExpression catches ThisExpression access so that getPropertyName no longer needs that logic.

This change uncovered something that I think is a bug in Components.js that made one of the existing no-unused-prop-types tests start failing, so I fixed that too.

@@ -1277,6 +1277,9 @@ ruleTester.run('prop-types', rule, {
' return names.map((name) => {',
' return <div>{name}</div>;',
' });',
'}',
'Hello.propTypes = {',
' names: React.PropTypes.string',
Copy link
Member

Choose a reason for hiding this comment

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

Here Hello is not a component (it returns an Array, so no propTypes should be specified)

@modosc
Copy link

modosc commented Mar 1, 2017

any update here? would be happy to help out if needed.

@marcgrr
Copy link
Author

marcgrr commented Mar 1, 2017

Sorry, I never found the time to address the change requests and to see this through to merging. And I probably won't any time soon. If you want to completely take this over and see it through to merging, feel free!

@modosc
Copy link

modosc commented Mar 1, 2017

sure!

@marcgrr
Copy link
Author

marcgrr commented Mar 1, 2017

Is there something I can do to let you "take over" this PR? Or maybe should I close this one and let you open another one?

@modosc
Copy link

modosc commented Mar 1, 2017

yeah, that makes the most sense to me.

@marcgrr marcgrr closed this Mar 1, 2017
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