Skip to content

Commit

Permalink
[Fix] component detection, display-name, no-this-in-sfc: fix fals…
Browse files Browse the repository at this point in the history
…e positive for HOF returning only nulls and literals
  • Loading branch information
golopot authored and ljharb committed Jun 1, 2022
1 parent c28ae9e commit 91e0922
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 54 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [`display-name`]: fix identifying `_` as a capital letter ([#3335][] @apbarrero)
* [`require-default-props`]: avoid a crash when function has no props param ([#3350][] @noahnu)
* [`display-name`], component detection: fix HOF returning null as Components ([#3347][] @jxm-math)
* component detection, [`display-name`], [`no-this-in-sfc`]: fix false positive for HOF returning only nulls and literals ([#3305][] @golopot)

### Changed
* [Refactor] [`jsx-indent-props`]: improved readability of the checkNodesIndent function ([#3315][] @caroline223)
Expand Down Expand Up @@ -47,6 +48,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
[#3315]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3315
[#3314]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3314
[#3311]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3311
[#3305]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3305
[#3262]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3262

## [7.30.1] - 2022.06.23
Expand Down
1 change: 0 additions & 1 deletion lib/util/Components.js
Expand Up @@ -503,7 +503,6 @@ function componentRule(rule, context) {
if (
(node.parent.type === 'ReturnStatement' || (node.parent.type === 'ArrowFunctionExpression' && node.parent.expression))
&& !utils.isReturningJSX(node)
&& !utils.isReturningOnlyNull(node)
) {
return undefined;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/display-name.js
Expand Up @@ -556,6 +556,17 @@ ruleTester.run('display-name', rule, {
}
`,
},
{
// issue #3300
code: `
const f = (a) => () => {
if (a) {
return null;
}
return 1;
};
`,
},
{
code: `
class Test {
Expand Down
53 changes: 0 additions & 53 deletions tests/lib/rules/no-this-in-sfc.js
Expand Up @@ -275,58 +275,5 @@ ruleTester.run('no-this-in-sfc', rule, {
{ messageId: 'noThisInSFC' },
],
},
{
code: `
class Foo {
bar() {
return () => {
this.something();
return null;
}
}
}
`,
errors: [{ messageId: 'noThisInSFC' }],
},
{
code: `
class Foo {
bar = () => () => {
this.something();
return null;
};
}
`,
features: ['class fields', 'no-ts-old'], // TODO: FIXME: remove `no-ts-old` and fix
errors: [{ messageId: 'noThisInSFC' }],
},
{
code: `
class Foo {
bar() {
function Bar(){
return () => {
this.something();
return null;
}
}
}
}
`,
errors: [{ messageId: 'noThisInSFC' }],
},
{
code: `
class Foo {
bar() {
() => () => {
this.something();
return null;
};
}
}
`,
errors: [{ messageId: 'noThisInSFC' }],
},
]),
});

0 comments on commit 91e0922

Please sign in to comment.