@@ -32,90 +32,51 @@ ruleTester.run('display-name', rule, {
32
32
{
33
33
code : `
34
34
import React, { memo, forwardRef } from 'react'
35
-
35
+
36
36
const TestComponent = function () {
37
37
{
38
38
const memo = (cb) => cb()
39
39
const forwardRef = (cb) => cb()
40
40
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>)
50
45
}
51
46
return null
52
47
}
53
48
` ,
54
49
} ,
55
50
{
56
51
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>)
64
56
}
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>)
76
60
}
77
61
` ,
78
62
} ,
79
63
{
80
64
code : `
81
65
import React, { memo, forwardRef } from 'react'
82
-
66
+
83
67
const TestComponent = function () {
84
68
function innerFunction() {
85
69
const memo = (cb) => cb()
86
70
const React = { forwardRef }
87
- const Comp = memo(() => <div>nested shadowed</div>)
71
+
72
+ const Comp = memo(() => <div>nested</div>)
88
73
const ForwardComp = React.forwardRef(() => <div>nested</div>)
89
74
return [Comp, ForwardComp]
90
75
}
91
76
return innerFunction()
92
77
}
93
78
` ,
94
79
} ,
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
- } ,
119
80
{
120
81
code : `
121
82
import React, { memo, forwardRef } from 'react'
@@ -125,13 +86,9 @@ ruleTester.run('display-name', rule, {
125
86
const { forwardRef } = { forwardRef: () => null }
126
87
const [React] = [{ memo, forwardRef }]
127
88
128
- const Comp = memo(() => {
129
- return <div>shadowed</div>
130
- })
89
+ const Comp = memo(() => <div>shadowed</div>)
131
90
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}\`)
135
92
const OtherComp = forwardRef((props, ref) => \`\${props} \${ref}\`)
136
93
137
94
return [Comp, ReactMemo, ReactForward, OtherComp]
@@ -960,7 +917,7 @@ ruleTester.run('display-name', rule, {
960
917
{
961
918
code : `
962
919
import React, { memo, forwardRef } from 'react'
963
-
920
+
964
921
const TestComponent = function () {
965
922
{
966
923
const BlockReactMemo = React.memo(() => {
@@ -980,120 +937,33 @@ ruleTester.run('display-name', rule, {
980
937
}
981
938
` ,
982
939
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' }
995
943
] ,
996
944
} ,
997
-
998
945
{
999
946
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'
1017
948
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>)
1027
951
return Comp
1028
952
}
1029
- ` ,
1030
- errors : [
1031
- {
1032
- messageId : 'noDisplayName' ,
1033
- line : 5 ,
1034
- } ,
1035
- ] ,
1036
- } ,
1037
953
1038
- {
1039
- code : `
1040
- import React, { memo, forwardRef } from 'react'
1041
-
1042
- const TestComponent = function () {
954
+ const Test2 = function () {
1043
955
function innerFunction() {
1044
956
const Comp = memo(() => <div>nested not shadowed</div>)
1045
957
const ForwardComp = React.forwardRef(() => <div>nested</div>)
1046
-
1047
958
return [Comp, ForwardComp]
1048
959
}
1049
-
1050
960
return innerFunction()
1051
961
}
1052
962
` ,
1053
963
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' }
1097
967
] ,
1098
968
} ,
1099
969
{
@@ -1114,82 +984,10 @@ ruleTester.run('display-name', rule, {
1114
984
}
1115
985
` ,
1116
986
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' }
1193
991
] ,
1194
992
} ,
1195
993
{
0 commit comments