From 9beb3a555cd617ec82a15767f44aa3e67abe59d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 24 Jun 2019 10:17:15 +0200 Subject: [PATCH 1/2] feat(eslint-config): enable "no-floating-promises" rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- packages/eslint-config/eslintrc.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/eslint-config/eslintrc.js b/packages/eslint-config/eslintrc.js index 4debac0c64f8..b4a7cd369159 100644 --- a/packages/eslint-config/eslintrc.js +++ b/packages/eslint-config/eslintrc.js @@ -134,9 +134,7 @@ module.exports = { // Rules mapped from `@loopback/tslint-config/tslint.build.json '@typescript-eslint/await-thenable': 'error', // tslint:await-promise: [true, 'PromiseLike', 'RequestPromise'], - - // See https://github.com/typescript-eslint/typescript-eslint/issues/464 - // tslint:no-floating-promises: [true, 'PromiseLike', 'RequestPromise'], + '@typescript-eslint/no-floating-promises': 'error', 'no-void': 'error', // tslint:no-void-expression: [true, 'ignore-arrow-function-shorthand'], }, From 00bcbbaa1ce4ee9860281addee4474d524d9a088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 24 Jun 2019 10:29:21 +0200 Subject: [PATCH 2/2] fix: address violations of "no-floating-promises" rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- bin/run-lerna.js | 7 ++++++- bin/sync-dev-deps.js | 7 ++++++- bin/update-template-deps.js | 7 ++++++- examples/context/src/binding-types.ts | 7 ++++++- examples/context/src/configuration-injection.ts | 7 ++++++- examples/context/src/context-chain.ts | 7 ++++++- examples/context/src/context-observation.ts | 7 ++++++- examples/context/src/custom-configuration-resolver.ts | 7 ++++++- examples/context/src/custom-inject-decorator.ts | 7 ++++++- examples/context/src/custom-inject-resolve.ts | 7 ++++++- examples/context/src/dependency-injection.ts | 7 ++++++- examples/context/src/find-bindings.ts | 7 ++++++- examples/context/src/index.ts | 5 ++++- examples/context/src/injection-without-binding.ts | 7 ++++++- examples/context/src/interceptor-proxy.ts | 7 ++++++- examples/context/src/parameterized-decoration.ts | 7 ++++++- examples/context/src/sync-async.ts | 7 ++++++- examples/context/src/value-promise.ts | 7 ++++++- examples/greeter-extension/index.js | 5 ++++- packages/cli/bin/download-connector-list.js | 5 ++++- packages/context/src/__tests__/unit/resolver.unit.ts | 2 ++ packages/context/src/__tests__/unit/value-promise.unit.ts | 1 + .../src/__tests__/unit/filter-json-schema.unit.ts | 7 +++++++ .../__tests__/acceptance/sequence/sequence.acceptance.ts | 6 +++--- packages/tsdocs/bin/extract-apis.js | 5 ++++- packages/tsdocs/bin/update-apidocs.js | 5 ++++- 26 files changed, 135 insertions(+), 25 deletions(-) diff --git a/bin/run-lerna.js b/bin/run-lerna.js index 91bfa11b0890..3586058f5280 100755 --- a/bin/run-lerna.js +++ b/bin/run-lerna.js @@ -25,4 +25,9 @@ async function run(argv, options) { } module.exports = run; -if (require.main === module) run(process.argv); +if (require.main === module) { + run(process.argv).catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/bin/sync-dev-deps.js b/bin/sync-dev-deps.js index 7f23e201177f..a8e30feac054 100755 --- a/bin/sync-dev-deps.js +++ b/bin/sync-dev-deps.js @@ -87,7 +87,12 @@ function updatePackageJson(pkgFile, masterDeps) { return true; } -if (require.main === module) syncDevDeps(); +if (require.main === module) { + syncDevDeps().catch(err => { + console.error(err); + process.exit(1); + }); +} function readPackageJson(filePath) { return JSON.parse(fs.readFileSync(filePath, 'utf-8')); diff --git a/bin/update-template-deps.js b/bin/update-template-deps.js index b37a2a7a885a..b9c362903b15 100755 --- a/bin/update-template-deps.js +++ b/bin/update-template-deps.js @@ -63,4 +63,9 @@ async function updateTemplateDeps() { } } -if (require.main === module) updateTemplateDeps(); +if (require.main === module) { + updateTemplateDeps().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/binding-types.ts b/examples/context/src/binding-types.ts index f0ae54e38c19..9a72dd017e14 100644 --- a/examples/context/src/binding-types.ts +++ b/examples/context/src/binding-types.ts @@ -96,4 +96,9 @@ export async function main() { console.log(greeter.hello()); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/configuration-injection.ts b/examples/context/src/configuration-injection.ts index 8dd12cf2ec98..71143713bf68 100644 --- a/examples/context/src/configuration-injection.ts +++ b/examples/context/src/configuration-injection.ts @@ -46,4 +46,9 @@ export async function main() { console.log(greeter.greet('Ray')); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/context-chain.ts b/examples/context/src/context-chain.ts index 3d08cbd5489d..e66db933feb5 100644 --- a/examples/context/src/context-chain.ts +++ b/examples/context/src/context-chain.ts @@ -44,4 +44,9 @@ export async function main() { console.log(greeter.greet('John')); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/context-observation.ts b/examples/context/src/context-observation.ts index 484e0b22dab5..88b8d71f405f 100644 --- a/examples/context/src/context-observation.ts +++ b/examples/context/src/context-observation.ts @@ -88,4 +88,9 @@ export async function main() { await requestCtx.waitUntilObserversNotified(); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/custom-configuration-resolver.ts b/examples/context/src/custom-configuration-resolver.ts index 9ba45d9ce89c..bfe24be8135d 100644 --- a/examples/context/src/custom-configuration-resolver.ts +++ b/examples/context/src/custom-configuration-resolver.ts @@ -77,4 +77,9 @@ export async function main() { console.log(barConfig); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/custom-inject-decorator.ts b/examples/context/src/custom-inject-decorator.ts index 8b6a519ea8ba..477ba5aa10f7 100644 --- a/examples/context/src/custom-inject-decorator.ts +++ b/examples/context/src/custom-inject-decorator.ts @@ -33,4 +33,9 @@ export async function main() { console.log(greeter.hello()); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/custom-inject-resolve.ts b/examples/context/src/custom-inject-resolve.ts index 3d902f1f2149..ac5226a091fb 100644 --- a/examples/context/src/custom-inject-resolve.ts +++ b/examples/context/src/custom-inject-resolve.ts @@ -52,4 +52,9 @@ export async function main() { console.log(greeter.hello()); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/dependency-injection.ts b/examples/context/src/dependency-injection.ts index eb8a468c0e13..baafc7d1a72f 100644 --- a/examples/context/src/dependency-injection.ts +++ b/examples/context/src/dependency-injection.ts @@ -138,4 +138,9 @@ export async function main() { console.log(greeting); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/find-bindings.ts b/examples/context/src/find-bindings.ts index 303dbd48377a..df8e2ddfe003 100644 --- a/examples/context/src/find-bindings.ts +++ b/examples/context/src/find-bindings.ts @@ -75,4 +75,9 @@ export async function main() { console.log(view.bindings.map(b => b.key)); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/index.ts b/examples/context/src/index.ts index d42616994e73..71e1cd7c1a50 100644 --- a/examples/context/src/index.ts +++ b/examples/context/src/index.ts @@ -27,5 +27,8 @@ export async function main() { if (require.main === module) { process.env.FOO = JSON.stringify({bar: 'xyz'}); - main(); + main().catch(err => { + console.error(err); + process.exit(1); + }); } diff --git a/examples/context/src/injection-without-binding.ts b/examples/context/src/injection-without-binding.ts index 3b7124842b7f..0c071039d896 100644 --- a/examples/context/src/injection-without-binding.ts +++ b/examples/context/src/injection-without-binding.ts @@ -36,4 +36,9 @@ export async function main() { await sayHello(ctx); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/interceptor-proxy.ts b/examples/context/src/interceptor-proxy.ts index 94d81deed9bc..27a0c839ab8e 100644 --- a/examples/context/src/interceptor-proxy.ts +++ b/examples/context/src/interceptor-proxy.ts @@ -109,4 +109,9 @@ export async function main() { console.log(await greeter!.greet('John')); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/parameterized-decoration.ts b/examples/context/src/parameterized-decoration.ts index f6e9704aa18d..8652739042d5 100644 --- a/examples/context/src/parameterized-decoration.ts +++ b/examples/context/src/parameterized-decoration.ts @@ -63,4 +63,9 @@ export async function main() { console.log('2: %s', greeting2.hello()); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/sync-async.ts b/examples/context/src/sync-async.ts index 3d5be1b3afc1..8546584e238a 100644 --- a/examples/context/src/sync-async.ts +++ b/examples/context/src/sync-async.ts @@ -76,4 +76,9 @@ export async function main() { await greetWithAsyncUser(ctx); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/context/src/value-promise.ts b/examples/context/src/value-promise.ts index db12f438bda9..a53a62836067 100644 --- a/examples/context/src/value-promise.ts +++ b/examples/context/src/value-promise.ts @@ -121,4 +121,9 @@ async function greetFromAll(greetersView: ContextView) { await transformValueOrPromise(greetingsByLanguage, console.log); } -if (require.main === module) main(); +if (require.main === module) { + main().catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/examples/greeter-extension/index.js b/examples/greeter-extension/index.js index 48d02ab26626..69c1a955988c 100644 --- a/examples/greeter-extension/index.js +++ b/examples/greeter-extension/index.js @@ -7,5 +7,8 @@ module.exports = require('./dist'); if (require.main === module) { const app = new module.exports.GreetingApplication(); - app.main(); + app.main().catch(err => { + console.error(err); + process.exit(1); + }); } diff --git a/packages/cli/bin/download-connector-list.js b/packages/cli/bin/download-connector-list.js index 706696655f5c..3208d7420a99 100644 --- a/packages/cli/bin/download-connector-list.js +++ b/packages/cli/bin/download-connector-list.js @@ -51,4 +51,7 @@ async function download() { await writeFileAsync(DEST, JSON.stringify(out, null, 2)); } -download(); +download().catch(err => { + console.error(err); + process.exit(1); +}); diff --git a/packages/context/src/__tests__/unit/resolver.unit.ts b/packages/context/src/__tests__/unit/resolver.unit.ts index 8aef86df2ad9..1983f3b0b6d1 100644 --- a/packages/context/src/__tests__/unit/resolver.unit.ts +++ b/packages/context/src/__tests__/unit/resolver.unit.ts @@ -56,6 +56,7 @@ describe('constructor injection', () => { } expect(() => { + // eslint-disable-next-line @typescript-eslint/no-floating-promises instantiateClass(TestClass, ctx); }).to.throw(/Cannot resolve injected arguments/); }); @@ -383,6 +384,7 @@ describe('property injection', () => { } expect(() => { + // eslint-disable-next-line @typescript-eslint/no-floating-promises instantiateClass(TestClass, ctx); }).to.throw(/Cannot resolve injected property/); }); diff --git a/packages/context/src/__tests__/unit/value-promise.unit.ts b/packages/context/src/__tests__/unit/value-promise.unit.ts index afa226a2c36c..7368bed874a0 100644 --- a/packages/context/src/__tests__/unit/value-promise.unit.ts +++ b/packages/context/src/__tests__/unit/value-promise.unit.ts @@ -26,6 +26,7 @@ describe('tryWithFinally', () => { let finalActionInvoked = false; const action = () => 1; const finalAction = () => (finalActionInvoked = true); + // eslint-disable-next-line @typescript-eslint/no-floating-promises tryWithFinally(action, finalAction); expect(finalActionInvoked).to.be.true(); }); diff --git a/packages/repository-json-schema/src/__tests__/unit/filter-json-schema.unit.ts b/packages/repository-json-schema/src/__tests__/unit/filter-json-schema.unit.ts index d4a3ea3d7374..3aeffa113bc9 100644 --- a/packages/repository-json-schema/src/__tests__/unit/filter-json-schema.unit.ts +++ b/packages/repository-json-schema/src/__tests__/unit/filter-json-schema.unit.ts @@ -51,6 +51,7 @@ describe('getFilterJsonSchemaFor', () => { it('describes "where" as an object', () => { const filter = {where: 'invalid-where'}; + // eslint-disable-next-line @typescript-eslint/no-floating-promises ajv.validate(customerFilterSchema, filter); expect(ajv.errors || []).to.containDeep([ { @@ -63,6 +64,7 @@ describe('getFilterJsonSchemaFor', () => { it('describes "fields" as an object', () => { const filter = {fields: 'invalid-fields'}; + // eslint-disable-next-line @typescript-eslint/no-floating-promises ajv.validate(customerFilterSchema, filter); expect(ajv.errors || []).to.containDeep([ { @@ -75,6 +77,7 @@ describe('getFilterJsonSchemaFor', () => { it('describes "include" as an array for models with relations', () => { const filter = {include: 'invalid-include'}; + // eslint-disable-next-line @typescript-eslint/no-floating-promises ajv.validate(customerFilterSchema, filter); expect(ajv.errors || []).to.containDeep([ { @@ -92,6 +95,7 @@ describe('getFilterJsonSchemaFor', () => { it('describes "offset" as an integer', () => { const filter = {offset: 'invalid-offset'}; + // eslint-disable-next-line @typescript-eslint/no-floating-promises ajv.validate(customerFilterSchema, filter); expect(ajv.errors || []).to.containDeep([ { @@ -104,6 +108,7 @@ describe('getFilterJsonSchemaFor', () => { it('describes "limit" as an integer', () => { const filter = {limit: 'invalid-limit'}; + // eslint-disable-next-line @typescript-eslint/no-floating-promises ajv.validate(customerFilterSchema, filter); expect(ajv.errors || []).to.containDeep([ { @@ -116,6 +121,7 @@ describe('getFilterJsonSchemaFor', () => { it('describes "skip" as an integer', () => { const filter = {skip: 'invalid-skip'}; + // eslint-disable-next-line @typescript-eslint/no-floating-promises ajv.validate(customerFilterSchema, filter); expect(ajv.errors || []).to.containDeep([ { @@ -128,6 +134,7 @@ describe('getFilterJsonSchemaFor', () => { it('describes "order" as an array', () => { const filter = {order: 'invalid-order'}; + // eslint-disable-next-line @typescript-eslint/no-floating-promises ajv.validate(customerFilterSchema, filter); expect(ajv.errors || []).to.containDeep([ { diff --git a/packages/rest/src/__tests__/acceptance/sequence/sequence.acceptance.ts b/packages/rest/src/__tests__/acceptance/sequence/sequence.acceptance.ts index 61a40b933b94..fa0c996452a7 100644 --- a/packages/rest/src/__tests__/acceptance/sequence/sequence.acceptance.ts +++ b/packages/rest/src/__tests__/acceptance/sequence/sequence.acceptance.ts @@ -38,7 +38,7 @@ describe('Sequence', () => { let server: RestServer; beforeEach(givenAppWithController); it('provides a default sequence', async () => { - whenIRequest() + await whenIRequest() .get('/name') .expect('SequenceApp'); }); @@ -52,7 +52,7 @@ describe('Sequence', () => { .expect('hello world'); }); - it('allows users to define a custom sequence as a class', () => { + it('allows users to define a custom sequence as a class', async () => { class MySequence implements SequenceHandler { constructor(@inject(SequenceActions.SEND) private send: Send) {} @@ -63,7 +63,7 @@ describe('Sequence', () => { // bind user defined sequence server.sequence(MySequence); - whenIRequest() + await whenIRequest() .get('/') .expect('hello world'); }); diff --git a/packages/tsdocs/bin/extract-apis.js b/packages/tsdocs/bin/extract-apis.js index 2de5758f9c1b..989601374d87 100755 --- a/packages/tsdocs/bin/extract-apis.js +++ b/packages/tsdocs/bin/extract-apis.js @@ -27,4 +27,7 @@ async function main() { await runExtractorForMonorepo({silent, dryRun, apiReportEnabled}); } -main(); +main().catch(err => { + console.error(err); + process.exit(1); +}); diff --git a/packages/tsdocs/bin/update-apidocs.js b/packages/tsdocs/bin/update-apidocs.js index 5795fd146c57..105e1e2448d7 100755 --- a/packages/tsdocs/bin/update-apidocs.js +++ b/packages/tsdocs/bin/update-apidocs.js @@ -15,4 +15,7 @@ async function main() { await updateApiDocs({silent, dryRun}); } -main(); +main().catch(err => { + console.error(err); + process.exit(1); +});