Skip to content

Add no-floating-promises options to tslint in order to ensure all promises are properly handled #3762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/helpers/livesync-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {

await this.$platformService.deployPlatform(deployPlatformInfo);
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, { appId: this.$projectData.projectId, projectName: this.$projectData.projectName });
this.$platformService.trackProjectType(this.$projectData);
await this.$platformService.trackProjectType(this.$projectData);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/nativescript-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ installUncaughtExceptionListener(process.exit.bind(process, ErrorCodes.UNCAUGHT)

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

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

$injector.dispose();
})();
/* tslint:enable:no-floating-promises */
2 changes: 1 addition & 1 deletion lib/services/analytics/analytics-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class AnalyticsService extends AnalyticsServiceBase {
}

public async trackAcceptFeatureUsage(settings: { acceptTrackFeatureUsage: boolean }): Promise<void> {
this.sendMessageToBroker(<IAcceptUsageReportingInformation>{
await this.sendMessageToBroker(<IAcceptUsageReportingInformation>{
type: TrackingTypes.AcceptTrackFeatureUsage,
acceptTrackFeatureUsage: settings.acceptTrackFeatureUsage
});
Expand Down
4 changes: 1 addition & 3 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
this.$androidToolsInfo.validateTargetSdk({ showWarningsAsErrors: true });
}

public async validatePlugins(): Promise<void> {
Promise.resolve();
}
public async validatePlugins(): Promise<void> { /* */ }

public async createProject(frameworkDir: string, frameworkVersion: string, projectData: IProjectData, config: ICreateProjectOptions): Promise<void> {
if (semver.lt(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) {
Expand Down
5 changes: 1 addition & 4 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
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.`);
}
}
Promise.resolve();
}

private async buildForDevice(projectRoot: string, args: string[], buildConfig: IBuildConfig, projectData: IProjectData): Promise<void> {
Expand Down Expand Up @@ -1032,9 +1031,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
}
}

public async prebuildNativePlugin(options: IBuildOptions): Promise<void> {
Promise.resolve();
}
public async prebuildNativePlugin(options: IBuildOptions): Promise<void> { /** */ }

public async checkIfPluginsNeedBuild(projectData: IProjectData): Promise<Array<any>> {
return [];
Expand Down
2 changes: 2 additions & 0 deletions lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,9 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
this.$processService.attachToProcessExitSignals(this, () => {
_.keys(this.liveSyncProcessesInfo).forEach(projectDir => {
// Do not await here, we are in process exit's handler.
/* tslint:disable:no-floating-promises */
this.stopLiveSync(projectDir);
/* tslint:enable:no-floating-promises */
});
});
}
Expand Down
6 changes: 3 additions & 3 deletions lib/services/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class PluginsService implements IPluginsService {
this.isPluginDataValidForPlatform(pluginData, platform, projectData);
};

this.executeForAllInstalledPlatforms(action, projectData);
await this.executeForAllInstalledPlatforms(action, projectData);

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

this.$pluginVariablesService.removePluginVariablesFromProjectFile(pluginName.toLowerCase(), projectData);
this.executeForAllInstalledPlatforms(removePluginNativeCodeAction, projectData);
await this.executeForAllInstalledPlatforms(removePluginNativeCodeAction, projectData);

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

Expand All @@ -97,7 +97,7 @@ export class PluginsService implements IPluginsService {
showMessage = false;
};

this.executeForAllInstalledPlatforms(action, projectData);
await this.executeForAllInstalledPlatforms(action, projectData);

if (showMessage) {
this.$logger.out(`Successfully removed plugin ${pluginName}`);
Expand Down
10 changes: 5 additions & 5 deletions test/services/ios-log-parser-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("iOSLogParserService", () => {
const emittedMessagesCount = 1;
const promise = attachOnDebuggerFoundEvent(emittedMessagesCount);

iOSLogParserService.startParsingLog(device, mockProjectNameObj);
await iOSLogParserService.startParsingLog(device, mockProjectNameObj);
emitDeviceLog("test message");
emitDeviceLog(getDebuggerPortMessage(18181));

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

iOSLogParserService.startParsingLog(device, mockProjectNameObj);
await iOSLogParserService.startParsingLog(device, mockProjectNameObj);
emitDeviceLog(getDebuggerPortMessage(18181));
emitDeviceLog(getDebuggerPortMessage(18181));
emitDeviceLog(getDebuggerPortMessage(18181));
Expand All @@ -121,7 +121,7 @@ describe("iOSLogParserService", () => {
const emittedMessagesCount = 5;
const promise = attachOnDebuggerFoundEvent(emittedMessagesCount);

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

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

iOSLogParserService.startParsingLog(device, mockProjectNameObj);
await iOSLogParserService.startParsingLog(device, mockProjectNameObj);
emitDeviceLog("some test message");
emitDeviceLog("another test message");

Expand Down
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"check-open-brace",
"check-whitespace"
],
"no-floating-promises": true,
"quotemark": [
false,
"double"
Expand Down