Skip to content

Commit

Permalink
[Fix] prop-types: handle anonymous functions
Browse files Browse the repository at this point in the history
Fixes #2728.

Co-authored-by: Odin Hørthe Omdal <odin.omdal@gmail.com>
Co-authored-by: Dmitriy Lazarev <w@kich.dev>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Johnny Zabala <jzabala.s@gmail.com>
  • Loading branch information
4 people committed Jul 27, 2020
1 parent e20522c commit e8d2ce9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/util/Components.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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'
}]
}
]
});

0 comments on commit e8d2ce9

Please sign in to comment.