diff --git a/lib/rules/display-name.js b/lib/rules/display-name.js index 647420b046..f2abb00f24 100644 --- a/lib/rules/display-name.js +++ b/lib/rules/display-name.js @@ -24,23 +24,25 @@ module.exports = Components.detect(function(context, components, utils) { * @returns {Boolean} True if we are declaring a display name, false if not. */ function isDisplayNameDeclaration(node) { - // Special case for class properties - // (babel-eslint does not expose property name so we have to rely on tokens) - if (node.type === 'ClassProperty') { - var tokens = sourceCode.getFirstTokens(node, 2); - if ( - tokens[0].value === 'displayName' || - (tokens[1] && tokens[1].value === 'displayName') - ) { - return true; - } - return false; + switch (node.type) { + // Special case for class properties + // (babel-eslint does not expose property name so we have to rely on tokens) + case 'ClassProperty': + var tokens = sourceCode.getFirstTokens(node, 2); + if ( + tokens[0].value === 'displayName' || + (tokens[1] && tokens[1].value === 'displayName') + ) { + return true; + } + return false; + case 'Identifier': + return node.name === 'displayName'; + case 'Literal': + return node.value === 'displayName'; + default: + return false; } - - return Boolean( - node && - node.name === 'displayName' - ); } /** diff --git a/tests/lib/rules/display-name.js b/tests/lib/rules/display-name.js index f2fa89f7fa..1d83108808 100644 --- a/tests/lib/rules/display-name.js +++ b/tests/lib/rules/display-name.js @@ -153,6 +153,16 @@ ruleTester.run('display-name', rule, { '});' ].join('\n'), parserOptions: parserOptions + }, { + code: [ + 'module.exports = React.createClass({', + ' "displayName": "Hello",', + ' "render": function() {', + ' return
Hello {this.props.name}
;', + ' }', + '});' + ].join('\n'), + parserOptions: parserOptions }, { code: [ 'var Hello = React.createClass({',