-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[Fix] prop-types
: handle anonymous functions
#2730
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
Fixes #2728. Co-authored-by: Odin Hørthe Omdal <[email protected]> Co-authored-by: Dmitriy Lazarev <[email protected]> Co-authored-by: Jordan Harband <[email protected]> Co-authored-by: Johnny Zabala <[email protected]>
I'm no expert in eslint, but is the check actually correct? I think an anonymous function could also be considered to be a stateless component. I was thinking of something like if (
node.type === 'FunctionDeclaration'
&& (node.id == null || isFirstLetterCapitalized(node.id.name))
&& utils.isReturningJSXOrNull(node)
) { |
As I read it, the code underneath will handle that case. It checks the variable that the anonymous function is being stored into. |
Thanks! This does need a regression test first. |
@odinho Since you made this PR from a fork that you don't own (whereby instead of odinho) I can't merge this yet. Can you please add me to https://github.com/whereby/eslint-plugin-react so I can force push to the PR branch? |
prop-types
: handle anonymous functions
Oup. Why do I keep forgetting that this restriction exists. I've added you now 🤦 |
This indeed will solve #2728 but then components defined this way won't be recognized: export default function () {
return <h1>Hello World</div>
} I think a better check would be: if (
node.type === 'FunctionDeclaration'
&& (!node.id || isFirstLetterCapitalized(node.id.name)) // skip first letter check if the node.id doesn't exists
&& utils.isReturningJSXOrNull(node)
) { |
@jzabala thanks, i've added a test case and your suggested fix. |
Fixes #2728.