Skip to content

Commit

Permalink
refactor: simplify getProviderType code
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagomini committed Feb 21, 2024
1 parent 93553a2 commit 51a7e69
Showing 1 changed file with 12 additions and 34 deletions.
46 changes: 12 additions & 34 deletions src/rules/enforce-custom-provider-type.rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,40 +146,18 @@ function getProviderType(node: TSESTree.Identifier): ProviderType | undefined {
if (init?.type === AST_NODE_TYPES.ObjectExpression) {
const properties = init.properties;
for (const property of properties) {
if (
property.type === AST_NODE_TYPES.Property &&
ASTUtils.isIdentifier(property.key) &&
property.key.name === 'useFactory'
) {
type = 'factory';
break;
}

if (
property.type === AST_NODE_TYPES.Property &&
ASTUtils.isIdentifier(property.key) &&
property.key.name === 'useClass'
) {
type = 'class';
break;
}

if (
property.type === AST_NODE_TYPES.Property &&
ASTUtils.isIdentifier(property.key) &&
property.key.name === 'useValue'
) {
type = 'value';
break;
}

if (
property.type === AST_NODE_TYPES.Property &&
ASTUtils.isIdentifier(property.key) &&
property.key.name === 'useExisting'
) {
type = 'existing';
break;
if (property.type === AST_NODE_TYPES.Property) {
const propertyKey = (property.key as TSESTree.Identifier)?.name;
type =
propertyKey === 'useClass'
? 'class'
: propertyKey === 'useFactory'
? 'factory'
: propertyKey === 'useValue'
? 'value'
: propertyKey === 'useExisting'
? 'existing'
: undefined;
}
}
}
Expand Down

0 comments on commit 51a7e69

Please sign in to comment.