Skip to content

Commit a8f3a05

Browse files
author
Yannick Croissant
committed
Remove properties limitations on some prop types (fixes #139)
1 parent 6104472 commit a8f3a05

File tree

2 files changed

+18
-61
lines changed

2 files changed

+18
-61
lines changed

lib/rules/prop-types.js

-25
Original file line numberDiff line numberDiff line change
@@ -295,31 +295,6 @@ module.exports = function(context) {
295295
return true;
296296
}
297297
}
298-
if (
299-
value.type === 'MemberExpression' &&
300-
value.property &&
301-
value.property.name
302-
) {
303-
var name = value.property.name;
304-
// React propTypes with limited possible properties
305-
var propertiesMap = {
306-
array: Array.prototype,
307-
bool: Boolean.prototype,
308-
func: Function.prototype,
309-
number: Number.prototype,
310-
string: String.prototype
311-
};
312-
if (name in propertiesMap) {
313-
return {
314-
type: name,
315-
children: {
316-
__ANY_KEY__: {
317-
acceptedProperties: propertiesMap[name]
318-
}
319-
}
320-
};
321-
}
322-
}
323298
// Unknown property or accepts everything (any, object, ...)
324299
return true;
325300
}

tests/lib/rules/prop-types.js

+18-36
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,23 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
548548
'};'
549549
].join('\n'),
550550
parser: 'babel-eslint'
551-
}
552-
],
551+
}, {
552+
code: [
553+
'var Hello = React.createClass({',
554+
' propTypes: {',
555+
' router: React.PropTypes.func',
556+
' },',
557+
' render: function() {',
558+
' var nextPath = this.props.router.getCurrentQuery().nextPath;',
559+
' return <div>{nextPath}</div>;',
560+
' }',
561+
'});'
562+
].join('\n'),
563+
ecmaFeatures: {
564+
classes: true,
565+
jsx: true
566+
}
567+
}],
553568

554569
invalid: [
555570
{
@@ -834,40 +849,7 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
834849
},
835850
errors: [
836851
{message: '\'a.length\' is missing in props validation for Hello'},
837-
{message: '\'a.b\' is missing in props validation for Hello'},
838-
{message: '\'a.e.anyProp\' is missing in props validation for Hello'},
839-
{message: '\'a.c.someThingElse\' is missing in props validation for Hello'}
840-
]
841-
}, {
842-
code: [
843-
'class Hello extends React.Component {',
844-
' render() {',
845-
' this.props.arr.toFixed();',
846-
' this.props.bo.push();',
847-
' this.props.fu.push();',
848-
' this.props.numb.propX;',
849-
' this.props.stri.tooString();',
850-
' return <div>Hello</div>;',
851-
' }',
852-
'}',
853-
'Hello.propTypes = {',
854-
' arr: React.PropTypes.array,',
855-
' bo: React.PropTypes.bool,',
856-
' fu: React.PropTypes.func,',
857-
' numb: React.PropTypes.number,',
858-
' stri: React.PropTypes.string',
859-
'};'
860-
].join('\n'),
861-
ecmaFeatures: {
862-
classes: true,
863-
jsx: true
864-
},
865-
errors: [
866-
{message: '\'arr.toFixed\' is missing in props validation for Hello'},
867-
{message: '\'bo.push\' is missing in props validation for Hello'},
868-
{message: '\'fu.push\' is missing in props validation for Hello'},
869-
{message: '\'numb.propX\' is missing in props validation for Hello'},
870-
{message: '\'stri.tooString\' is missing in props validation for Hello'}
852+
{message: '\'a.b\' is missing in props validation for Hello'}
871853
]
872854
}, {
873855
code: [

0 commit comments

Comments
 (0)