Skip to content

Commit

Permalink
Fix display-name when JSON style is used for defining components (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gitim authored and yannickcr committed May 17, 2016
1 parent 750f979 commit 82b3aa9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
34 changes: 18 additions & 16 deletions lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ ruleTester.run('display-name', rule, {
'});'
].join('\n'),
parserOptions: parserOptions
}, {
code: [
'module.exports = React.createClass({',
' "displayName": "Hello",',
' "render": function() {',
' return <div>Hello {this.props.name}</div>;',
' }',
'});'
].join('\n'),
parserOptions: parserOptions
}, {
code: [
'var Hello = React.createClass({',
Expand Down

0 comments on commit 82b3aa9

Please sign in to comment.