Skip to content

Commit 4e362bc

Browse files
committed
[Fix] display-name: fix false negative around nested functions
1 parent 6bb1604 commit 4e362bc

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-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

+44
Original file line numberDiff line numberDiff line change
@@ -693,5 +693,49 @@ ruleTester.run('display-name', rule, {
693693
errors: [{
694694
message: 'Component definition is missing display name'
695695
}]
696+
}, {
697+
code: `
698+
module.exports = function () {
699+
700+
function a () {}
701+
const b = function b () {}
702+
const c = function () {}
703+
const d = () => {}
704+
705+
const obj = {
706+
a: function a () {},
707+
b: function b () {},
708+
c () {},
709+
d: () => {},
710+
}
711+
712+
return React.createElement("div", {}, "text content");
713+
}
714+
`,
715+
errors: [{
716+
message: 'Component definition is missing display name'
717+
}]
718+
}, {
719+
code: `
720+
module.exports = () => {
721+
722+
function a () {}
723+
const b = function b () {}
724+
const c = function () {}
725+
const d = () => {}
726+
727+
const obj = {
728+
a: function a () {},
729+
b: function b () {},
730+
c () {},
731+
d: () => {},
732+
}
733+
734+
return React.createElement("div", {}, "text content");
735+
}
736+
`,
737+
errors: [{
738+
message: 'Component definition is missing display name'
739+
}]
696740
}]
697741
});

0 commit comments

Comments
 (0)