Skip to content

Commit

Permalink
add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
TildaDares committed Jul 16, 2022
1 parent f274112 commit 5118610
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand Down Expand Up @@ -218,7 +218,6 @@ module.exports = {
node.callee.object
&& !isPropTypesPackage(node.callee.object)
&& !propsUtil.isPropTypesDeclaration(node.callee)
&& node.callee.object.name !== 'PropTypes'
) {
return;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
`,
}
)),

Expand Down

0 comments on commit 5118610

Please sign in to comment.