Skip to content

Commit

Permalink
Remove properties limitations on some prop types (fixes #139)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Croissant committed Jul 10, 2015
1 parent 6104472 commit a8f3a05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 61 deletions.
25 changes: 0 additions & 25 deletions lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,31 +295,6 @@ module.exports = function(context) {
return true;
}
}
if (
value.type === 'MemberExpression' &&
value.property &&
value.property.name
) {
var name = value.property.name;
// React propTypes with limited possible properties
var propertiesMap = {
array: Array.prototype,
bool: Boolean.prototype,
func: Function.prototype,
number: Number.prototype,
string: String.prototype
};
if (name in propertiesMap) {
return {
type: name,
children: {
__ANY_KEY__: {
acceptedProperties: propertiesMap[name]
}
}
};
}
}
// Unknown property or accepts everything (any, object, ...)
return true;
}
Expand Down
54 changes: 18 additions & 36 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,23 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
'};'
].join('\n'),
parser: 'babel-eslint'
}
],
}, {
code: [
'var Hello = React.createClass({',
' propTypes: {',
' router: React.PropTypes.func',
' },',
' render: function() {',
' var nextPath = this.props.router.getCurrentQuery().nextPath;',
' return <div>{nextPath}</div>;',
' }',
'});'
].join('\n'),
ecmaFeatures: {
classes: true,
jsx: true
}
}],

invalid: [
{
Expand Down Expand Up @@ -834,40 +849,7 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
},
errors: [
{message: '\'a.length\' is missing in props validation for Hello'},
{message: '\'a.b\' is missing in props validation for Hello'},
{message: '\'a.e.anyProp\' is missing in props validation for Hello'},
{message: '\'a.c.someThingElse\' is missing in props validation for Hello'}
]
}, {
code: [
'class Hello extends React.Component {',
' render() {',
' this.props.arr.toFixed();',
' this.props.bo.push();',
' this.props.fu.push();',
' this.props.numb.propX;',
' this.props.stri.tooString();',
' return <div>Hello</div>;',
' }',
'}',
'Hello.propTypes = {',
' arr: React.PropTypes.array,',
' bo: React.PropTypes.bool,',
' fu: React.PropTypes.func,',
' numb: React.PropTypes.number,',
' stri: React.PropTypes.string',
'};'
].join('\n'),
ecmaFeatures: {
classes: true,
jsx: true
},
errors: [
{message: '\'arr.toFixed\' is missing in props validation for Hello'},
{message: '\'bo.push\' is missing in props validation for Hello'},
{message: '\'fu.push\' is missing in props validation for Hello'},
{message: '\'numb.propX\' is missing in props validation for Hello'},
{message: '\'stri.tooString\' is missing in props validation for Hello'}
{message: '\'a.b\' is missing in props validation for Hello'}
]
}, {
code: [
Expand Down

0 comments on commit a8f3a05

Please sign in to comment.