Skip to content

Commit f25bccb

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

9 files changed

+17
-17
lines changed

lib/helpers/livesync-command-helper.ts

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

163163
await this.$platformService.deployPlatform(deployPlatformInfo);
164164
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, { appId: this.$projectData.projectId, projectName: this.$projectData.projectName });
165-
this.$platformService.trackProjectType(this.$projectData);
165+
await this.$platformService.trackProjectType(this.$projectData);
166166
}
167167
}
168168
}

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> {
@@ -1032,9 +1031,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
10321031
}
10331032
}
10341033

1035-
public async prebuildNativePlugin(options: IBuildOptions): Promise<void> {
1036-
Promise.resolve();
1037-
}
1034+
public async prebuildNativePlugin(options: IBuildOptions): Promise<void> { /** */ }
10381035

10391036
public async checkIfPluginsNeedBuild(projectData: IProjectData): Promise<Array<any>> {
10401037
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
@@ -58,7 +58,7 @@ export class PluginsService implements IPluginsService {
5858
this.isPluginDataValidForPlatform(pluginData, platform, projectData);
5959
};
6060

61-
this.executeForAllInstalledPlatforms(action, projectData);
61+
await this.executeForAllInstalledPlatforms(action, projectData);
6262

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

8787
this.$pluginVariablesService.removePluginVariablesFromProjectFile(pluginName.toLowerCase(), projectData);
88-
this.executeForAllInstalledPlatforms(removePluginNativeCodeAction, projectData);
88+
await this.executeForAllInstalledPlatforms(removePluginNativeCodeAction, projectData);
8989

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

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

100-
this.executeForAllInstalledPlatforms(action, projectData);
100+
await this.executeForAllInstalledPlatforms(action, projectData);
101101

102102
if (showMessage) {
103103
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)