Skip to content

Commit

Permalink
[Fix] display-name: fix false positive for HOF returning only nulls…
Browse files Browse the repository at this point in the history
… and literals
  • Loading branch information
golopot committed Aug 9, 2022
1 parent 6b330b8 commit 658b7d8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 82 deletions.
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
39 changes: 11 additions & 28 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 Expand Up @@ -1169,33 +1180,5 @@ ruleTester.run('display-name', rule, {
},
],
},
{
code: `
Demo = () => () => null;
`,
errors: [{ messageId: 'noDisplayName' }],
},
{
code: `
demo = {
Property: () => () => null
}
`,
errors: [{ messageId: 'noDisplayName' }],
},
{
code: `
Demo = function() {return function() {return null;};};
`,
errors: [{ messageId: 'noDisplayName' }],
},
{
code: `
demo = {
Property: function() {return function() {return null;};}
}
`,
errors: [{ messageId: 'noDisplayName' }],
},
]),
});
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 658b7d8

Please sign in to comment.