Skip to content

Commit

Permalink
[Fix] display-name: fix false negative around nested functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelle committed Apr 3, 2019
1 parent 6bb1604 commit 4e362bc
Show file tree
Hide file tree
Showing 2 changed files with 53 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
44 changes: 44 additions & 0 deletions tests/lib/rules/display-name.js
Expand Up @@ -693,5 +693,49 @@ 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'
}]
}]
});

0 comments on commit 4e362bc

Please sign in to comment.