Skip to content

Commit 35de81b

Browse files
authored
Merge pull request jsx-eslint#2225 from dwelle/display_name_nested
[Fix] `display-name`: fix false negative around nested functions
2 parents 91c38fa + 8b1a64f commit 35de81b

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

lib/rules/display-name.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,27 @@ module.exports = {
160160
if (ignoreTranspilerName || !hasTranspilerName(node)) {
161161
return;
162162
}
163-
markDisplayNameAsDeclared(node);
163+
if (components.get(node)) {
164+
markDisplayNameAsDeclared(node);
165+
}
164166
},
165167

166168
FunctionDeclaration: function(node) {
167169
if (ignoreTranspilerName || !hasTranspilerName(node)) {
168170
return;
169171
}
170-
markDisplayNameAsDeclared(node);
172+
if (components.get(node)) {
173+
markDisplayNameAsDeclared(node);
174+
}
171175
},
172176

173177
ArrowFunctionExpression: function(node) {
174178
if (ignoreTranspilerName || !hasTranspilerName(node)) {
175179
return;
176180
}
177-
markDisplayNameAsDeclared(node);
181+
if (components.get(node)) {
182+
markDisplayNameAsDeclared(node);
183+
}
178184
},
179185

180186
MethodDefinition: function(node) {

tests/lib/rules/display-name.js

+60
Original file line numberDiff line numberDiff line change
@@ -693,5 +693,65 @@ ruleTester.run('display-name', rule, {
693693
errors: [{
694694
message: 'Component definition is missing display name'
695695
}]
696+
}, {
697+
code: `
698+
module.exports = function () {
699+
function a () {}
700+
const b = function b () {}
701+
const c = function () {}
702+
const d = () => {}
703+
const obj = {
704+
a: function a () {},
705+
b: function b () {},
706+
c () {},
707+
d: () => {},
708+
}
709+
return React.createElement("div", {}, "text content");
710+
}
711+
`,
712+
errors: [{
713+
message: 'Component definition is missing display name'
714+
}]
715+
}, {
716+
code: `
717+
module.exports = () => {
718+
function a () {}
719+
const b = function b () {}
720+
const c = function () {}
721+
const d = () => {}
722+
const obj = {
723+
a: function a () {},
724+
b: function b () {},
725+
c () {},
726+
d: () => {},
727+
}
728+
729+
return React.createElement("div", {}, "text content");
730+
}
731+
`,
732+
errors: [{
733+
message: 'Component definition is missing display name'
734+
}]
735+
}, {
736+
code: `
737+
export default class extends React.Component {
738+
render() {
739+
function a () {}
740+
const b = function b () {}
741+
const c = function () {}
742+
const d = () => {}
743+
const obj = {
744+
a: function a () {},
745+
b: function b () {},
746+
c () {},
747+
d: () => {},
748+
}
749+
return <div>Hello {this.props.name}</div>;
750+
}
751+
}
752+
`,
753+
errors: [{
754+
message: 'Component definition is missing display name'
755+
}]
696756
}]
697757
});

0 commit comments

Comments
 (0)