Skip to content

Commit

Permalink
refactor: no-floating-promises
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jan 2, 2024
1 parent 674fb69 commit 2e21100
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions src/resolve/connectionResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,51 +53,51 @@ export class ConnectionResolver {
const componentTypes: Set<MetadataType> = new Set();
const lifecycle = Lifecycle.getInstance();

const componentPromises = this.mdTypeNames.map((type) => this.listMembers({ type }));

(await Promise.all(componentPromises)).map(async (componentResult) => {
for (const component of componentResult) {
let componentType: MetadataType;
if (typeof component.type === 'string' && component.type.length) {
componentType = this.registry.getTypeByName(component.type);
} else if (typeof component.fileName === 'string' && component.fileName.length) {
// fix { type: { "$": { "xsi:nil": "true" } } }
componentType = ensurePlainObject(
this.registry.getTypeBySuffix(extName(component.fileName)),
`No type found for ${component.fileName} when matching by suffix. Check the file extension.`
);
component.type = componentType.name;
} else if (component.type === undefined && component.fileName === undefined) {
// has no type and has no filename! Warn and skip that component.
// eslint-disable-next-line no-await-in-loop
await Promise.all([
lifecycle.emitWarning(messages.getMessage('error_could_not_infer_type', [component.fullName])),
lifecycle.emitTelemetry({ TypeInferenceError: component, from: 'ConnectionResolver' }),
]);
continue;
} else {
// it DOES have all the important info but we couldn't resolve it.
// has no type and has no filename!
throw new SfError(
messages.getMessage('error_could_not_infer_type', [component.fullName]),
'TypeInferenceError',
[messages.getMessage('suggest_type_more_suggestions')]
);
}
const componentFromDescribe = (
await Promise.all(this.mdTypeNames.map((type) => this.listMembers({ type })))
).flat();

for (const component of componentFromDescribe) {
let componentType: MetadataType;
if (typeof component.type === 'string' && component.type.length) {
componentType = this.registry.getTypeByName(component.type);
} else if (typeof component.fileName === 'string' && component.fileName.length) {
// fix { type: { "$": { "xsi:nil": "true" } } }
componentType = ensurePlainObject(
this.registry.getTypeBySuffix(extName(component.fileName)),
`No type found for ${component.fileName} when matching by suffix. Check the file extension.`
);
component.type = componentType.name;
} else if (component.type === undefined && component.fileName === undefined) {
// has no type and has no filename! Warn and skip that component.
// eslint-disable-next-line no-await-in-loop
await Promise.all([
lifecycle.emitWarning(messages.getMessage('error_could_not_infer_type', [component.fullName])),
lifecycle.emitTelemetry({ TypeInferenceError: component, from: 'ConnectionResolver' }),
]);
continue;
} else {
// it DOES have all the important info but we couldn't resolve it.
// has no type and has no filename!
throw new SfError(
messages.getMessage('error_could_not_infer_type', [component.fullName]),
'TypeInferenceError',
[messages.getMessage('suggest_type_more_suggestions')]
);
}

Aggregator.push(component);
componentTypes.add(componentType);
const folderContentType = componentType.folderContentType;
if (folderContentType) {
childrenPromises.push(
this.listMembers({
type: this.registry.getTypeByName(folderContentType).name,
folder: component.fullName,
})
);
}
Aggregator.push(component);
componentTypes.add(componentType);
const folderContentType = componentType.folderContentType;
if (folderContentType) {
childrenPromises.push(
this.listMembers({
type: this.registry.getTypeByName(folderContentType).name,
folder: component.fullName,
})
);
}
});
}

for (const componentType of componentTypes) {
const childTypes = componentType.children?.types;
Expand Down

0 comments on commit 2e21100

Please sign in to comment.