@@ -23,56 +23,70 @@ const enforceProxyConfigurationType: Rule.RuleModule = {
23
23
if ( node . source . value === '../../models' ) {
24
24
importNode = node ;
25
25
hasProxyConfigurationImport = node . specifiers . some (
26
- ( specifier ) => specifier . type === 'ImportSpecifier' &&
27
- 'imported' in specifier &&
28
- specifier . imported . type === 'Identifier' &&
29
- specifier . imported . name === 'ProxyConfiguration'
26
+ ( specifier ) =>
27
+ specifier . type === 'ImportSpecifier' &&
28
+ 'imported' in specifier &&
29
+ specifier . imported . type === 'Identifier' &&
30
+ specifier . imported . name === 'ProxyConfiguration'
30
31
) ;
31
32
}
32
33
} ,
33
34
VariableDeclaration ( node : VariableDeclaration ) {
34
35
const declarator = node . declarations [ 0 ] as VariableDeclarator ;
35
- if ( declarator && declarator . type === 'VariableDeclarator' &&
36
- declarator . id . type === 'Identifier' && declarator . init &&
37
- declarator . init . type === 'ObjectExpression' ) {
36
+ if (
37
+ declarator &&
38
+ declarator . type === 'VariableDeclarator' &&
39
+ declarator . id . type === 'Identifier' &&
40
+ declarator . init &&
41
+ declarator . init . type === 'ObjectExpression'
42
+ ) {
38
43
const properties = declarator . init . properties ;
39
- if ( properties . some ( ( prop ) : prop is Property =>
40
- prop . type === 'Property' &&
41
- prop . key . type === 'Identifier' &&
42
- prop . key . name === 'endpoint' ) ) {
44
+ if (
45
+ properties . some (
46
+ ( prop ) : prop is Property =>
47
+ prop . type === 'Property' &&
48
+ prop . key . type === 'Identifier' &&
49
+ prop . key . name === 'endpoint'
50
+ )
51
+ ) {
43
52
configVariableName = declarator . id . name ;
44
53
configNode = node ;
45
54
}
46
55
}
47
56
} ,
48
57
'Program:exit' ( ) {
49
58
if ( configVariableName && ! hasProxyConfigurationImport && importNode && configNode ) {
50
- context . report ( {
51
- node : context . getSourceCode ( ) . ast ,
52
- message : 'ProxyConfiguration type should be imported and used for Nango API call configurations' ,
53
- fix ( fixer ) {
54
- const fixes = [ ] ;
59
+ const declarator = configNode . declarations [ 0 ] as VariableDeclarator ;
55
60
56
- if ( importNode && importNode . specifiers . length > 0 ) {
57
- fixes . push ( fixer . insertTextAfter (
58
- importNode . specifiers [ importNode . specifiers . length - 1 ] ,
59
- ', ProxyConfiguration'
60
- ) ) ;
61
- }
61
+ const hasTypeAnnotation =
62
+ 'typeAnnotation' in declarator . id && ! ! ( declarator . id as any ) . typeAnnotation ;
62
63
63
- if ( configNode && configNode . declarations . length > 0 ) {
64
- const configDeclarator = configNode . declarations [ 0 ] as VariableDeclarator ;
65
- if ( configDeclarator && configDeclarator . id . type === 'Identifier' ) {
66
- fixes . push ( fixer . insertTextAfter (
67
- configDeclarator . id ,
68
- ': ProxyConfiguration'
69
- ) ) ;
64
+ if ( declarator . id . type === 'Identifier' && ! hasTypeAnnotation ) {
65
+ context . report ( {
66
+ node : context . getSourceCode ( ) . ast ,
67
+ message : 'ProxyConfiguration type should be imported and used for Nango API call configurations' ,
68
+ fix ( fixer ) {
69
+ const fixes = [ ] ;
70
+
71
+ if ( importNode && importNode . specifiers . length > 0 ) {
72
+ fixes . push (
73
+ fixer . insertTextAfter (
74
+ importNode . specifiers [ importNode . specifiers . length - 1 ] ,
75
+ ', ProxyConfiguration'
76
+ )
77
+ ) ;
78
+ }
79
+
80
+ if ( declarator && declarator . id . type === 'Identifier' ) {
81
+ fixes . push (
82
+ fixer . insertTextAfter ( declarator . id , ': ProxyConfiguration' )
83
+ ) ;
70
84
}
71
- }
72
85
73
- return fixes ;
74
- } ,
75
- } ) ;
86
+ return fixes ;
87
+ } ,
88
+ } ) ;
89
+ }
76
90
}
77
91
} ,
78
92
} ;
0 commit comments