Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Added
* add [`no-namespace`] rule ([#2640] @yacinehmito @ljharb)

### Fixed
* [`display-name`]: Get rid of false position on component detection ([#2759] @iiison)

[#2640]: https://github.com/yannickcr/eslint-plugin-react/pull/2640
[#2759]: https://github.com/yannickcr/eslint-plugin-react/pull/2759

## [7.25.3] - 2021.09.19

Expand Down
3 changes: 2 additions & 1 deletion lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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 @@ -161,6 +161,7 @@ module.exports = {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
return;
}

if (components.get(node)) {
markDisplayNameAsDeclared(node);
}
Expand Down
27 changes: 27 additions & 0 deletions tests/lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,26 @@ ruleTester.run('display-name', rule, {
class Link extends Component<LinkProps> {}
`,
parser: parsers.BABEL_ESLINT
}, {
code: `
const x = {
title: "URL",
dataIndex: "url",
key: "url",
render: url => (
<a href={url} target="_blank" rel="noopener noreferrer">
<p>lol</p>
</a>
)
}
`,
parser: parsers.BABEL_ESLINT
}, {
code: `
const renderer = a => function Component(listItem) {
return <div>{a} {listItem}</div>;
};
`
}],

invalid: [{
Expand Down Expand Up @@ -921,5 +941,12 @@ ruleTester.run('display-name', rule, {
endLine: 11,
endColumn: 11
}]
}, {
code: `
const renderer = a => listItem => (
<div>{a} {listItem}</div>
);
`,
errors: [{message: 'Component definition is missing display name'}]
}]
});