@@ -2030,6 +2030,44 @@ ruleTester.run('prop-types', rule, {
2030
2030
2031
2031
Slider.propTypes = RcSlider.propTypes;
2032
2032
`
2033
+ } ,
2034
+ {
2035
+ code : `
2036
+ class Foo extends React.Component {
2037
+ bar() {
2038
+ this.setState((state, props) => ({ current: props.current }));
2039
+ }
2040
+ render() {
2041
+ return <div />;
2042
+ }
2043
+ }
2044
+
2045
+ Foo.propTypes = {
2046
+ current: PropTypes.number.isRequired,
2047
+ };
2048
+ `
2049
+ } ,
2050
+ {
2051
+ code : `
2052
+ class Foo extends React.Component {
2053
+ static getDerivedStateFromProps(props) {
2054
+ const { foo } = props;
2055
+ return {
2056
+ foobar: foo
2057
+ };
2058
+ }
2059
+
2060
+ render() {
2061
+ const { foobar } = this.state;
2062
+ return <div>{foobar}</div>;
2063
+ }
2064
+ }
2065
+
2066
+ Foo.propTypes = {
2067
+ foo: PropTypes.func.isRequired,
2068
+ };
2069
+ ` ,
2070
+ settings : { react : { version : '16.3.0' } }
2033
2071
}
2034
2072
] ,
2035
2073
@@ -3851,6 +3889,50 @@ ruleTester.run('prop-types', rule, {
3851
3889
` ,
3852
3890
errors : [ {
3853
3891
message : '\'foo.baz\' is missing in props validation'
3892
+ } ] ,
3893
+ } ,
3894
+ {
3895
+ code : `
3896
+ class Foo extends React.Component {
3897
+ bar() {
3898
+ this.setState((state, props) => ({ current: props.current, bar: props.bar }));
3899
+ }
3900
+ render() {
3901
+ return <div />;
3902
+ }
3903
+ }
3904
+
3905
+ Foo.propTypes = {
3906
+ current: PropTypes.number.isRequired,
3907
+ };
3908
+ ` ,
3909
+ errors : [ {
3910
+ message : '\'bar\' is missing in props validation'
3911
+ } ]
3912
+ } ,
3913
+ {
3914
+ code : `
3915
+ class Foo extends React.Component {
3916
+ static getDerivedStateFromProps(props) {
3917
+ const { foo, bar } = props;
3918
+ return {
3919
+ foobar: foo + bar
3920
+ };
3921
+ }
3922
+
3923
+ render() {
3924
+ const { foobar } = this.state;
3925
+ return <div>{foobar}</div>;
3926
+ }
3927
+ }
3928
+
3929
+ Foo.propTypes = {
3930
+ foo: PropTypes.func.isRequired,
3931
+ };
3932
+ ` ,
3933
+ settings : { react : { version : '16.3.0' } } ,
3934
+ errors : [ {
3935
+ message : '\'bar\' is missing in props validation'
3854
3936
} ]
3855
3937
} ,
3856
3938
{
0 commit comments