Skip to content

Commit

Permalink
Merge pull request #2225 from dwelle/display_name_nested
Browse files Browse the repository at this point in the history
[Fix] `display-name`: fix false negative around nested functions
  • Loading branch information
ljharb committed Apr 3, 2019
2 parents 91c38fa + 8b1a64f commit 35de81b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/rules/display-name.js
Expand Up @@ -160,21 +160,27 @@ module.exports = {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
return;
}
markDisplayNameAsDeclared(node);
if (components.get(node)) {
markDisplayNameAsDeclared(node);
}
},

FunctionDeclaration: function(node) {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
return;
}
markDisplayNameAsDeclared(node);
if (components.get(node)) {
markDisplayNameAsDeclared(node);
}
},

ArrowFunctionExpression: function(node) {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
return;
}
markDisplayNameAsDeclared(node);
if (components.get(node)) {
markDisplayNameAsDeclared(node);
}
},

MethodDefinition: function(node) {
Expand Down
60 changes: 60 additions & 0 deletions tests/lib/rules/display-name.js
Expand Up @@ -693,5 +693,65 @@ ruleTester.run('display-name', rule, {
errors: [{
message: 'Component definition is missing display name'
}]
}, {
code: `
module.exports = function () {
function a () {}
const b = function b () {}
const c = function () {}
const d = () => {}
const obj = {
a: function a () {},
b: function b () {},
c () {},
d: () => {},
}
return React.createElement("div", {}, "text content");
}
`,
errors: [{
message: 'Component definition is missing display name'
}]
}, {
code: `
module.exports = () => {
function a () {}
const b = function b () {}
const c = function () {}
const d = () => {}
const obj = {
a: function a () {},
b: function b () {},
c () {},
d: () => {},
}
return React.createElement("div", {}, "text content");
}
`,
errors: [{
message: 'Component definition is missing display name'
}]
}, {
code: `
export default class extends React.Component {
render() {
function a () {}
const b = function b () {}
const c = function () {}
const d = () => {}
const obj = {
a: function a () {},
b: function b () {},
c () {},
d: () => {},
}
return <div>Hello {this.props.name}</div>;
}
}
`,
errors: [{
message: 'Component definition is missing display name'
}]
}]
});

0 comments on commit 35de81b

Please sign in to comment.