Skip to content

Commit

Permalink
[FIX] display-name: Get rid of false position on component detection
Browse files Browse the repository at this point in the history
fixes #2751
  • Loading branch information
iiison committed Aug 15, 2020
1 parent f55ecaa commit 5fc6de8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module.exports = {
const namedFunctionExpression = (
astUtil.isFunctionLikeExpression(node)
&& node.parent
&& (node.parent.type === 'VariableDeclarator' || node.parent.method === true)
&& (node.parent.type === 'VariableDeclarator' || node.parent.type === 'Property' || node.parent.method === true)
&& (!node.parent.parent || !utils.isES5Component(node.parent.parent))
);

Expand Down Expand Up @@ -159,15 +159,10 @@ module.exports = {
},

ArrowFunctionExpression(node) {
/* eslint-disable */
console.log('*******************')
console.log(node)
console.log('*******************')
/* elsint-enable */

if (ignoreTranspilerName || !hasTranspilerName(node)) {
return;
}

if (components.get(node)) {
markDisplayNameAsDeclared(node);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,5 +908,21 @@ ruleTester.run('display-name', rule, {
errors: [{
message: 'Component definition is missing display name'
}]
}, {
code: `
const x = {
title: "URL",
dataIndex: "url",
key: "url",
render: url => (
<a href={url} target="_blank" rel="noopener noreferrer">
<p>lol</p>
</a>
)
}
`,
options: [{ignoreTranspilerName: true}],
parser: parsers.BABEL_ESLINT,
errors: [{message: 'Component definition is missing display name'}]
}]
});

0 comments on commit 5fc6de8

Please sign in to comment.