@@ -12,8 +12,13 @@ const Components = require('../util/Components');
1212const docsUrl = require ( '../util/docsUrl' ) ;
1313const report = require ( '../util/report' ) ;
1414
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+ }
1722
1823function isCovariant ( node ) {
1924 return ( node . variance && node . variance . kind === 'plus' )
@@ -80,12 +85,8 @@ module.exports = {
8085 return ;
8186 }
8287
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 ) ) {
8990 reportReadOnlyProp ( prop , propName , ( fixer ) => {
9091 if ( ! prop . node . variance ) {
9192 // Insert covariance
@@ -95,20 +96,17 @@ module.exports = {
9596 // Replace contravariance with covariance
9697 return fixer . replaceText ( prop . node . variance , '+' ) ;
9798 } ) ;
99+ }
98100
99- break ;
100- case TYPESCRIPT_PROPERTY_TYPE :
101- if ( isReadonly ( prop . node ) ) {
102- break ;
103- }
101+ return ;
102+ }
104103
104+ if ( isTypescriptPropertyType ( prop . node ) ) {
105+ if ( ! isReadonly ( prop . node ) ) {
105106 reportReadOnlyProp ( prop , propName , ( fixer ) => (
106107 fixer . insertTextBefore ( prop . node , 'readonly ' )
107108 ) ) ;
108-
109- break ;
110- default :
111- break ;
109+ }
112110 }
113111 } ) ;
114112 } ) ;
0 commit comments