Skip to content

Commit

Permalink
Add support for wrapped propTypes to prop-types
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinsoftware committed Jun 25, 2017
1 parent bb97fc8 commit eda7e1d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = {
create: Components.detect(function(context, components, utils) {
var sourceCode = context.getSourceCode();
var configuration = context.options[0] || {};
var propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
var ignored = configuration.ignore || [];
var customValidators = configuration.customValidators || [];
var skipUndeclared = configuration.skipUndeclared || false;
Expand Down Expand Up @@ -769,6 +770,15 @@ module.exports = {
}
ignorePropsValidation = true;
break;
case 'CallExpression':
if (
propWrapperFunctions.has(propTypes.callee.name) &&
propTypes.arguments && propTypes.arguments[0]
) {
markPropTypesAsDeclared(node, propTypes.arguments[0]);
return;
}
break;
case null:
break;
default:
Expand Down
43 changes: 43 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,26 @@ ruleTester.run('prop-types', rule, {
errors: [
{message: '\'lastname\' is missing in props validation'}
]
}, {
code: [
'class Test extends Foo.Component {',
' render() {',
' return (',
' <div>{this.props.firstname} {this.props.lastname}</div>',
' );',
' }',
'}',
'Test.propTypes = forbidExtraProps({',
' firstname: PropTypes.string',
'});'
].join('\n'),
parser: 'babel-eslint',
settings: Object.assign({}, settings, {
propWrapperFunctions: ['forbidExtraProps']
}),
errors: [
{message: '\'lastname\' is missing in props validation'}
]
}, {
code: [
'/** @jsx Foo */',
Expand Down Expand Up @@ -2689,6 +2709,29 @@ ruleTester.run('prop-types', rule, {
errors: [
{message: '\'foo\' is missing in props validation'}
]
}, {
code: [
'class Hello extends Component {',
' static propTypes = forbidExtraProps({',
' bar: PropTypes.func',
' })',
' componentWillReceiveProps(nextProps) {',
' if (nextProps.foo) {',
' return;',
' }',
' }',
' render() {',
' return <div bar={this.props.bar} />;',
' }',
'}'
].join('\n'),
parser: 'babel-eslint',
settings: Object.assign({}, settings, {
propWrapperFunctions: ['forbidExtraProps']
}),
errors: [
{message: '\'foo\' is missing in props validation'}
]
}, {
code: [
'class Hello extends Component {',
Expand Down

0 comments on commit eda7e1d

Please sign in to comment.