@@ -1385,6 +1385,19 @@ ruleTester.run('prop-types', rule, {
1385
1385
'}'
1386
1386
] . join ( '\n' ) ,
1387
1387
parser : 'babel-eslint'
1388
+ } , {
1389
+ // Flow annotations with variance
1390
+ code : [
1391
+ 'type Props = {' ,
1392
+ ' +firstname: string;' ,
1393
+ ' -lastname: string;' ,
1394
+ '};' ,
1395
+ 'function Hello(props: Props): React.Element {' ,
1396
+ ' const {firstname, lastname} = props;' ,
1397
+ ' return <div>Hello {firstname} {lastname}</div>' ,
1398
+ '}'
1399
+ ] . join ( '\n' ) ,
1400
+ parser : 'babel-eslint'
1388
1401
}
1389
1402
] ,
1390
1403
@@ -2471,6 +2484,52 @@ ruleTester.run('prop-types', rule, {
2471
2484
line : 3 ,
2472
2485
column : 29
2473
2486
} ]
2487
+ } , {
2488
+ code : [
2489
+ 'type MyComponentProps = {' ,
2490
+ ' +a: number,' ,
2491
+ '};' ,
2492
+ 'function MyComponent({ a, b }: MyComponentProps) {' ,
2493
+ ' return <div />;' ,
2494
+ '}'
2495
+ ] . join ( '\n' ) ,
2496
+ parser : 'babel-eslint' ,
2497
+ errors : [ {
2498
+ message : '\'b\' is missing in props validation' ,
2499
+ line : 4 ,
2500
+ column : 27 ,
2501
+ type : 'Property'
2502
+ } ]
2503
+ } , {
2504
+ code : [
2505
+ 'type MyComponentProps = {' ,
2506
+ ' -a: number,' ,
2507
+ '};' ,
2508
+ 'function MyComponent({ a, b }: MyComponentProps) {' ,
2509
+ ' return <div />;' ,
2510
+ '}'
2511
+ ] . join ( '\n' ) ,
2512
+ parser : 'babel-eslint' ,
2513
+ errors : [ {
2514
+ message : '\'b\' is missing in props validation' ,
2515
+ line : 4 ,
2516
+ column : 27 ,
2517
+ type : 'Property'
2518
+ } ]
2519
+ } , {
2520
+ code : [
2521
+ 'type Props = {+name: Object;};' ,
2522
+ 'class Hello extends React.Component {' ,
2523
+ ' props: Props;' ,
2524
+ ' render () {' ,
2525
+ ' return <div>Hello {this.props.firstname}</div>;' ,
2526
+ ' }' ,
2527
+ '}'
2528
+ ] . join ( '\n' ) ,
2529
+ parser : 'babel-eslint' ,
2530
+ errors : [
2531
+ { message : '\'firstname\' is missing in props validation' }
2532
+ ]
2474
2533
}
2475
2534
]
2476
2535
} ) ;
0 commit comments