Skip to content

Commit

Permalink
refactor: fix no-floating-promises linter rule (#1201)
Browse files Browse the repository at this point in the history
* refactor: no-floating-promises

* chore: happy new year
  • Loading branch information
mshanemc authored Jan 3, 2024
1 parent 674fb69 commit a3a9fdd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023, Salesforce.com, Inc.
Copyright (c) 2024, Salesforce.com, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
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 a3a9fdd

Please sign in to comment.