@@ -32,15 +32,30 @@ ruleTester.run('button-has-type', rule, {
32
32
{ code : '<button type="button"/>' } ,
33
33
{ code : '<button type="submit"/>' } ,
34
34
{ code : '<button type="reset"/>' } ,
35
+ { code : '<button type={"button"}/>' } ,
36
+ { code : '<button type={\'button\'}/>' } ,
37
+ { code : '<button type={`button`}/>' } ,
38
+ { code : '<button type={condition ? "button" : "submit"}/>' } ,
39
+ { code : '<button type={condition ? \'button\' : \'submit\'}/>' } ,
40
+ { code : '<button type={condition ? `button` : `submit`}/>' } ,
35
41
{
36
42
code : '<button type="button"/>' ,
37
43
options : [ { reset : false } ]
38
44
} ,
39
45
{ code : 'React.createElement("span")' } ,
40
46
{ code : 'React.createElement("span", {type: "foo"})' } ,
41
47
{ code : 'React.createElement("button", {type: "button"})' } ,
48
+ { code : 'React.createElement("button", {type: \'button\'})' } ,
49
+ { code : 'React.createElement("button", {type: `button`})' } ,
42
50
{ code : 'React.createElement("button", {type: "submit"})' } ,
51
+ { code : 'React.createElement("button", {type: \'submit\'})' } ,
52
+ { code : 'React.createElement("button", {type: `submit`})' } ,
43
53
{ code : 'React.createElement("button", {type: "reset"})' } ,
54
+ { code : 'React.createElement("button", {type: \'reset\'})' } ,
55
+ { code : 'React.createElement("button", {type: `reset`})' } ,
56
+ { code : 'React.createElement("button", {type: condition ? "button" : "submit"})' } ,
57
+ { code : 'React.createElement("button", {type: condition ? \'button\' : \'submit\'})' } ,
58
+ { code : 'React.createElement("button", {type: condition ? `button` : `submit`})' } ,
44
59
{
45
60
code : 'React.createElement("button", {type: "button"})' ,
46
61
options : [ { reset : false } ]
@@ -73,13 +88,31 @@ ruleTester.run('button-has-type', rule, {
73
88
{
74
89
code : '<button type={foo}/>' ,
75
90
errors : [ {
76
- message : 'The button type attribute must be specified by a static string'
91
+ message : 'The button type attribute must be specified by a static string or a trivial ternary expression '
77
92
} ]
78
93
} ,
79
94
{
80
95
code : '<button type={"foo"}/>' ,
81
96
errors : [ {
82
- message : 'The button type attribute must be specified by a static string'
97
+ message : '"foo" is an invalid value for button type attribute'
98
+ } ]
99
+ } ,
100
+ {
101
+ code : '<button type={\'foo\'}/>' ,
102
+ errors : [ {
103
+ message : '"foo" is an invalid value for button type attribute'
104
+ } ]
105
+ } ,
106
+ {
107
+ code : '<button type={`foo`}/>' ,
108
+ errors : [ {
109
+ message : '"foo" is an invalid value for button type attribute'
110
+ } ]
111
+ } ,
112
+ {
113
+ code : '<button type={`button${foo}`}/>' ,
114
+ errors : [ {
115
+ message : 'The button type attribute must be specified by a static string or a trivial ternary expression'
83
116
} ]
84
117
} ,
85
118
{
@@ -89,12 +122,56 @@ ruleTester.run('button-has-type', rule, {
89
122
message : '"reset" is a forbidden value for button type attribute'
90
123
} ]
91
124
} ,
125
+ {
126
+ code : '<button type={condition ? "button" : foo}/>' ,
127
+ errors : [ {
128
+ message : 'The button type attribute must be specified by a static string or a trivial ternary expression'
129
+ } ]
130
+ } ,
131
+ {
132
+ code : '<button type={condition ? "button" : "foo"}/>' ,
133
+ errors : [ {
134
+ message : '"foo" is an invalid value for button type attribute'
135
+ } ]
136
+ } ,
137
+ {
138
+ code : '<button type={condition ? "button" : "reset"}/>' ,
139
+ options : [ { reset : false } ] ,
140
+ errors : [ {
141
+ message : '"reset" is a forbidden value for button type attribute'
142
+ } ]
143
+ } ,
144
+ {
145
+ code : '<button type={condition ? foo : "button"}/>' ,
146
+ errors : [ {
147
+ message : 'The button type attribute must be specified by a static string or a trivial ternary expression'
148
+ } ]
149
+ } ,
150
+ {
151
+ code : '<button type={condition ? "foo" : "button"}/>' ,
152
+ errors : [ {
153
+ message : '"foo" is an invalid value for button type attribute'
154
+ } ]
155
+ } ,
156
+ {
157
+ code : '<button type={condition ? "reset" : "button"}/>' ,
158
+ options : [ { reset : false } ] ,
159
+ errors : [ {
160
+ message : '"reset" is a forbidden value for button type attribute'
161
+ } ]
162
+ } ,
92
163
{
93
164
code : 'React.createElement("button")' ,
94
165
errors : [ {
95
166
message : 'Missing an explicit type attribute for button'
96
167
} ]
97
168
} ,
169
+ {
170
+ code : 'React.createElement("button", {type: foo})' ,
171
+ errors : [ {
172
+ message : 'The button type attribute must be specified by a static string or a trivial ternary expression'
173
+ } ]
174
+ } ,
98
175
{
99
176
code : 'React.createElement("button", {type: "foo"})' ,
100
177
errors : [ {
@@ -108,6 +185,44 @@ ruleTester.run('button-has-type', rule, {
108
185
message : '"reset" is a forbidden value for button type attribute'
109
186
} ]
110
187
} ,
188
+ {
189
+ code : 'React.createElement("button", {type: condition ? "button" : foo})' ,
190
+ errors : [ {
191
+ message : 'The button type attribute must be specified by a static string or a trivial ternary expression'
192
+ } ]
193
+ } ,
194
+ {
195
+ code : 'React.createElement("button", {type: condition ? "button" : "foo"})' ,
196
+ errors : [ {
197
+ message : '"foo" is an invalid value for button type attribute'
198
+ } ]
199
+ } ,
200
+ {
201
+ code : 'React.createElement("button", {type: condition ? "button" : "reset"})' ,
202
+ options : [ { reset : false } ] ,
203
+ errors : [ {
204
+ message : '"reset" is a forbidden value for button type attribute'
205
+ } ]
206
+ } ,
207
+ {
208
+ code : 'React.createElement("button", {type: condition ? foo : "button"})' ,
209
+ errors : [ {
210
+ message : 'The button type attribute must be specified by a static string or a trivial ternary expression'
211
+ } ]
212
+ } ,
213
+ {
214
+ code : 'React.createElement("button", {type: condition ? "foo" : "button"})' ,
215
+ errors : [ {
216
+ message : '"foo" is an invalid value for button type attribute'
217
+ } ]
218
+ } ,
219
+ {
220
+ code : 'React.createElement("button", {type: condition ? "reset" : "button"})' ,
221
+ options : [ { reset : false } ] ,
222
+ errors : [ {
223
+ message : '"reset" is a forbidden value for button type attribute'
224
+ } ]
225
+ } ,
111
226
{
112
227
code : 'Foo.createElement("button")' ,
113
228
errors : [ {
@@ -122,7 +237,7 @@ ruleTester.run('button-has-type', rule, {
122
237
{
123
238
code : 'function Button({ type, ...extraProps }) { const button = type; return <button type={button} {...extraProps} />; }' ,
124
239
errors : [ {
125
- message : 'The button type attribute must be specified by a static string'
240
+ message : 'The button type attribute must be specified by a static string or a trivial ternary expression '
126
241
} ]
127
242
}
128
243
]
0 commit comments