@@ -12,13 +12,8 @@ const Components = require('../util/Components');
12
12
const docsUrl = require ( '../util/docsUrl' ) ;
13
13
const report = require ( '../util/report' ) ;
14
14
15
- function isFlowPropertyType ( node ) {
16
- return node . type === 'ObjectTypeProperty' ;
17
- }
18
-
19
- function isTypeScriptPropertyType ( node ) {
20
- return node . type === 'TSPropertySignature' ;
21
- }
15
+ const FLOW_PROPERTY_TYPE = 'ObjectTypeProperty' ;
16
+ const TYPESCRIPT_PROPERTY_TYPE = 'TSPropertySignature' ;
22
17
23
18
function isCovariant ( node ) {
24
19
return ( node . variance && node . variance . kind === 'plus' )
@@ -85,18 +80,12 @@ module.exports = {
85
80
return ;
86
81
}
87
82
88
- if ( isTypeScriptPropertyType ( prop . node ) ) {
89
- if ( ! isReadonly ( prop . node ) ) {
90
- reportReadOnlyProp ( prop , propName , ( fixer ) => (
91
- fixer . insertTextBefore ( prop . node , 'readonly ' )
92
- ) ) ;
93
- }
83
+ switch ( prop . node . type ) {
84
+ case FLOW_PROPERTY_TYPE :
85
+ if ( isCovariant ( prop . node ) ) {
86
+ break ;
87
+ }
94
88
95
- return ;
96
- }
97
-
98
- if ( isFlowPropertyType ( prop . node ) ) {
99
- if ( ! isCovariant ( prop . node ) ) {
100
89
reportReadOnlyProp ( prop , propName , ( fixer ) => {
101
90
if ( ! prop . node . variance ) {
102
91
// Insert covariance
@@ -106,7 +95,20 @@ module.exports = {
106
95
// Replace contravariance with covariance
107
96
return fixer . replaceText ( prop . node . variance , '+' ) ;
108
97
} ) ;
109
- }
98
+
99
+ break ;
100
+ case TYPESCRIPT_PROPERTY_TYPE :
101
+ if ( isReadonly ( prop . node ) ) {
102
+ break ;
103
+ }
104
+
105
+ reportReadOnlyProp ( prop , propName , ( fixer ) => (
106
+ fixer . insertTextBefore ( prop . node , 'readonly ' )
107
+ ) ) ;
108
+
109
+ break ;
110
+ default :
111
+ break ;
110
112
}
111
113
} ) ;
112
114
} ) ;
0 commit comments