@@ -32,15 +32,30 @@ ruleTester.run('button-has-type', rule, {
3232 { code : '<button type="button"/>' } ,
3333 { code : '<button type="submit"/>' } ,
3434 { 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`}/>' } ,
3541 {
3642 code : '<button type="button"/>' ,
3743 options : [ { reset : false } ]
3844 } ,
3945 { code : 'React.createElement("span")' } ,
4046 { code : 'React.createElement("span", {type: "foo"})' } ,
4147 { code : 'React.createElement("button", {type: "button"})' } ,
48+ { code : 'React.createElement("button", {type: \'button\'})' } ,
49+ { code : 'React.createElement("button", {type: `button`})' } ,
4250 { code : 'React.createElement("button", {type: "submit"})' } ,
51+ { code : 'React.createElement("button", {type: \'submit\'})' } ,
52+ { code : 'React.createElement("button", {type: `submit`})' } ,
4353 { 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`})' } ,
4459 {
4560 code : 'React.createElement("button", {type: "button"})' ,
4661 options : [ { reset : false } ]
@@ -73,13 +88,31 @@ ruleTester.run('button-has-type', rule, {
7388 {
7489 code : '<button type={foo}/>' ,
7590 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 '
7792 } ]
7893 } ,
7994 {
8095 code : '<button type={"foo"}/>' ,
8196 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'
83116 } ]
84117 } ,
85118 {
@@ -89,12 +122,56 @@ ruleTester.run('button-has-type', rule, {
89122 message : '"reset" is a forbidden value for button type attribute'
90123 } ]
91124 } ,
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+ } ,
92163 {
93164 code : 'React.createElement("button")' ,
94165 errors : [ {
95166 message : 'Missing an explicit type attribute for button'
96167 } ]
97168 } ,
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+ } ,
98175 {
99176 code : 'React.createElement("button", {type: "foo"})' ,
100177 errors : [ {
@@ -108,6 +185,44 @@ ruleTester.run('button-has-type', rule, {
108185 message : '"reset" is a forbidden value for button type attribute'
109186 } ]
110187 } ,
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+ } ,
111226 {
112227 code : 'Foo.createElement("button")' ,
113228 errors : [ {
@@ -122,7 +237,7 @@ ruleTester.run('button-has-type', rule, {
122237 {
123238 code : 'function Button({ type, ...extraProps }) { const button = type; return <button type={button} {...extraProps} />; }' ,
124239 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 '
126241 } ]
127242 }
128243 ]
0 commit comments