@@ -1957,6 +1957,44 @@ ruleTester.run('prop-types', rule, {
19571957
19581958 Slider.propTypes = RcSlider.propTypes;
19591959 `
1960+ } ,
1961+ {
1962+ code : `
1963+ class Foo extends React.Component {
1964+ bar() {
1965+ this.setState((state, props) => ({ current: props.current }));
1966+ }
1967+ render() {
1968+ return <div />;
1969+ }
1970+ }
1971+
1972+ Foo.propTypes = {
1973+ current: PropTypes.number.isRequired,
1974+ };
1975+ `
1976+ } ,
1977+ {
1978+ code : `
1979+ class Foo extends React.Component {
1980+ static getDerivedStateFromProps(props) {
1981+ const { foo } = props;
1982+ return {
1983+ foobar: foo
1984+ };
1985+ }
1986+
1987+ render() {
1988+ const { foobar } = this.state;
1989+ return <div>{foobar}</div>;
1990+ }
1991+ }
1992+
1993+ Foo.propTypes = {
1994+ foo: PropTypes.func.isRequired,
1995+ };
1996+ ` ,
1997+ settings : { react : { version : '16.3.0' } }
19601998 }
19611999 ] ,
19622000
@@ -3760,6 +3798,50 @@ ruleTester.run('prop-types', rule, {
37603798 message : '\'bad\' is missing in props validation'
37613799 } ] ,
37623800 parser : 'babel-eslint'
3801+ } ,
3802+ {
3803+ code : `
3804+ class Foo extends React.Component {
3805+ bar() {
3806+ this.setState((state, props) => ({ current: props.current, bar: props.bar }));
3807+ }
3808+ render() {
3809+ return <div />;
3810+ }
3811+ }
3812+
3813+ Foo.propTypes = {
3814+ current: PropTypes.number.isRequired,
3815+ };
3816+ ` ,
3817+ errors : [ {
3818+ message : '\'bar\' is missing in props validation'
3819+ } ]
3820+ } ,
3821+ {
3822+ code : `
3823+ class Foo extends React.Component {
3824+ static getDerivedStateFromProps(props) {
3825+ const { foo, bar } = props;
3826+ return {
3827+ foobar: foo + bar
3828+ };
3829+ }
3830+
3831+ render() {
3832+ const { foobar } = this.state;
3833+ return <div>{foobar}</div>;
3834+ }
3835+ }
3836+
3837+ Foo.propTypes = {
3838+ foo: PropTypes.func.isRequired,
3839+ };
3840+ ` ,
3841+ settings : { react : { version : '16.3.0' } } ,
3842+ errors : [ {
3843+ message : '\'bar\' is missing in props validation'
3844+ } ]
37633845 }
37643846 ]
37653847} ) ;
0 commit comments