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

[Fix] prop-types: handle anonymous functions #2730

Merged
merged 1 commit into from Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/util/Components.js
Expand Up @@ -689,7 +689,7 @@ function componentRule(rule, context) {
getStatelessComponent(node) {
if (
node.type === 'FunctionDeclaration'
&& isFirstLetterCapitalized(node.id.name)
&& (!node.id || isFirstLetterCapitalized(node.id.name))
&& utils.isReturningJSXOrNull(node)
) {
return node;
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -2569,6 +2569,11 @@ ruleTester.run('prop-types', rule, {
return null;
}`,
parser: parsers.TYPESCRIPT_ESLINT
},
{
code: `
export default function() {}
`
}
],

Expand Down Expand Up @@ -5161,6 +5166,16 @@ ruleTester.run('prop-types', rule, {
errors: [{
message: '\'value\' is missing in props validation'
}]
},
{
code: `
export default function ({ value = 'World' }) {
return <h1>Hello {value}</h1>
}
`,
errors: [{
message: '\'value\' is missing in props validation'
}]
}
]
});