diff --git a/lib/rules/no-typos.js b/lib/rules/no-typos.js index 98a161eac0..5720503736 100644 --- a/lib/rules/no-typos.js +++ b/lib/rules/no-typos.js @@ -73,7 +73,7 @@ module.exports = { } function checkValidPropObject (node) { - if (node.type === 'ObjectExpression') { + if (node && node.type === 'ObjectExpression') { node.properties.forEach(prop => checkValidProp(prop.value)); } } diff --git a/tests/lib/rules/no-typos.js b/tests/lib/rules/no-typos.js index 8fd5eb53f1..3a4ab31c1f 100644 --- a/tests/lib/rules/no-typos.js +++ b/tests/lib/rules/no-typos.js @@ -174,7 +174,7 @@ ruleTester.run('no-typos', rule, { const contextTypes = "CONTEXTTYPES" const childContextTypes = "CHILDCONTEXTTYPES" const defautProps = "DEFAULTPROPS" - + class First extends React.Component {} First[propTypes] = {}; First[contextTypes] = {}; @@ -338,6 +338,29 @@ ruleTester.run('no-typos', rule, { `, parser: 'babel-eslint', parserOptions: parserOptions + }, { + // ensure that an absent arg to PropTypes.shape does not crash + code: `class Component extends React.Component {}; + Component.propTypes = { + a: PropTypes.shape(), + }; + Component.contextTypes = { + a: PropTypes.shape(), + }; + `, + parserOptions: parserOptions + }, { + // ensure that an absent arg to PropTypes.shape does not crash + code: `class Component extends React.Component {}; + Component.propTypes = { + a: PropTypes.shape(), + }; + Component.contextTypes = { + a: PropTypes.shape(), + }; + `, + parser: 'babel-eslint', + parserOptions: parserOptions }, { code: ` const fn = (err, res) => {