Skip to content

Commit

Permalink
Fix no-unused-prop-types crash (fixes #825)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgueni Naverniouk authored and yannickcr committed Sep 14, 2016
1 parent cf3b220 commit a0e0e57
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-unused-prop-types.js
Expand Up @@ -619,7 +619,7 @@ module.exports = {
});
break;
case 'destructuring':
for (var k = 0, l = properties.length; k < l; k++) {
for (var k = 0, l = (properties || []).length; k < l; k++) {
if (hasSpreadOperator(properties[k]) || properties[k].computed) {
continue;
}
Expand Down
62 changes: 62 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Expand Up @@ -1382,6 +1382,33 @@ ruleTester.run('no-unused-prop-types', rule, {
].join('\n'),
parser: 'babel-eslint',
parserOptions: parserOptions
}, {
// Destructured state props in `componentDidUpdate` [Issue #825]
code: [
'class Hello extends Component {',
' static propTypes = {',
' something: PropTypes.bool',
' }',
' componentDidUpdate ({something}, {state1, state2}) {',
' return something;',
' }',
'}'
].join('\n'),
parser: 'babel-eslint',
parserOptions: parserOptions
}, {
// Destructured state props in `componentDidUpdate` without custom parser [Issue #825]
code: [
'var Hello = React.Component({',
' propTypes: {',
' something: PropTypes.bool',
' },',
' componentDidUpdate: function ({something}, {state1, state2}) {',
' return something;',
' }',
'});'
].join('\n'),
parserOptions: parserOptions
}
],

Expand Down Expand Up @@ -2337,6 +2364,41 @@ ruleTester.run('no-unused-prop-types', rule, {
line: 3,
column: 13
}]
}, {
code: [
'class Hello extends Component {',
' static propTypes = {',
' something: PropTypes.bool',
' }',
' componentDidUpdate (prevProps, {state1, state2}) {',
' return something;',
' }',
'}'
].join('\n'),
parser: 'babel-eslint',
parserOptions: parserOptions,
errors: [{
message: '\'something\' PropType is defined but prop is never used',
line: 3,
column: 16
}]
}, {
code: [
'var Hello = React.createClass({',
' propTypes: {',
' something: PropTypes.bool',
' },',
' componentDidUpdate: function (prevProps, {state1, state2}) {',
' return something;',
' }',
'})'
].join('\n'),
parserOptions: parserOptions,
errors: [{
message: '\'something\' PropType is defined but prop is never used',
line: 3,
column: 16
}]
}/* , {
// Enable this when the following issue is fixed
// https://github.com/yannickcr/eslint-plugin-react/issues/296
Expand Down

0 comments on commit a0e0e57

Please sign in to comment.