Skip to content

Commit 9325fa5

Browse files
committed
[Fix] propTypes, no-unused-prop-types: remove the fake node added in jsx-eslint#3064
Fixes jsx-eslint#3068
1 parent 952a768 commit 9325fa5

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/util/propTypes.js

-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,6 @@ module.exports = function propTypesInstructions(context, components, utils) {
764764
this.declaredPropTypes.children = {
765765
fullName: 'children',
766766
name: 'children',
767-
node: {},
768767
isRequired: false
769768
};
770769
}

lib/util/usedPropTypes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
454454
Object.keys(propTypes).forEach((key) => {
455455
const node = propTypes[key].node;
456456

457-
if (node.value && astUtil.isFunctionLikeExpression(node.value)) {
457+
if (node && node.value && astUtil.isFunctionLikeExpression(node.value)) {
458458
markPropTypesAsUsed(node.value);
459459
}
460460
});

tests/lib/rules/no-unused-prop-types.js

+16
Original file line numberDiff line numberDiff line change
@@ -3908,6 +3908,22 @@ ruleTester.run('no-unused-prop-types', rule, {
39083908
type StateProps = ReturnType<typeof mapStateToProps>
39093909
type DispatchProps = ReturnType<typeof mapDispatchToProps>`,
39103910
parser: parsers['@TYPESCRIPT_ESLINT']
3911+
},
3912+
{
3913+
code: [
3914+
'import React from "react";',
3915+
'',
3916+
'interface Props {',
3917+
' name: string;',
3918+
'}',
3919+
'',
3920+
'const MyComponent: React.FC<Props> = ({ name }) => {',
3921+
' return <div>{name}</div>;',
3922+
'};',
3923+
'',
3924+
'export default MyComponent;'
3925+
].join('\n'),
3926+
parser: parsers['@TYPESCRIPT_ESLINT']
39113927
}
39123928
])
39133929
),

0 commit comments

Comments
 (0)