diff --git a/lib/rules/prop-types.js b/lib/rules/prop-types.js index 7c10c71385..ed78afd07c 100644 --- a/lib/rules/prop-types.js +++ b/lib/rules/prop-types.js @@ -8,6 +8,7 @@ // https://github.com/yannickcr/eslint-plugin-react/issues/7 var Components = require('../util/Components'); +var variable = require('../util/variable'); // ------------------------------------------------------------------------------ // Rule Definition @@ -518,6 +519,18 @@ module.exports = Components.detect(function(context, components, utils) { buildReactDeclarationTypes(propTypes.parent.right); } break; + case 'Identifier': + var variablesInScope = variable.variablesInScope(context); + for (var i = 0, j = variablesInScope.length; i < j; i++) { + if (variablesInScope[i].name !== propTypes.name) { + continue; + } + var defInScope = variablesInScope[i].defs[variablesInScope[i].defs.length - 1]; + markPropTypesAsDeclared(node, defInScope.node && defInScope.node.init); + return; + } + ignorePropsValidation = true; + break; case null: break; default: diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index 746f1670fc..bb20dfe4ac 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -1408,6 +1408,24 @@ ruleTester.run('prop-types', rule, { errors: [ {message: '\'name\' is missing in props validation'} ] + }, { + code: [ + 'var propTypes = {', + ' firstname: React.PropTypes.string', + '};', + 'class Test extends React.Component {', + ' render() {', + ' return (', + '