From 5118610f136a4de65daeda9500b4748b9c2017b3 Mon Sep 17 00:00:00 2001 From: TildaDares Date: Sat, 16 Jul 2022 09:14:11 +0100 Subject: [PATCH] add more test cases --- lib/rules/forbid-prop-types.js | 5 ++--- tests/lib/rules/forbid-prop-types.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/rules/forbid-prop-types.js b/lib/rules/forbid-prop-types.js index 5b5ad097e2..a1660125aa 100644 --- a/lib/rules/forbid-prop-types.js +++ b/lib/rules/forbid-prop-types.js @@ -66,11 +66,11 @@ module.exports = { function isPropTypesPackage(node) { return ( node.type === 'Identifier' - && node.name === propTypesPackageName + && (node.name === null || node.name === propTypesPackageName) ) || ( node.type === 'MemberExpression' && node.property.name === 'PropTypes' - && node.object.name === reactPackageName + && (node.object.name === null || node.object.name === reactPackageName) ); } @@ -218,7 +218,6 @@ module.exports = { node.callee.object && !isPropTypesPackage(node.callee.object) && !propsUtil.isPropTypesDeclaration(node.callee) - && node.callee.object.name !== 'PropTypes' ) { return; } diff --git a/tests/lib/rules/forbid-prop-types.js b/tests/lib/rules/forbid-prop-types.js index 23513db169..69549a49d6 100644 --- a/tests/lib/rules/forbid-prop-types.js +++ b/tests/lib/rules/forbid-prop-types.js @@ -654,6 +654,27 @@ ruleTester.run('forbid-prop-types', rule, { }) ) `, + }, + { + code: ` + import CustomPropTypes from "prop-types"; + class Component extends React.Component {}; + Component.propTypes = { + a: CustomPropTypes.shape({ + b: CustomPropTypes.String, + c: CustomPropTypes.number.isRequired, + }) + } + `, + }, + { + code: ` + import CustomReact from "react" + class Component extends React.Component {}; + Component.propTypes = { + b: CustomReact.PropTypes.string, + } + `, } )),