Skip to content

Commit

Permalink
[Fix] propTypes, no-unused-prop-types: remove the fake node add…
Browse files Browse the repository at this point in the history
…ed in #3064

Fixes #3068
  • Loading branch information
ljharb committed Sep 5, 2021
1 parent 952a768 commit 9325fa5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/util/propTypes.js
Expand Up @@ -764,7 +764,6 @@ module.exports = function propTypesInstructions(context, components, utils) {
this.declaredPropTypes.children = {
fullName: 'children',
name: 'children',
node: {},
isRequired: false
};
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/usedPropTypes.js
Expand Up @@ -454,7 +454,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
Object.keys(propTypes).forEach((key) => {
const node = propTypes[key].node;

if (node.value && astUtil.isFunctionLikeExpression(node.value)) {
if (node && node.value && astUtil.isFunctionLikeExpression(node.value)) {
markPropTypesAsUsed(node.value);
}
});
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Expand Up @@ -3908,6 +3908,22 @@ ruleTester.run('no-unused-prop-types', rule, {
type StateProps = ReturnType<typeof mapStateToProps>
type DispatchProps = ReturnType<typeof mapDispatchToProps>`,
parser: parsers['@TYPESCRIPT_ESLINT']
},
{
code: [
'import React from "react";',
'',
'interface Props {',
' name: string;',
'}',
'',
'const MyComponent: React.FC<Props> = ({ name }) => {',
' return <div>{name}</div>;',
'};',
'',
'export default MyComponent;'
].join('\n'),
parser: parsers['@TYPESCRIPT_ESLINT']
}
])
),
Expand Down

0 comments on commit 9325fa5

Please sign in to comment.