@@ -23,6 +23,7 @@ const parserOptions = {
23
23
// -----------------------------------------------------------------------------
24
24
25
25
const ERROR_MESSAGE = 'Typo in static class property declaration' ;
26
+ const ERROR_MESSAGE_ES5 = 'Typo in property declaration' ;
26
27
const ERROR_MESSAGE_LIFECYCLE_METHOD = 'Typo in component lifecycle method declaration' ;
27
28
28
29
const ruleTester = new RuleTester ( ) ;
@@ -519,6 +520,105 @@ ruleTester.run('no-typos', rule, {
519
520
` ,
520
521
parser : 'babel-eslint' ,
521
522
parserOptions : parserOptions
523
+ } , {
524
+ code : `
525
+ import React from 'react';
526
+ import PropTypes from 'prop-types';
527
+ const Component = React.createReactClass({
528
+ propTypes: {
529
+ a: PropTypes.string.isRequired,
530
+ b: PropTypes.shape({
531
+ c: PropTypes.number
532
+ }).isRequired
533
+ }
534
+ });
535
+ ` ,
536
+ parserOptions : parserOptions
537
+ } , {
538
+ code : `
539
+ import React from 'react';
540
+ import PropTypes from 'prop-types';
541
+ const Component = React.createReactClass({
542
+ propTypes: {
543
+ a: PropTypes.string.isRequired,
544
+ b: PropTypes.shape({
545
+ c: PropTypes.number
546
+ }).isRequired
547
+ }
548
+ });
549
+ ` ,
550
+ parser : 'babel-eslint' ,
551
+ parserOptions : parserOptions
552
+ } , {
553
+ code : `
554
+ import React from 'react';
555
+ import PropTypes from 'prop-types';
556
+ const Component = React.createReactClass({
557
+ childContextTypes: {
558
+ a: PropTypes.bool,
559
+ b: PropTypes.array,
560
+ c: PropTypes.func,
561
+ d: PropTypes.object,
562
+ }
563
+ });
564
+ ` ,
565
+ parserOptions : parserOptions
566
+ } , {
567
+ code : `
568
+ import React from 'react';
569
+ import PropTypes from 'prop-types';
570
+ const Component = React.createReactClass({
571
+ childContextTypes: {
572
+ a: PropTypes.bool,
573
+ b: PropTypes.array,
574
+ c: PropTypes.func,
575
+ d: PropTypes.object,
576
+ }
577
+ });
578
+ ` ,
579
+ parser : 'babel-eslint' ,
580
+ parserOptions : parserOptions
581
+ } , {
582
+ code : `
583
+ import React from 'react';
584
+ const Component = React.createReactClass({
585
+ propTypes: {},
586
+ childContextTypes: {},
587
+ contextTypes: {},
588
+ componentWillMount() { },
589
+ componentDidMount() { },
590
+ componentWillReceiveProps() { },
591
+ shouldComponentUpdate() { },
592
+ componentWillUpdate() { },
593
+ componentDidUpdate() { },
594
+ componentWillUnmount() { },
595
+ render() {
596
+ return <div>Hello {this.props.name}</div>;
597
+ }
598
+ });
599
+ ` ,
600
+ parserOptions : parserOptions
601
+ } , {
602
+ code : `
603
+ import React from 'react';
604
+ const Component = React.createReactClass({
605
+ propTypes: {},
606
+ childContextTypes: {},
607
+ contextTypes: {},
608
+ componentWillMount() { },
609
+ componentDidMount() { },
610
+ componentWillReceiveProps() { },
611
+ shouldComponentUpdate() { },
612
+ componentWillUpdate() { },
613
+ componentDidUpdate() { },
614
+ componentWillUnmount() { },
615
+ render() {
616
+ return <div>Hello {this.props.name}</div>;
617
+ }
618
+ });
619
+ ` ,
620
+ parser : 'babel-eslint' ,
621
+ parserOptions : parserOptions
522
622
} ] ,
523
623
524
624
invalid : [ {
@@ -1369,28 +1469,11 @@ ruleTester.run('no-typos', rule, {
1369
1469
} , {
1370
1470
message : 'Typo in declared prop type: objectof'
1371
1471
} ]
1372
- } ]
1373
- /*
1374
- // PropTypes declared on a component that is detected through JSDoc comments and is
1375
- // declared AFTER the PropTypes assignment
1376
- // Commented out since it only works with ESLint 5.
1377
- ,{
1378
- code: `
1379
- MyComponent.PROPTYPES = {}
1380
- \/** @extends React.Component *\/
1381
- class MyComponent extends BaseComponent {}
1382
- `,
1383
- parserOptions: parserOptions
1384
- },
1385
- */
1386
- /*
1387
- // createClass tests below fail, so they're commented out
1388
- // ---------
1389
1472
} , {
1390
1473
code : `
1391
1474
import React from 'react';
1392
1475
import PropTypes from 'prop-types';
1393
- const Component = React.createClass ({
1476
+ const Component = React.createReactClass ({
1394
1477
propTypes: {
1395
1478
a: PropTypes.string.isrequired,
1396
1479
b: PropTypes.shape({
@@ -1410,7 +1493,7 @@ ruleTester.run('no-typos', rule, {
1410
1493
code : `
1411
1494
import React from 'react';
1412
1495
import PropTypes from 'prop-types';
1413
- const Component = React.createClass ({
1496
+ const Component = React.createReactClass ({
1414
1497
childContextTypes: {
1415
1498
a: PropTypes.bools,
1416
1499
b: PropTypes.Array,
@@ -1434,7 +1517,7 @@ ruleTester.run('no-typos', rule, {
1434
1517
code : `
1435
1518
import React from 'react';
1436
1519
import PropTypes from 'prop-types';
1437
- const Component = React.createClass ({
1520
+ const Component = React.createReactClass ({
1438
1521
propTypes: {
1439
1522
a: PropTypes.string.isrequired,
1440
1523
b: PropTypes.shape({
@@ -1453,7 +1536,7 @@ ruleTester.run('no-typos', rule, {
1453
1536
code : `
1454
1537
import React from 'react';
1455
1538
import PropTypes from 'prop-types';
1456
- const Component = React.createClass ({
1539
+ const Component = React.createReactClass ({
1457
1540
childContextTypes: {
1458
1541
a: PropTypes.bools,
1459
1542
b: PropTypes.Array,
@@ -1472,8 +1555,121 @@ ruleTester.run('no-typos', rule, {
1472
1555
} , {
1473
1556
message : 'Typo in declared prop type: objectof'
1474
1557
} ]
1558
+ } , {
1559
+ code : `
1560
+ import React from 'react';
1561
+ const Component = React.createReactClass({
1562
+ proptypes: {},
1563
+ childcontexttypes: {},
1564
+ contexttypes: {},
1565
+ ComponentWillMount() { },
1566
+ ComponentDidMount() { },
1567
+ ComponentWillReceiveProps() { },
1568
+ ShouldComponentUpdate() { },
1569
+ ComponentWillUpdate() { },
1570
+ ComponentDidUpdate() { },
1571
+ ComponentWillUnmount() { },
1572
+ render() {
1573
+ return <div>Hello {this.props.name}</div>;
1574
+ }
1575
+ });
1576
+ ` ,
1577
+ parserOptions : parserOptions ,
1578
+ errors : [ {
1579
+ message : ERROR_MESSAGE_ES5 ,
1580
+ type : 'ObjectExpression'
1581
+ } , {
1582
+ message : ERROR_MESSAGE_ES5 ,
1583
+ type : 'ObjectExpression'
1584
+ } , {
1585
+ message : ERROR_MESSAGE_ES5 ,
1586
+ type : 'ObjectExpression'
1587
+ } , {
1588
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1589
+ type : 'Property'
1590
+ } , {
1591
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1592
+ type : 'Property'
1593
+ } , {
1594
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1595
+ type : 'Property'
1596
+ } , {
1597
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1598
+ type : 'Property'
1599
+ } , {
1600
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1601
+ type : 'Property'
1602
+ } , {
1603
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1604
+ type : 'Property'
1605
+ } , {
1606
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1607
+ type : 'Property'
1608
+ } ]
1609
+ } , {
1610
+ code : `
1611
+ import React from 'react';
1612
+ const Component = React.createReactClass({
1613
+ proptypes: {},
1614
+ childcontexttypes: {},
1615
+ contexttypes: {},
1616
+ ComponentWillMount() { },
1617
+ ComponentDidMount() { },
1618
+ ComponentWillReceiveProps() { },
1619
+ ShouldComponentUpdate() { },
1620
+ ComponentWillUpdate() { },
1621
+ ComponentDidUpdate() { },
1622
+ ComponentWillUnmount() { },
1623
+ render() {
1624
+ return <div>Hello {this.props.name}</div>;
1625
+ }
1626
+ });
1627
+ ` ,
1628
+ parser : 'babel-eslint' ,
1629
+ parserOptions : parserOptions ,
1630
+ errors : [ {
1631
+ message : ERROR_MESSAGE_ES5 ,
1632
+ type : 'ObjectExpression'
1633
+ } , {
1634
+ message : ERROR_MESSAGE_ES5 ,
1635
+ type : 'ObjectExpression'
1636
+ } , {
1637
+ message : ERROR_MESSAGE_ES5 ,
1638
+ type : 'ObjectExpression'
1639
+ } , {
1640
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1641
+ type : 'Property'
1642
+ } , {
1643
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1644
+ type : 'Property'
1645
+ } , {
1646
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1647
+ type : 'Property'
1648
+ } , {
1649
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1650
+ type : 'Property'
1651
+ } , {
1652
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1653
+ type : 'Property'
1654
+ } , {
1655
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1656
+ type : 'Property'
1657
+ } , {
1658
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
1659
+ type : 'Property'
1660
+ } ]
1661
+ /*
1662
+ // PropTypes declared on a component that is detected through JSDoc comments and is
1663
+ // declared AFTER the PropTypes assignment
1664
+ // Commented out since it only works with ESLint 5.
1665
+ ,{
1666
+ code: `
1667
+ MyComponent.PROPTYPES = {}
1668
+ \/** @extends React.Component *\/
1669
+ class MyComponent extends BaseComponent {}
1670
+ `,
1671
+ parserOptions: parserOptions
1672
+ },
1673
+ */
1475
1674
} ]
1476
- // ---------
1477
- // createClass tests above fail, so they're commented out
1478
- */
1479
1675
} ) ;
0 commit comments