Skip to content

Commit f1c42aa

Browse files
committed
Add no-floating-promises options to tslint in order to ensure all promises are properly handled
1 parent f73ec8e commit f1c42aa

10 files changed

+18
-18
lines changed

lib/helpers/livesync-command-helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
157157

158158
await this.$platformService.deployPlatform(deployPlatformInfo);
159159
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, { appId: this.$projectData.projectId, projectName: this.$projectData.projectName });
160-
this.$platformService.trackProjectType(this.$projectData);
160+
await this.$platformService.trackProjectType(this.$projectData);
161161
}
162162
}
163163
}

lib/nativescript-cli.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ installUncaughtExceptionListener(process.exit.bind(process, ErrorCodes.UNCAUGHT)
88

99
import { settlePromises } from "./common/helpers";
1010

11+
/* tslint:disable:no-floating-promises */
1112
(async () => {
1213
const config: Config.IConfig = $injector.resolve("$config");
1314
const err: IErrors = $injector.resolve("$errors");
@@ -42,3 +43,4 @@ import { settlePromises } from "./common/helpers";
4243

4344
$injector.dispose();
4445
})();
46+
/* tslint:enable:no-floating-promises */

lib/services/analytics/analytics-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class AnalyticsService extends AnalyticsServiceBase {
4444
}
4545

4646
public async trackAcceptFeatureUsage(settings: { acceptTrackFeatureUsage: boolean }): Promise<void> {
47-
this.sendMessageToBroker(<IAcceptUsageReportingInformation>{
47+
await this.sendMessageToBroker(<IAcceptUsageReportingInformation>{
4848
type: TrackingTypes.AcceptTrackFeatureUsage,
4949
acceptTrackFeatureUsage: settings.acceptTrackFeatureUsage
5050
});

lib/services/android-project-service.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
126126
this.$androidToolsInfo.validateTargetSdk({ showWarningsAsErrors: true });
127127
}
128128

129-
public async validatePlugins(): Promise<void> {
130-
Promise.resolve();
131-
}
129+
public async validatePlugins(): Promise<void> { /* */ }
132130

133131
public async createProject(frameworkDir: string, frameworkVersion: string, projectData: IProjectData, config: ICreateProjectOptions): Promise<void> {
134132
if (semver.lt(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) {

lib/services/ios-project-service.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
380380
this.$errors.failWithoutHelp(`${pluginData.name} has Podfile and you don't have Cocoapods installed or it is not configured correctly. Please verify Cocoapods can work on your machine.`);
381381
}
382382
}
383-
Promise.resolve();
384383
}
385384

386385
private async buildForDevice(projectRoot: string, args: string[], buildConfig: IBuildConfig, projectData: IProjectData): Promise<void> {
@@ -1024,9 +1023,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
10241023
}
10251024
}
10261025

1027-
public async prebuildNativePlugin(options: IBuildOptions): Promise<void> {
1028-
Promise.resolve();
1029-
}
1026+
public async prebuildNativePlugin(options: IBuildOptions): Promise<void> { /** */ }
10301027

10311028
public async checkIfPluginsNeedBuild(projectData: IProjectData): Promise<Array<any>> {
10321029
return [];

lib/services/livesync/livesync-service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,9 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
685685
this.$processService.attachToProcessExitSignals(this, () => {
686686
_.keys(this.liveSyncProcessesInfo).forEach(projectDir => {
687687
// Do not await here, we are in process exit's handler.
688+
/* tslint:disable:no-floating-promises */
688689
this.stopLiveSync(projectDir);
690+
/* tslint:enable:no-floating-promises */
689691
});
690692
});
691693
}

lib/services/plugins-service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class PluginsService implements IPluginsService {
5757
this.isPluginDataValidForPlatform(pluginData, platform, projectData);
5858
};
5959

60-
this.executeForAllInstalledPlatforms(action, projectData);
60+
await this.executeForAllInstalledPlatforms(action, projectData);
6161

6262
try {
6363
await this.$pluginVariablesService.savePluginVariablesInProjectFile(pluginData, projectData);
@@ -84,7 +84,7 @@ export class PluginsService implements IPluginsService {
8484
};
8585

8686
this.$pluginVariablesService.removePluginVariablesFromProjectFile(pluginName.toLowerCase(), projectData);
87-
this.executeForAllInstalledPlatforms(removePluginNativeCodeAction, projectData);
87+
await this.executeForAllInstalledPlatforms(removePluginNativeCodeAction, projectData);
8888

8989
await this.executeNpmCommand(PluginsService.UNINSTALL_COMMAND_NAME, pluginName, projectData);
9090

@@ -96,7 +96,7 @@ export class PluginsService implements IPluginsService {
9696
showMessage = false;
9797
};
9898

99-
this.executeForAllInstalledPlatforms(action, projectData);
99+
await this.executeForAllInstalledPlatforms(action, projectData);
100100

101101
if (showMessage) {
102102
this.$logger.out(`Successfully removed plugin ${pluginName}`);

test/services/ios-log-parser-service.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe("iOSLogParserService", () => {
8888
const emittedMessagesCount = 1;
8989
const promise = attachOnDebuggerFoundEvent(emittedMessagesCount);
9090

91-
iOSLogParserService.startParsingLog(device, mockProjectNameObj);
91+
await iOSLogParserService.startParsingLog(device, mockProjectNameObj);
9292
emitDeviceLog("test message");
9393
emitDeviceLog(getDebuggerPortMessage(18181));
9494

@@ -101,7 +101,7 @@ describe("iOSLogParserService", () => {
101101
const emittedMessagesCount = 5;
102102
const promise = attachOnDebuggerFoundEvent(emittedMessagesCount);
103103

104-
iOSLogParserService.startParsingLog(device, mockProjectNameObj);
104+
await iOSLogParserService.startParsingLog(device, mockProjectNameObj);
105105
emitDeviceLog(getDebuggerPortMessage(18181));
106106
emitDeviceLog(getDebuggerPortMessage(18181));
107107
emitDeviceLog(getDebuggerPortMessage(18181));
@@ -121,7 +121,7 @@ describe("iOSLogParserService", () => {
121121
const emittedMessagesCount = 5;
122122
const promise = attachOnDebuggerFoundEvent(emittedMessagesCount);
123123

124-
iOSLogParserService.startParsingLog(device, mockProjectNameObj);
124+
await iOSLogParserService.startParsingLog(device, mockProjectNameObj);
125125
emitDeviceLog(getDebuggerPortMessage(45898));
126126
emitDeviceLog(getDebuggerPortMessage(1809));
127127
emitDeviceLog(getDebuggerPortMessage(65072));
@@ -137,12 +137,12 @@ describe("iOSLogParserService", () => {
137137
assert.deepEqual(data[3], { port: 12345, deviceId: deviceId, appId: appId });
138138
assert.deepEqual(data[4], { port: 18181, deviceId: deviceId, appId: appId });
139139
});
140-
it(`should not receive ${DEBUGGER_PORT_FOUND_EVENT_NAME} event when debugger port message is not emitted`, () => {
140+
it(`should not receive ${DEBUGGER_PORT_FOUND_EVENT_NAME} event when debugger port message is not emitted`, async () => {
141141
let isDebuggedPortFound = false;
142142

143143
iOSLogParserService.on(DEBUGGER_PORT_FOUND_EVENT_NAME, (data: IIOSDebuggerPortData) => isDebuggedPortFound = true);
144144

145-
iOSLogParserService.startParsingLog(device, mockProjectNameObj);
145+
await iOSLogParserService.startParsingLog(device, mockProjectNameObj);
146146
emitDeviceLog("some test message");
147147
emitDeviceLog("another test message");
148148

tslint.json

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"check-open-brace",
3636
"check-whitespace"
3737
],
38+
"no-floating-promises": true,
3839
"quotemark": [
3940
false,
4041
"double"

0 commit comments

Comments
 (0)