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

Change the reporting for no-unused-prop-types #2292

Merged

Conversation

jseminck
Copy link
Contributor

@jseminck jseminck commented May 27, 2019

Fixes #2287

This change seems rather trivial, which made me wonder if there was ever a reason why it was not done this way? 🤔

The code used to report only on prop.node value, then it would report like this:

Screen Shot 2019-05-27 at 08 02 12

However, this logic was changed in this commit to report only on the node.value instead. But this commit doesn't really explain why and seems mostly about another rule instead. I'm thinking that it may have been done by accident?
2e4f91a

So now I question whether we should report back to the full node or change it to node.key.

Otherwise, I tried it out on a local project and seemed to work fine, all tests also continue to pass once the column context values were adjusted.

Before:
Screen Shot 2019-05-27 at 07 44 58

After:
Screen Shot 2019-05-27 at 07 44 42

@@ -104,7 +104,7 @@ module.exports = {

if (prop.node && !isPropUsed(component, prop)) {
context.report({
node: prop.node.value || prop.node,
node: prop.node.key || prop.node,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if the fallback to prop.node here is actually needed? If the fallback is used then it will report like this:

Screen Shot 2019-05-27 at 08 02 12

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it is for flow object type? It seems that babel-eslint does not provide key in ObjectTypeProperty nodes demo.

@ljharb
Copy link
Member

ljharb commented Dec 13, 2019

@jseminck it'd be great to add a test case that fails when the prop.node fallback is removed - that way we can be confident about keeping it or not :-)

@jseminck jseminck closed this Jan 6, 2020
@ljharb
Copy link
Member

ljharb commented Jan 6, 2020

@jseminck are you no longer interested in completing this PR?

@ljharb ljharb reopened this Jan 6, 2020
@golopot
Copy link
Contributor

golopot commented Feb 16, 2020

it'd be great to add a test case that fails when the prop.node fallback is removed - that way we can be confident about keeping it or not :-)

There are already 34+ test cases that will fail when prop.node fallback is removed. The prop.node fallback is needed for propTypes written with flow types.

This pr is ready to go after a rebase and fixing a test case from master.

@ljharb ljharb added the flow label Feb 17, 2020
@ljharb ljharb force-pushed the change-reporting-for-no-unused-prop-types branch 2 times, most recently from e2f4c2c to b833535 Compare February 17, 2020 20:58
@ljharb ljharb merged commit b833535 into jsx-eslint:master Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

no-unused-prop-types: change reported node to property key
3 participants