Skip to content

Commit e8d2ce9

Browse files
odinhowKichljharbjzabala
committed
[Fix] prop-types: handle anonymous functions
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]>
1 parent e20522c commit e8d2ce9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/util/Components.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ function componentRule(rule, context) {
689689
getStatelessComponent(node) {
690690
if (
691691
node.type === 'FunctionDeclaration'
692-
&& isFirstLetterCapitalized(node.id.name)
692+
&& (!node.id || isFirstLetterCapitalized(node.id.name))
693693
&& utils.isReturningJSXOrNull(node)
694694
) {
695695
return node;

tests/lib/rules/prop-types.js

+15
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,11 @@ ruleTester.run('prop-types', rule, {
25692569
return null;
25702570
}`,
25712571
parser: parsers.TYPESCRIPT_ESLINT
2572+
},
2573+
{
2574+
code: `
2575+
export default function() {}
2576+
`
25722577
}
25732578
],
25742579

@@ -5161,6 +5166,16 @@ ruleTester.run('prop-types', rule, {
51615166
errors: [{
51625167
message: '\'value\' is missing in props validation'
51635168
}]
5169+
},
5170+
{
5171+
code: `
5172+
export default function ({ value = 'World' }) {
5173+
return <h1>Hello {value}</h1>
5174+
}
5175+
`,
5176+
errors: [{
5177+
message: '\'value\' is missing in props validation'
5178+
}]
51645179
}
51655180
]
51665181
});

0 commit comments

Comments
 (0)