@@ -829,10 +829,10 @@ ruleTester.run('no-unused-prop-types', rule, {
829
829
type PropsA = { a: string }
830
830
type PropsB = { b: string }
831
831
type Props = PropsA & PropsB;
832
-
832
+
833
833
class MyComponent extends React.Component {
834
834
props: Props;
835
-
835
+
836
836
render() {
837
837
return <div>{this.props.a} - {this.props.b}</div>
838
838
}
@@ -848,7 +848,7 @@ ruleTester.run('no-unused-prop-types', rule, {
848
848
849
849
class Bar extends React.Component {
850
850
props: Props & PropsC;
851
-
851
+
852
852
render() {
853
853
return <div>{this.props.foo} - {this.props.bar} - {this.props.zap}</div>
854
854
}
@@ -864,7 +864,7 @@ ruleTester.run('no-unused-prop-types', rule, {
864
864
865
865
class Bar extends React.Component {
866
866
props: Props & PropsC;
867
-
867
+
868
868
render() {
869
869
return <div>{this.props.foo} - {this.props.bar} - {this.props.zap}</div>
870
870
}
@@ -876,12 +876,12 @@ ruleTester.run('no-unused-prop-types', rule, {
876
876
type PropsB = { foo: string };
877
877
type PropsC = { bar: string };
878
878
type Props = PropsB & {
879
- zap: string
879
+ zap: string
880
880
};
881
881
882
882
class Bar extends React.Component {
883
883
props: Props & PropsC;
884
-
884
+
885
885
render() {
886
886
return <div>{this.props.foo} - {this.props.bar} - {this.props.zap}</div>
887
887
}
@@ -893,12 +893,12 @@ ruleTester.run('no-unused-prop-types', rule, {
893
893
type PropsB = { foo: string };
894
894
type PropsC = { bar: string };
895
895
type Props = {
896
- zap: string
896
+ zap: string
897
897
} & PropsB;
898
898
899
899
class Bar extends React.Component {
900
900
props: Props & PropsC;
901
-
901
+
902
902
render() {
903
903
return <div>{this.props.foo} - {this.props.bar} - {this.props.zap}</div>
904
904
}
@@ -2110,6 +2110,93 @@ ruleTester.run('no-unused-prop-types', rule, {
2110
2110
] . join ( '\n' ) ,
2111
2111
parser : 'babel-eslint' ,
2112
2112
options : [ { skipShapeProps : false } ]
2113
+ } , {
2114
+ // issue #1506
2115
+ code : [
2116
+ 'class MyComponent extends React.Component {' ,
2117
+ ' onFoo() {' ,
2118
+ ' this.setState((prevState, props) => {' ,
2119
+ ' props.doSomething();' ,
2120
+ ' });' ,
2121
+ ' }' ,
2122
+ ' render() {' ,
2123
+ ' return (' ,
2124
+ ' <div onClick={this.onFoo}>Test</div>' ,
2125
+ ' );' ,
2126
+ ' }' ,
2127
+ '}' ,
2128
+ 'MyComponent.propTypes = {' ,
2129
+ ' doSomething: PropTypes.func' ,
2130
+ '};' ,
2131
+ 'var tempVar2;'
2132
+ ] . join ( '\n' ) ,
2133
+ parser : 'babel-eslint' ,
2134
+ options : [ { skipShapeProps : false } ]
2135
+ } , {
2136
+ // issue #1506
2137
+ code : [
2138
+ 'class MyComponent extends React.Component {' ,
2139
+ ' onFoo() {' ,
2140
+ ' this.setState((prevState, { doSomething }) => {' ,
2141
+ ' doSomething();' ,
2142
+ ' });' ,
2143
+ ' }' ,
2144
+ ' render() {' ,
2145
+ ' return (' ,
2146
+ ' <div onClick={this.onFoo}>Test</div>' ,
2147
+ ' );' ,
2148
+ ' }' ,
2149
+ '}' ,
2150
+ 'MyComponent.propTypes = {' ,
2151
+ ' doSomething: PropTypes.func' ,
2152
+ '};'
2153
+ ] . join ( '\n' ) ,
2154
+ parser : 'babel-eslint' ,
2155
+ options : [ { skipShapeProps : false } ]
2156
+ } , {
2157
+ // issue #1506
2158
+ code : [
2159
+ 'class MyComponent extends React.Component {' ,
2160
+ ' onFoo() {' ,
2161
+ ' this.setState((prevState, obj) => {' ,
2162
+ ' obj.doSomething();' ,
2163
+ ' });' ,
2164
+ ' }' ,
2165
+ ' render() {' ,
2166
+ ' return (' ,
2167
+ ' <div onClick={this.onFoo}>Test</div>' ,
2168
+ ' );' ,
2169
+ ' }' ,
2170
+ '}' ,
2171
+ 'MyComponent.propTypes = {' ,
2172
+ ' doSomething: PropTypes.func' ,
2173
+ '};' ,
2174
+ 'var tempVar2;'
2175
+ ] . join ( '\n' ) ,
2176
+ parser : 'babel-eslint' ,
2177
+ options : [ { skipShapeProps : false } ]
2178
+ } , {
2179
+ // issue #1506
2180
+ code : [
2181
+ 'class MyComponent extends React.Component {' ,
2182
+ ' onFoo() {' ,
2183
+ ' this.setState(() => {' ,
2184
+ ' this.props.doSomething();' ,
2185
+ ' });' ,
2186
+ ' }' ,
2187
+ ' render() {' ,
2188
+ ' return (' ,
2189
+ ' <div onClick={this.onFoo}>Test</div>' ,
2190
+ ' );' ,
2191
+ ' }' ,
2192
+ '}' ,
2193
+ 'MyComponent.propTypes = {' ,
2194
+ ' doSomething: PropTypes.func' ,
2195
+ '};' ,
2196
+ 'var tempVar;'
2197
+ ] . join ( '\n' ) ,
2198
+ parser : 'babel-eslint' ,
2199
+ options : [ { skipShapeProps : false } ]
2113
2200
} , {
2114
2201
// issue #106
2115
2202
code : `
@@ -2796,10 +2883,10 @@ ruleTester.run('no-unused-prop-types', rule, {
2796
2883
type PropsA = { a: string }
2797
2884
type PropsB = { b: string }
2798
2885
type Props = PropsA & PropsB;
2799
-
2886
+
2800
2887
class MyComponent extends React.Component {
2801
2888
props: Props;
2802
-
2889
+
2803
2890
render() {
2804
2891
return <div>{this.props.a}</div>
2805
2892
}
@@ -2818,7 +2905,7 @@ ruleTester.run('no-unused-prop-types', rule, {
2818
2905
2819
2906
class Bar extends React.Component {
2820
2907
props: Props & PropsC;
2821
-
2908
+
2822
2909
render() {
2823
2910
return <div>{this.props.foo} - {this.props.bar}</div>
2824
2911
}
@@ -2833,12 +2920,12 @@ ruleTester.run('no-unused-prop-types', rule, {
2833
2920
type PropsB = { foo: string };
2834
2921
type PropsC = { bar: string };
2835
2922
type Props = PropsB & {
2836
- zap: string
2923
+ zap: string
2837
2924
};
2838
2925
2839
2926
class Bar extends React.Component {
2840
2927
props: Props & PropsC;
2841
-
2928
+
2842
2929
render() {
2843
2930
return <div>{this.props.foo} - {this.props.bar}</div>
2844
2931
}
@@ -2853,12 +2940,12 @@ ruleTester.run('no-unused-prop-types', rule, {
2853
2940
type PropsB = { foo: string };
2854
2941
type PropsC = { bar: string };
2855
2942
type Props = {
2856
- zap: string
2943
+ zap: string
2857
2944
} & PropsB;
2858
2945
2859
2946
class Bar extends React.Component {
2860
2947
props: Props & PropsC;
2861
-
2948
+
2862
2949
render() {
2863
2950
return <div>{this.props.foo} - {this.props.bar}</div>
2864
2951
}
@@ -3716,6 +3803,28 @@ ruleTester.run('no-unused-prop-types', rule, {
3716
3803
errors : [ {
3717
3804
message : '\'lastname\' PropType is defined but prop is never used'
3718
3805
} ]
3806
+ } , {
3807
+ // issue #1506
3808
+ code : [
3809
+ 'class MyComponent extends React.Component {' ,
3810
+ ' onFoo() {' ,
3811
+ ' this.setState(({ doSomething }, props) => {' ,
3812
+ ' return { doSomething: doSomething + 1 };' ,
3813
+ ' });' ,
3814
+ ' }' ,
3815
+ ' render() {' ,
3816
+ ' return (' ,
3817
+ ' <div onClick={this.onFoo}>Test</div>' ,
3818
+ ' );' ,
3819
+ ' }' ,
3820
+ '}' ,
3821
+ 'MyComponent.propTypes = {' ,
3822
+ ' doSomething: PropTypes.func' ,
3823
+ '};'
3824
+ ] . join ( '\n' ) ,
3825
+ errors : [ {
3826
+ message : '\'doSomething\' PropType is defined but prop is never used'
3827
+ } ]
3719
3828
} , {
3720
3829
code : `
3721
3830
type Props = {
0 commit comments