Skip to content

[Fix] display-name: fix false negative around nested functions #2225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/rules/display-name.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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'
}]
}]
});