Skip to content

Commit c99bd4b

Browse files
authored
Merge pull request #4 from NangoHQ/fix-double-type
remove double type produced from the enforce-proxy-configuration rule
2 parents 8181502 + 4ec1318 commit c99bd4b

File tree

1 file changed

+47
-33
lines changed

1 file changed

+47
-33
lines changed

src/rules/enforce-proxy-configuration-type.ts

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,56 +23,70 @@ const enforceProxyConfigurationType: Rule.RuleModule = {
2323
if (node.source.value === '../../models') {
2424
importNode = node;
2525
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'
3031
);
3132
}
3233
},
3334
VariableDeclaration(node: VariableDeclaration) {
3435
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+
) {
3843
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+
) {
4352
configVariableName = declarator.id.name;
4453
configNode = node;
4554
}
4655
}
4756
},
4857
'Program:exit'() {
4958
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;
5560

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;
6263

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+
);
7084
}
71-
}
7285

73-
return fixes;
74-
},
75-
});
86+
return fixes;
87+
},
88+
});
89+
}
7690
}
7791
},
7892
};

0 commit comments

Comments
 (0)