Skip to content

Commit 658b7d8

Browse files
committed
[Fix] display-name: fix false positive for HOF returning only nulls and literals
1 parent 6b330b8 commit 658b7d8

File tree

3 files changed

+11
-82
lines changed

3 files changed

+11
-82
lines changed

lib/util/Components.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ function componentRule(rule, context) {
503503
if (
504504
(node.parent.type === 'ReturnStatement' || (node.parent.type === 'ArrowFunctionExpression' && node.parent.expression))
505505
&& !utils.isReturningJSX(node)
506-
&& !utils.isReturningOnlyNull(node)
507506
) {
508507
return undefined;
509508
}

tests/lib/rules/display-name.js

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,17 @@ ruleTester.run('display-name', rule, {
556556
}
557557
`,
558558
},
559+
{
560+
// issue #3300
561+
code: `
562+
const f = (a) => () => {
563+
if (a) {
564+
return null;
565+
}
566+
return 1;
567+
};
568+
`,
569+
},
559570
{
560571
code: `
561572
class Test {
@@ -1169,33 +1180,5 @@ ruleTester.run('display-name', rule, {
11691180
},
11701181
],
11711182
},
1172-
{
1173-
code: `
1174-
Demo = () => () => null;
1175-
`,
1176-
errors: [{ messageId: 'noDisplayName' }],
1177-
},
1178-
{
1179-
code: `
1180-
demo = {
1181-
Property: () => () => null
1182-
}
1183-
`,
1184-
errors: [{ messageId: 'noDisplayName' }],
1185-
},
1186-
{
1187-
code: `
1188-
Demo = function() {return function() {return null;};};
1189-
`,
1190-
errors: [{ messageId: 'noDisplayName' }],
1191-
},
1192-
{
1193-
code: `
1194-
demo = {
1195-
Property: function() {return function() {return null;};}
1196-
}
1197-
`,
1198-
errors: [{ messageId: 'noDisplayName' }],
1199-
},
12001183
]),
12011184
});

tests/lib/rules/no-this-in-sfc.js

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -275,58 +275,5 @@ ruleTester.run('no-this-in-sfc', rule, {
275275
{ messageId: 'noThisInSFC' },
276276
],
277277
},
278-
{
279-
code: `
280-
class Foo {
281-
bar() {
282-
return () => {
283-
this.something();
284-
return null;
285-
}
286-
}
287-
}
288-
`,
289-
errors: [{ messageId: 'noThisInSFC' }],
290-
},
291-
{
292-
code: `
293-
class Foo {
294-
bar = () => () => {
295-
this.something();
296-
return null;
297-
};
298-
}
299-
`,
300-
features: ['class fields', 'no-ts-old'], // TODO: FIXME: remove `no-ts-old` and fix
301-
errors: [{ messageId: 'noThisInSFC' }],
302-
},
303-
{
304-
code: `
305-
class Foo {
306-
bar() {
307-
function Bar(){
308-
return () => {
309-
this.something();
310-
return null;
311-
}
312-
}
313-
}
314-
}
315-
`,
316-
errors: [{ messageId: 'noThisInSFC' }],
317-
},
318-
{
319-
code: `
320-
class Foo {
321-
bar() {
322-
() => () => {
323-
this.something();
324-
return null;
325-
};
326-
}
327-
}
328-
`,
329-
errors: [{ messageId: 'noThisInSFC' }],
330-
},
331278
]),
332279
});

0 commit comments

Comments
 (0)