@@ -49,6 +49,10 @@ ruleTester.run('jsx-no-bind', rule, {
49
49
code : '<div ref={this._refCallback.bind(this)}></div>' ,
50
50
options : [ { ignoreRefs : true } ]
51
51
} ,
52
+ {
53
+ code : '<div ref={function (c) {this._input = c}}></div>' ,
54
+ options : [ { ignoreRefs : true } ]
55
+ } ,
52
56
53
57
// bind() explicitly allowed
54
58
{
@@ -61,6 +65,24 @@ ruleTester.run('jsx-no-bind', rule, {
61
65
code : '<div onClick={() => alert("1337")}></div>' ,
62
66
options : [ { allowArrowFunctions : true } ]
63
67
} ,
68
+ {
69
+ code : '<div onClick={async () => alert("1337")}></div>' ,
70
+ options : [ { allowArrowFunctions : true } ]
71
+ } ,
72
+
73
+ // Functions explicitly allowed
74
+ {
75
+ code : '<div onClick={function () { alert("1337") }}></div>' ,
76
+ options : [ { allowFunctions : true } ]
77
+ } ,
78
+ {
79
+ code : '<div onClick={function * () { alert("1337") }}></div>' ,
80
+ options : [ { allowFunctions : true } ]
81
+ } ,
82
+ {
83
+ code : '<div onClick={async function () { alert("1337") }}></div>' ,
84
+ options : [ { allowFunctions : true } ]
85
+ } ,
64
86
65
87
// Redux connect
66
88
{
@@ -370,6 +392,10 @@ ruleTester.run('jsx-no-bind', rule, {
370
392
code : '<div onClick={() => alert("1337")}></div>' ,
371
393
errors : [ { message : 'JSX props should not use arrow functions' } ]
372
394
} ,
395
+ {
396
+ code : '<div onClick={async () => alert("1337")}></div>' ,
397
+ errors : [ { message : 'JSX props should not use arrow functions' } ]
398
+ } ,
373
399
{
374
400
code : '<div onClick={() => 42}></div>' ,
375
401
errors : [ { message : 'JSX props should not use arrow functions' } ]
@@ -480,6 +506,154 @@ ruleTester.run('jsx-no-bind', rule, {
480
506
parser : 'babel-eslint'
481
507
} ,
482
508
509
+ // Functions
510
+ {
511
+ code : '<div onClick={function () { alert("1337") }}></div>' ,
512
+ errors : [ { message : 'JSX props should not use functions' } ]
513
+ } ,
514
+ {
515
+ code : '<div onClick={function * () { alert("1337") }}></div>' ,
516
+ errors : [ { message : 'JSX props should not use functions' } ]
517
+ } ,
518
+ {
519
+ code : '<div onClick={async function () { alert("1337") }}></div>' ,
520
+ errors : [ { message : 'JSX props should not use functions' } ]
521
+ } ,
522
+ {
523
+ code : '<div ref={function (c) { this._input = c }}></div>' ,
524
+ errors : [ { message : 'JSX props should not use functions' } ]
525
+ } ,
526
+ {
527
+ code : [
528
+ 'class Hello23 extends React.Component {' ,
529
+ ' renderDiv = () => {' ,
530
+ ' const click = function () { return true }' ,
531
+ ' return <div onClick={click}>Hello</div>;' ,
532
+ ' }' ,
533
+ '};'
534
+ ] . join ( '\n' ) ,
535
+ errors : [ { message : 'JSX props should not use functions' } ] ,
536
+ parser : 'babel-eslint'
537
+ } ,
538
+ {
539
+ code : [
540
+ 'class Hello23 extends React.Component {' ,
541
+ ' renderDiv = () => {' ,
542
+ ' const click = function * () { return true }' ,
543
+ ' return <div onClick={click}>Hello</div>;' ,
544
+ ' }' ,
545
+ '};'
546
+ ] . join ( '\n' ) ,
547
+ errors : [ { message : 'JSX props should not use functions' } ] ,
548
+ parser : 'babel-eslint'
549
+ } ,
550
+ {
551
+ code : [
552
+ 'class Hello23 extends React.Component {' ,
553
+ ' renderDiv = async () => {' ,
554
+ ' const click = function () { return true }' ,
555
+ ' return <div onClick={click}>Hello</div>;' ,
556
+ ' }' ,
557
+ '};'
558
+ ] . join ( '\n' ) ,
559
+ errors : [ { message : 'JSX props should not use functions' } ] ,
560
+ parser : 'babel-eslint'
561
+ } ,
562
+ {
563
+ code : [
564
+ 'class Hello23 extends React.Component {' ,
565
+ ' renderDiv = async () => {' ,
566
+ ' const click = async function () { return true }' ,
567
+ ' return <div onClick={click}>Hello</div>;' ,
568
+ ' }' ,
569
+ '};'
570
+ ] . join ( '\n' ) ,
571
+ errors : [ { message : 'JSX props should not use functions' } ] ,
572
+ parser : 'babel-eslint'
573
+ } ,
574
+ {
575
+ code : [
576
+ 'var Hello = React.createClass({' ,
577
+ ' render: function() { ' ,
578
+ ' return <div onClick={function () { return true }} />' ,
579
+ ' }' ,
580
+ '});'
581
+ ] . join ( '\n' ) ,
582
+ errors : [ { message : 'JSX props should not use functions' } ]
583
+ } ,
584
+ {
585
+ code : [
586
+ 'var Hello = React.createClass({' ,
587
+ ' render: function() { ' ,
588
+ ' return <div onClick={function * () { return true }} />' ,
589
+ ' }' ,
590
+ '});'
591
+ ] . join ( '\n' ) ,
592
+ errors : [ { message : 'JSX props should not use functions' } ]
593
+ } ,
594
+ {
595
+ code : [
596
+ 'var Hello = React.createClass({' ,
597
+ ' render: function() { ' ,
598
+ ' return <div onClick={async function () { return true }} />' ,
599
+ ' }' ,
600
+ '});'
601
+ ] . join ( '\n' ) ,
602
+ errors : [ { message : 'JSX props should not use functions' } ]
603
+ } ,
604
+ {
605
+ code : [
606
+ 'var Hello = React.createClass({' ,
607
+ ' render: function() { ' ,
608
+ ' const doThing = function () { return true }' ,
609
+ ' return <div onClick={doThing} />' ,
610
+ ' }' ,
611
+ '});'
612
+ ] . join ( '\n' ) ,
613
+ errors : [ { message : 'JSX props should not use functions' } ]
614
+ } ,
615
+ {
616
+ code : [
617
+ 'var Hello = React.createClass({' ,
618
+ ' render: function() { ' ,
619
+ ' const doThing = async function () { return true }' ,
620
+ ' return <div onClick={doThing} />' ,
621
+ ' }' ,
622
+ '});'
623
+ ] . join ( '\n' ) ,
624
+ errors : [ { message : 'JSX props should not use functions' } ]
625
+ } ,
626
+ {
627
+ code : [
628
+ 'var Hello = React.createClass({' ,
629
+ ' render: function() { ' ,
630
+ ' const doThing = function * () { return true }' ,
631
+ ' return <div onClick={doThing} />' ,
632
+ ' }' ,
633
+ '});'
634
+ ] . join ( '\n' ) ,
635
+ errors : [ { message : 'JSX props should not use functions' } ]
636
+ } ,
637
+ {
638
+ code : [
639
+ 'class Hello23 extends React.Component {' ,
640
+ ' renderDiv = () => {' ,
641
+ ' const click = ::this.onChange' ,
642
+ ' const renderStuff = () => {' ,
643
+ ' const click = function () { return true }' ,
644
+ ' return <div onClick={click} />' ,
645
+ ' }' ,
646
+ ' return <div onClick={click}>Hello</div>;' ,
647
+ ' }' ,
648
+ '};'
649
+ ] . join ( '\n' ) ,
650
+ errors : [
651
+ { message : 'JSX props should not use functions' } ,
652
+ { message : 'JSX props should not use ::' }
653
+ ] ,
654
+ parser : 'babel-eslint'
655
+ } ,
656
+
483
657
// Bind expression
484
658
{
485
659
code : '<div foo={::this.onChange} />' ,
0 commit comments