Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,14 @@ function componentRule(rule, context) {
var isFunction = /Function/.test(node.type); // Functions
var isMethod = node.parent && node.parent.type === 'MethodDefinition'; // Classes methods
var isArgument = node.parent && node.parent.type === 'CallExpression'; // Arguments (callback, etc.)
// Attribute Expressions inside JSX Elements (<button onClick={() => props.handleClick()}></button>)
var isJSXExpressionContainer = node.parent && node.parent.type === 'JSXExpressionContainer';
// Stop moving up if we reach a class or an argument (like a callback)
if (isClass || isArgument) {
return null;
}
// Return the node if it is a function that is not a class method
if (isFunction && !isMethod) {
// Return the node if it is a function that is not a class method and is not inside a JSX Element
if (isFunction && !isMethod && !isJSXExpressionContainer) {
return node;
}
scope = scope.upper;
Expand Down
33 changes: 33 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,39 @@ ruleTester.run('no-unused-prop-types', rule, {
'};'
].join('\n'),
parserOptions: parserOptions
}, {
// `no-unused-prop-types` in jsx expressions - [Issue #885]
code: [
'const PagingBlock = function(props) {',
' return (',
' <span>',
' <a onClick={() => props.previousPage()}/>',
' <a onClick={() => props.nextPage()}/>',
' </span>',
' );',
'};',

'PagingBlock.propTypes = {',
' nextPage: React.PropTypes.func.isRequired,',
' previousPage: React.PropTypes.func.isRequired,',
'};'
].join('\n'),
parserOptions: parserOptions
}, {
// `no-unused-prop-types` rest param props in jsx expressions - [Issue #885]
code: [
'const PagingBlock = function(props) {',
' return (',
' <SomeChild {...props} />',
' );',
'};',

'PagingBlock.propTypes = {',
' nextPage: React.PropTypes.func.isRequired,',
' previousPage: React.PropTypes.func.isRequired,',
'};'
].join('\n'),
parserOptions: parserOptions
}
],

Expand Down