diff --git a/lib/util/usedPropTypes.js b/lib/util/usedPropTypes.js index ffd67c441a..7c5477716c 100644 --- a/lib/util/usedPropTypes.js +++ b/lib/util/usedPropTypes.js @@ -285,13 +285,14 @@ module.exports = function usedPropTypesInstructions(context, components, utils) * @returns {Boolean} True if we are using a prop, false if not. */ function isPropTypesUsage(node) { + const isThisPropsUsage = node.object.type === 'ThisExpression' && node.property.name === 'props'; + const isPropsUsage = isThisPropsUsage || node.object.name === 'nextProps' || node.object.name === 'prevProps'; const isClassUsage = ( (utils.getParentES6Component() || utils.getParentES5Component()) && - ((node.object.type === 'ThisExpression' && node.property.name === 'props') - || isPropArgumentInSetStateUpdater(node)) + (isThisPropsUsage || isPropArgumentInSetStateUpdater(node)) ); const isStatelessFunctionUsage = node.object.name === 'props' && !isAssignmentToProp(node); - return isClassUsage || isStatelessFunctionUsage || inLifeCycleMethod(); + return isClassUsage || isStatelessFunctionUsage || (isPropsUsage && inLifeCycleMethod()); } /** diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index 13c270c785..32c601f9ce 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -2170,6 +2170,83 @@ ruleTester.run('prop-types', rule, { pragma: 'Foo' } } + }, + { + code: ` + class Foo extends React.Component { + propTypes = { + actions: PropTypes.object.isRequired, + }; + componentWillReceiveProps (nextProps) { + this.props.actions.doSomething(); + } + + componentWillUnmount () { + this.props.actions.doSomething(); + } + + render() { + return