Skip to content

Commit fd7da3c

Browse files
committed
Fix invalid class property handling in jsx-sort-prop-types (fixes #129)
1 parent 338e530 commit fd7da3c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/rules/jsx-sort-prop-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module.exports = function(context) {
6565

6666
return {
6767
ClassProperty: function(node) {
68-
if (isPropTypesDeclaration(node) && node.value.type === 'ObjectExpression') {
68+
if (isPropTypesDeclaration(node) && node.value && node.value.type === 'ObjectExpression') {
6969
checkSorted(node.value.properties);
7070
}
7171
},

tests/lib/rules/jsx-sort-prop-types.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ eslintTester.addRuleTest('lib/rules/jsx-sort-prop-types', {
176176
args: [1, {
177177
ignoreCase: true
178178
}]
179+
}, {
180+
// Invalid code, should not be valided
181+
code: [
182+
'class Component extends React.Component {',
183+
' propTypes: {',
184+
' a: React.PropTypes.any,',
185+
' c: React.PropTypes.any,',
186+
' b: React.PropTypes.any',
187+
' }',
188+
' render() {',
189+
' return <div />;',
190+
' }',
191+
'}'
192+
].join('\n'),
193+
parser: 'babel-eslint'
179194
}
180195
],
181196

0 commit comments

Comments
 (0)