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