Skip to content

Commit 98718a3

Browse files
author
Yannick Croissant
committed
Fix quoted propTypes in ES6 (fixes #77)
1 parent c59a6d8 commit 98718a3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/rules/prop-types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ module.exports = function(context) {
165165
switch (propTypes.type) {
166166
case 'ObjectExpression':
167167
for (var i = 0, j = propTypes.properties.length; i < j; i++) {
168-
declaredPropTypes.push(propTypes.properties[i].key.name);
168+
var key = propTypes.properties[i].key;
169+
declaredPropTypes.push(key.type === 'Identifier' ? key.name : key.value);
169170
}
170171
break;
171172
case 'MemberExpression':

tests/lib/rules/prop-types.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
220220
destructuring: true,
221221
jsx: true
222222
}
223+
}, {
224+
code: [
225+
'class Hello extends React.Component {',
226+
' render() {',
227+
' return <div>Hello {this.props.firstname}</div>;',
228+
' }',
229+
'}',
230+
'Hello.propTypes = {',
231+
' \'firstname\': React.PropTypes.string',
232+
'};'
233+
].join('\n'),
234+
ecmaFeatures: {
235+
classes: true,
236+
jsx: true
237+
}
223238
}
224239
],
225240

0 commit comments

Comments
 (0)