@@ -151,13 +151,24 @@ ruleTester.run('prefer-read-only-props', rule, {
151
151
parser : parsers . BABEL_ESLINT ,
152
152
errors : [ {
153
153
message : 'Prop \'name\' should be read-only.'
154
- } ]
154
+ } ] ,
155
+ output : `
156
+ type Props = {
157
+ +name: string,
158
+ }
159
+
160
+ class Hello extends React.Component<Props> {
161
+ render () {
162
+ return <div>Hello {this.props.name}</div>;
163
+ }
164
+ }
165
+ `
155
166
} ,
156
167
{
157
168
// Props.name is contravariant
158
169
code : `
159
170
type Props = {
160
- -name: string,
171
+ -name: string,
161
172
}
162
173
163
174
class Hello extends React.Component<Props> {
@@ -169,7 +180,18 @@ ruleTester.run('prefer-read-only-props', rule, {
169
180
parser : parsers . BABEL_ESLINT ,
170
181
errors : [ {
171
182
message : 'Prop \'name\' should be read-only.'
172
- } ]
183
+ } ] ,
184
+ output : `
185
+ type Props = {
186
+ +name: string,
187
+ }
188
+
189
+ class Hello extends React.Component<Props> {
190
+ render () {
191
+ return <div>Hello {this.props.name}</div>;
192
+ }
193
+ }
194
+ `
173
195
} ,
174
196
{
175
197
code : `
@@ -186,7 +208,18 @@ ruleTester.run('prefer-read-only-props', rule, {
186
208
parser : parsers . BABEL_ESLINT ,
187
209
errors : [ {
188
210
message : 'Prop \'name\' should be read-only.'
189
- } ]
211
+ } ] ,
212
+ output : `
213
+ class Hello extends React.Component {
214
+ props: {
215
+ +name: string,
216
+ }
217
+
218
+ render () {
219
+ return <div>Hello {this.props.name}</div>;
220
+ }
221
+ }
222
+ `
190
223
} ,
191
224
{
192
225
code : `
@@ -197,7 +230,12 @@ ruleTester.run('prefer-read-only-props', rule, {
197
230
parser : parsers . BABEL_ESLINT ,
198
231
errors : [ {
199
232
message : 'Prop \'name\' should be read-only.'
200
- } ]
233
+ } ] ,
234
+ output : `
235
+ function Hello(props: {+name: string}) {
236
+ return <div>Hello {props.name}</div>;
237
+ }
238
+ `
201
239
} ,
202
240
{
203
241
code : `
@@ -208,7 +246,12 @@ ruleTester.run('prefer-read-only-props', rule, {
208
246
parser : parsers . BABEL_ESLINT ,
209
247
errors : [ {
210
248
message : 'Prop \'name\' should be read-only.'
211
- } ]
249
+ } ] ,
250
+ output : `
251
+ function Hello(props: {|+name: string|}) {
252
+ return <div>Hello {props.name}</div>;
253
+ }
254
+ `
212
255
} ,
213
256
{
214
257
code : `
@@ -219,7 +262,12 @@ ruleTester.run('prefer-read-only-props', rule, {
219
262
parser : parsers . BABEL_ESLINT ,
220
263
errors : [ {
221
264
message : 'Prop \'name\' should be read-only.'
222
- } ]
265
+ } ] ,
266
+ output : `
267
+ function Hello({name}: {+name: string}) {
268
+ return <div>Hello {props.name}</div>;
269
+ }
270
+ `
223
271
} ,
224
272
{
225
273
code : `
@@ -236,7 +284,16 @@ ruleTester.run('prefer-read-only-props', rule, {
236
284
message : 'Prop \'firstName\' should be read-only.'
237
285
} , {
238
286
message : 'Prop \'lastName\' should be read-only.'
239
- } ]
287
+ } ] ,
288
+ output : `
289
+ type PropsA = {+firstName: string};
290
+ type PropsB = {+lastName: string};
291
+ type Props = PropsA & PropsB;
292
+
293
+ function Hello({firstName, lastName}: Props) {
294
+ return <div>Hello {firstName} {lastName}</div>;
295
+ }
296
+ `
240
297
} ,
241
298
{
242
299
code : `
@@ -247,7 +304,12 @@ ruleTester.run('prefer-read-only-props', rule, {
247
304
parser : parsers . BABEL_ESLINT ,
248
305
errors : [ {
249
306
message : 'Prop \'name\' should be read-only.'
250
- } ]
307
+ } ] ,
308
+ output : `
309
+ const Hello = (props: {+name: string}) => (
310
+ <div>Hello {props.name}</div>
311
+ );
312
+ `
251
313
}
252
314
]
253
315
} ) ;
0 commit comments