From 585e154cec4a23caa6bcc075901c857d84b0dbb1 Mon Sep 17 00:00:00 2001 From: Aaron Cook Date: Thu, 1 Feb 2024 10:49:47 +0100 Subject: [PATCH] Remove floating promises (#1095) This enables a linting warning for floating promises and solves the few warnings that were found after enabling it. --- * Catch and log cache clearing failures after deletion * Remove floating promises --- .eslintrc.js | 1 + src/datasources/cache/cache.module.ts | 2 +- src/datasources/cache/redis.cache.service.spec.ts | 4 ++-- src/main.ts | 2 +- src/routes/alerts/alerts.controller.ts | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index cb2a1699f4..1ad411c168 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -24,5 +24,6 @@ module.exports = { { assertionStyle: 'as' }, ], '@typescript-eslint/no-explicit-any': 'error', + '@typescript-eslint/no-floating-promises': 'warn', }, }; diff --git a/src/datasources/cache/cache.module.ts b/src/datasources/cache/cache.module.ts index 13f9a73e6b..b4f64caf53 100644 --- a/src/datasources/cache/cache.module.ts +++ b/src/datasources/cache/cache.module.ts @@ -21,7 +21,7 @@ async function redisClientFactory( client.on('error', (err) => loggingService.error(`Redis client error: ${err}`), ); - client.connect(); + await client.connect(); return client; } diff --git a/src/datasources/cache/redis.cache.service.spec.ts b/src/datasources/cache/redis.cache.service.spec.ts index 82e5b36295..47d66f0087 100644 --- a/src/datasources/cache/redis.cache.service.spec.ts +++ b/src/datasources/cache/redis.cache.service.spec.ts @@ -103,7 +103,7 @@ describe('RedisCacheService', () => { faker.string.sample(), ); const value = fakeJson(); - redisClient.hSet(cacheDir.key, cacheDir.field, value); + await redisClient.hSet(cacheDir.key, cacheDir.field, value); const storedValue = await redisCacheService.get(cacheDir); @@ -117,7 +117,7 @@ describe('RedisCacheService', () => { faker.string.sample(), ); const value = fakeJson(); - redisClient.hSet(cacheDir.key, cacheDir.field, value); + await redisClient.hSet(cacheDir.key, cacheDir.field, value); await redisCacheService.deleteByKey(cacheDir.key); diff --git a/src/main.ts b/src/main.ts index fb9fd02c13..629817b54c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,4 +13,4 @@ async function bootstrap(): Promise { await app.listen(applicationPort); } -bootstrap(); +void bootstrap(); diff --git a/src/routes/alerts/alerts.controller.ts b/src/routes/alerts/alerts.controller.ts index 6398ae74c1..f325b29dd8 100644 --- a/src/routes/alerts/alerts.controller.ts +++ b/src/routes/alerts/alerts.controller.ts @@ -22,6 +22,6 @@ export class AlertsController { @Body(AlertValidationPipe) alertPayload: Alert, ): Promise { - this.alertsService.onAlert(alertPayload); + await this.alertsService.onAlert(alertPayload); } }