diff --git a/lib/rules/jsx-sort-prop-types.js b/lib/rules/jsx-sort-prop-types.js index a9e06fabd7..8dd0758acb 100644 --- a/lib/rules/jsx-sort-prop-types.js +++ b/lib/rules/jsx-sort-prop-types.js @@ -40,7 +40,7 @@ module.exports = function(context) { } function getValueName(node) { - return node.value.property.name; + return node.value.property && node.value.property.name; } function isCallbackPropName(propName) { diff --git a/tests/lib/rules/jsx-sort-prop-types.js b/tests/lib/rules/jsx-sort-prop-types.js index 40978fec35..b718dee589 100644 --- a/tests/lib/rules/jsx-sort-prop-types.js +++ b/tests/lib/rules/jsx-sort-prop-types.js @@ -276,6 +276,21 @@ ruleTester.run('jsx-sort-prop-types', rule, { requiredFirst: true }], parserOptions: parserOptions + }, { + code: [ + 'class First extends React.Component {', + ' render() {', + ' return
;', + ' }', + '}', + 'First.propTypes = {', + ' fooRequired: MyPropType,', + '};' + ].join('\n'), + options: [{ + requiredFirst: true + }], + parserOptions: parserOptions }, { code: [ 'class First extends React.Component {',