From 9f49274aa72c45f1ea44992d401df1c940c14a6e Mon Sep 17 00:00:00 2001 From: Romain Marcadier-Muller Date: Sun, 26 Aug 2018 05:04:56 -0700 Subject: [PATCH] Enable `no-floating-promises` `tslint` rule (#626) This prevents the code from getting promises and not handling them appropriately, a known source of subtle bugs and race conditions. --- packages/aws-cdk/test/test.account-cache.ts | 16 ++++++++-------- packages/simple-resource-bundler/bin/bundler.ts | 2 +- tools/cdk-build-tools/bin/cdk-package.ts | 2 +- tslint.yaml | 3 +++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/aws-cdk/test/test.account-cache.ts b/packages/aws-cdk/test/test.account-cache.ts index 6a3e177cbeaad..522d85d5b6537 100644 --- a/packages/aws-cdk/test/test.account-cache.ts +++ b/packages/aws-cdk/test/test.account-cache.ts @@ -4,18 +4,18 @@ import path = require('path'); import { AccountAccessKeyCache } from '../lib/api/util/account-cache'; export = { - 'setUp'(cb: ICallbackFunction) { + async 'setUp'(cb: ICallbackFunction) { const self = this as any; - fs.mkdtemp('/tmp/account-cache-test').then(dir => { - self.file = path.join(dir, 'cache.json'); - self.cache = new AccountAccessKeyCache(self.file); - return cb(); - }); + const dir = await fs.mkdtemp('/tmp/account-cache-test'); + self.file = path.join(dir, 'cache.json'); + self.cache = new AccountAccessKeyCache(self.file); + return cb(); }, - 'tearDown'(cb: ICallbackFunction) { + async 'tearDown'(cb: ICallbackFunction) { const self = this as any; - fs.remove(path.dirname(self.file)).then(cb); + await fs.remove(path.dirname(self.file)); + cb(); }, async 'get(k) when cache is empty'(test: Test) { diff --git a/packages/simple-resource-bundler/bin/bundler.ts b/packages/simple-resource-bundler/bin/bundler.ts index 7d2ffbe82372b..a378f0501cb29 100644 --- a/packages/simple-resource-bundler/bin/bundler.ts +++ b/packages/simple-resource-bundler/bin/bundler.ts @@ -38,7 +38,7 @@ async function main() { 'export = resources;' ]; - fs.writeFile(path.join(output, 'resources.d.ts'), declContents.join('\n')); + await fs.writeFile(path.join(output, 'resources.d.ts'), declContents.join('\n')); } } diff --git a/tools/cdk-build-tools/bin/cdk-package.ts b/tools/cdk-build-tools/bin/cdk-package.ts index d9a9f18551184..30162705cbae3 100644 --- a/tools/cdk-build-tools/bin/cdk-package.ts +++ b/tools/cdk-build-tools/bin/cdk-package.ts @@ -47,7 +47,7 @@ async function main() { await fs.move(tarball, path.join(target, path.basename(tarball))); } - detector.markClean(); + await detector.markClean(); } main().then(() => { diff --git a/tslint.yaml b/tslint.yaml index 49db1839a1bb3..75284b0c1d44e 100644 --- a/tslint.yaml +++ b/tslint.yaml @@ -45,3 +45,6 @@ rules: # Without this rule, _blabla would be disallowed, which is necessary to silence unused variable errors. variable-name: [true, "ban-keywords", "check-format", "allow-leading-underscore"] + + # Unhandled promises are the source of all kinds of bugs and race conditions... + no-floating-promises: true