Skip to content

Commit eda7e1d

Browse files
Add support for wrapped propTypes to prop-types
1 parent bb97fc8 commit eda7e1d

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

lib/rules/prop-types.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module.exports = {
5757
create: Components.detect(function(context, components, utils) {
5858
var sourceCode = context.getSourceCode();
5959
var configuration = context.options[0] || {};
60+
var propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
6061
var ignored = configuration.ignore || [];
6162
var customValidators = configuration.customValidators || [];
6263
var skipUndeclared = configuration.skipUndeclared || false;
@@ -769,6 +770,15 @@ module.exports = {
769770
}
770771
ignorePropsValidation = true;
771772
break;
773+
case 'CallExpression':
774+
if (
775+
propWrapperFunctions.has(propTypes.callee.name) &&
776+
propTypes.arguments && propTypes.arguments[0]
777+
) {
778+
markPropTypesAsDeclared(node, propTypes.arguments[0]);
779+
return;
780+
}
781+
break;
772782
case null:
773783
break;
774784
default:

tests/lib/rules/prop-types.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,26 @@ ruleTester.run('prop-types', rule, {
22082208
errors: [
22092209
{message: '\'lastname\' is missing in props validation'}
22102210
]
2211+
}, {
2212+
code: [
2213+
'class Test extends Foo.Component {',
2214+
' render() {',
2215+
' return (',
2216+
' <div>{this.props.firstname} {this.props.lastname}</div>',
2217+
' );',
2218+
' }',
2219+
'}',
2220+
'Test.propTypes = forbidExtraProps({',
2221+
' firstname: PropTypes.string',
2222+
'});'
2223+
].join('\n'),
2224+
parser: 'babel-eslint',
2225+
settings: Object.assign({}, settings, {
2226+
propWrapperFunctions: ['forbidExtraProps']
2227+
}),
2228+
errors: [
2229+
{message: '\'lastname\' is missing in props validation'}
2230+
]
22112231
}, {
22122232
code: [
22132233
'/** @jsx Foo */',
@@ -2689,6 +2709,29 @@ ruleTester.run('prop-types', rule, {
26892709
errors: [
26902710
{message: '\'foo\' is missing in props validation'}
26912711
]
2712+
}, {
2713+
code: [
2714+
'class Hello extends Component {',
2715+
' static propTypes = forbidExtraProps({',
2716+
' bar: PropTypes.func',
2717+
' })',
2718+
' componentWillReceiveProps(nextProps) {',
2719+
' if (nextProps.foo) {',
2720+
' return;',
2721+
' }',
2722+
' }',
2723+
' render() {',
2724+
' return <div bar={this.props.bar} />;',
2725+
' }',
2726+
'}'
2727+
].join('\n'),
2728+
parser: 'babel-eslint',
2729+
settings: Object.assign({}, settings, {
2730+
propWrapperFunctions: ['forbidExtraProps']
2731+
}),
2732+
errors: [
2733+
{message: '\'foo\' is missing in props validation'}
2734+
]
26922735
}, {
26932736
code: [
26942737
'class Hello extends Component {',

0 commit comments

Comments
 (0)