-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[Fix] no-unused-prop-types
: false positive with callback
#2375
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
Conversation
lib/util/Components.js
Outdated
case 'AssignmentExpression': | ||
case 'Property': | ||
case 'ReturnStatement': | ||
case 'ExportDefaultDeclaration': { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These cases are
const Foo = () => <p />;
module.exports = function Foo() {};
module.exports = {
Foo() {},
};
function hof() {
return function Foo() {};
}
export default function Foo() {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add explicit test cases for each of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the tests cases for them are scattered in several rules, do you want a set of test cases centralized in, say, tests/rules/prop-types.js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'd probably be ideal for every rule that uses component detection to have all of these cases, tbh
The tests are broken by the merge of #2184, which added a test case: https://github.com/yannickcr/eslint-plugin-react/blob/7bc55ccb6ed2c32d381f09d2f43a77ca60afaae3/tests/lib/rules/no-multi-comp.js#L345-L349 Do we want to support components defined in comma operator? (IMO, no.) |
Yes, we should support components in any expression position. |
73bb36d
to
47e8640
Compare
Fixes #2350
This pr fixes
getParentStatelessComponent
when the current traversed node is like a callback (is a function and is an argument). The functiongetParentStatelessComponent
is revised to use a more whitelist-ish approach.Fixes false positive like: