@@ -1957,6 +1957,44 @@ ruleTester.run('prop-types', rule, {
1957
1957
1958
1958
Slider.propTypes = RcSlider.propTypes;
1959
1959
`
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' } }
1960
1998
}
1961
1999
] ,
1962
2000
@@ -3760,6 +3798,50 @@ ruleTester.run('prop-types', rule, {
3760
3798
message : '\'bad\' is missing in props validation'
3761
3799
} ] ,
3762
3800
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
+ } ]
3763
3845
}
3764
3846
]
3765
3847
} ) ;
0 commit comments