Skip to content

Commit 513cdf9

Browse files
committed
fix(display-name): optimize shadowing test cases
1 parent 48491b9 commit 513cdf9

File tree

1 file changed

+32
-234
lines changed

1 file changed

+32
-234
lines changed

tests/lib/rules/display-name.js

Lines changed: 32 additions & 234 deletions
Original file line numberDiff line numberDiff line change
@@ -32,90 +32,51 @@ ruleTester.run('display-name', rule, {
3232
{
3333
code: `
3434
import React, { memo, forwardRef } from 'react'
35-
35+
3636
const TestComponent = function () {
3737
{
3838
const memo = (cb) => cb()
3939
const forwardRef = (cb) => cb()
4040
const React = { memo, forwardRef }
41-
const BlockReactShadowedMemo = React.memo(() => {
42-
return <div>shadowed</div>
43-
})
44-
const BlockShadowedMemo = memo(() => {
45-
return <div>shadowed</div>
46-
})
47-
const BlockShadowedForwardRef = forwardRef((props, ref) => {
48-
return \`\${props} \${ref}\`
49-
})
41+
42+
const BlockMemo = memo(() => <div>shadowed</div>)
43+
const BlockForwardRef = forwardRef(() => <div>shadowed</div>)
44+
const BlockReactMemo = React.memo(() => <div>shadowed</div>)
5045
}
5146
return null
5247
}
5348
`,
5449
},
5550
{
5651
code: `
57-
import React, { memo } from 'react'
58-
59-
const TestComponent = function (memo) {
60-
const Comp = memo(() => {
61-
return <div>param shadowed</div>
62-
})
63-
return Comp
52+
import React, { memo, forwardRef } from 'react'
53+
54+
const Test1 = function (memo) {
55+
return memo(() => <div>param shadowed</div>)
6456
}
65-
`,
66-
},
67-
{
68-
code: `
69-
import React, { memo } from 'react'
70-
71-
const TestComponent = function ({ memo }) {
72-
const Comp = memo(() => {
73-
return <div>destructured param shadowed</div>
74-
})
75-
return Comp
57+
58+
const Test2 = function ({ forwardRef }) {
59+
return forwardRef(() => <div>destructured param</div>)
7660
}
7761
`,
7862
},
7963
{
8064
code: `
8165
import React, { memo, forwardRef } from 'react'
82-
66+
8367
const TestComponent = function () {
8468
function innerFunction() {
8569
const memo = (cb) => cb()
8670
const React = { forwardRef }
87-
const Comp = memo(() => <div>nested shadowed</div>)
71+
72+
const Comp = memo(() => <div>nested</div>)
8873
const ForwardComp = React.forwardRef(() => <div>nested</div>)
8974
return [Comp, ForwardComp]
9075
}
9176
return innerFunction()
9277
}
9378
`,
9479
},
95-
{
96-
code: `
97-
import React, { forwardRef } from 'react'
98-
99-
const TestComponent = function () {
100-
const { forwardRef } = { forwardRef: () => null }
101-
const OtherComp = forwardRef((props, ref) => \`\${props} \${ref}\`)
102-
return OtherComp
103-
}
104-
`,
105-
},
106-
{
107-
code: `
108-
import React, { memo } from 'react'
109-
110-
const TestComponent = function () {
111-
const memo = (cb) => cb()
112-
const Comp = memo(() => {
113-
return <div>shadowed</div>
114-
})
115-
return Comp
116-
}
117-
`,
118-
},
11980
{
12081
code: `
12182
import React, { memo, forwardRef } from 'react'
@@ -125,13 +86,9 @@ ruleTester.run('display-name', rule, {
12586
const { forwardRef } = { forwardRef: () => null }
12687
const [React] = [{ memo, forwardRef }]
12788
128-
const Comp = memo(() => {
129-
return <div>shadowed</div>
130-
})
89+
const Comp = memo(() => <div>shadowed</div>)
13190
const ReactMemo = React.memo(() => null)
132-
const ReactForward = React.forwardRef((props, ref) => {
133-
return \`\${props} \${ref}\`
134-
})
91+
const ReactForward = React.forwardRef((props, ref) => \`\${props} \${ref}\`)
13592
const OtherComp = forwardRef((props, ref) => \`\${props} \${ref}\`)
13693
13794
return [Comp, ReactMemo, ReactForward, OtherComp]
@@ -960,7 +917,7 @@ ruleTester.run('display-name', rule, {
960917
{
961918
code: `
962919
import React, { memo, forwardRef } from 'react'
963-
920+
964921
const TestComponent = function () {
965922
{
966923
const BlockReactMemo = React.memo(() => {
@@ -980,120 +937,33 @@ ruleTester.run('display-name', rule, {
980937
}
981938
`,
982939
errors: [
983-
{
984-
messageId: 'noDisplayName',
985-
line: 6,
986-
},
987-
{
988-
messageId: 'noDisplayName',
989-
line: 10,
990-
},
991-
{
992-
messageId: 'noDisplayName',
993-
line: 14,
994-
},
940+
{ messageId: 'noDisplayName' },
941+
{ messageId: 'noDisplayName' },
942+
{ messageId: 'noDisplayName' }
995943
],
996944
},
997-
998945
{
999946
code: `
1000-
import React, { memo } from 'react'
1001-
1002-
const TestComponent = function () {
1003-
const Comp = memo(() => {
1004-
return <div>not param shadowed</div>
1005-
})
1006-
1007-
return Comp
1008-
}
1009-
`,
1010-
errors: [
1011-
{
1012-
messageId: 'noDisplayName',
1013-
line: 5,
1014-
},
1015-
],
1016-
},
947+
import React, { memo, forwardRef } from 'react'
1017948
1018-
{
1019-
code: `
1020-
import React, { memo } from 'react'
1021-
1022-
const TestComponent = function () {
1023-
const Comp = memo(() => {
1024-
return <div>not destructured param shadowed</div>
1025-
})
1026-
949+
const Test1 = function () {
950+
const Comp = memo(() => <div>not param shadowed</div>)
1027951
return Comp
1028952
}
1029-
`,
1030-
errors: [
1031-
{
1032-
messageId: 'noDisplayName',
1033-
line: 5,
1034-
},
1035-
],
1036-
},
1037953
1038-
{
1039-
code: `
1040-
import React, { memo, forwardRef } from 'react'
1041-
1042-
const TestComponent = function () {
954+
const Test2 = function () {
1043955
function innerFunction() {
1044956
const Comp = memo(() => <div>nested not shadowed</div>)
1045957
const ForwardComp = React.forwardRef(() => <div>nested</div>)
1046-
1047958
return [Comp, ForwardComp]
1048959
}
1049-
1050960
return innerFunction()
1051961
}
1052962
`,
1053963
errors: [
1054-
{
1055-
messageId: 'noDisplayName',
1056-
line: 6,
1057-
},
1058-
{
1059-
messageId: 'noDisplayName',
1060-
line: 7,
1061-
},
1062-
],
1063-
},
1064-
{
1065-
code: `
1066-
import React, { forwardRef } from 'react'
1067-
1068-
const TestComponent = function () {
1069-
const OtherComp = forwardRef((props, ref) => \`\${props} \${ref}\`)
1070-
1071-
return OtherComp
1072-
}
1073-
`,
1074-
errors: [
1075-
{
1076-
messageId: 'noDisplayName',
1077-
line: 5,
1078-
},
1079-
],
1080-
},
1081-
{
1082-
code: `
1083-
import React, { memo } from 'react'
1084-
1085-
const TestComponent = function () {
1086-
const Comp = memo(() => {
1087-
return <div>not shadowed</div>
1088-
})
1089-
return Comp
1090-
}
1091-
`,
1092-
errors: [
1093-
{
1094-
messageId: 'noDisplayName',
1095-
line: 5,
1096-
},
964+
{ messageId: 'noDisplayName' },
965+
{ messageId: 'noDisplayName' },
966+
{ messageId: 'noDisplayName' }
1097967
],
1098968
},
1099969
{
@@ -1114,82 +984,10 @@ ruleTester.run('display-name', rule, {
1114984
}
1115985
`,
1116986
errors: [
1117-
{
1118-
messageId: 'noDisplayName',
1119-
line: 5,
1120-
},
1121-
{
1122-
messageId: 'noDisplayName',
1123-
line: 8,
1124-
},
1125-
{
1126-
messageId: 'noDisplayName',
1127-
line: 9,
1128-
},
1129-
{
1130-
messageId: 'noDisplayName',
1131-
line: 12,
1132-
},
1133-
],
1134-
},
1135-
{
1136-
code: `
1137-
import React from 'react'
1138-
1139-
const Comp = React.forwardRef((props, ref) => {
1140-
return <div>test</div>
1141-
})
1142-
`,
1143-
errors: [
1144-
{
1145-
messageId: 'noDisplayName',
1146-
line: 4,
1147-
},
1148-
],
1149-
},
1150-
{
1151-
code: `
1152-
import {forwardRef} from 'react'
1153-
1154-
const Comp = forwardRef((props, ref) => {
1155-
return <div>test</div>
1156-
})
1157-
`,
1158-
errors: [
1159-
{
1160-
messageId: 'noDisplayName',
1161-
line: 4,
1162-
},
1163-
],
1164-
},
1165-
{
1166-
code: `
1167-
import React from 'react'
1168-
1169-
const Comp = React.memo(() => {
1170-
return <div>test</div>
1171-
})
1172-
`,
1173-
errors: [
1174-
{
1175-
messageId: 'noDisplayName',
1176-
line: 4,
1177-
},
1178-
],
1179-
},
1180-
{
1181-
code: `
1182-
import { memo } from 'react'
1183-
1184-
const Comp = memo(() => {
1185-
return <div>test</div>
1186-
})
1187-
`,
1188-
errors: [
1189-
{
1190-
messageId: 'noDisplayName',
1191-
line: 4,
1192-
},
987+
{ messageId: 'noDisplayName' },
988+
{ messageId: 'noDisplayName' },
989+
{ messageId: 'noDisplayName' },
990+
{ messageId: 'noDisplayName' }
1193991
],
1194992
},
1195993
{

0 commit comments

Comments
 (0)