From be9672f4c3b8c1128b81009744ff33cbd47f775d Mon Sep 17 00:00:00 2001 From: getlarge Date: Wed, 13 Dec 2023 15:44:21 +0100 Subject: [PATCH] format: fix lint warnings --- apps/auth/src/main.ts | 19 ++++++++++-------- apps/auth/test/users.e2e-spec.ts | 12 +++++------ apps/ng-client/src/app/app.component.ts | 5 ++--- .../src/app/orders/list/list.component.ts | 6 +++--- .../app/tickets/details/details.component.ts | 17 +++++++++------- .../src/app/tickets/list/list.component.ts | 4 ++-- .../src/app/user/sign-in.component.ts | 10 +++++----- .../src/app/user/sign-up.component.ts | 12 +++++------ .../app/orders/orders-ms.controller.spec.ts | 4 ++-- .../ory-client/src/lib/ory.module.ts | 12 +++++------ .../shared/fastify-passport/src/auth.guard.ts | 1 + .../fastify-passport/src/passport.module.ts | 8 ++++---- .../shared/filters/src/http-error.filter.ts | 4 ++-- .../guards/src/ory-action-auth.guard.ts | 4 ++-- .../shared/redis/src/redis.healthcheck.ts | 20 ++++++++----------- 15 files changed, 69 insertions(+), 69 deletions(-) diff --git a/apps/auth/src/main.ts b/apps/auth/src/main.ts index 981f2e9e..e7342db3 100644 --- a/apps/auth/src/main.ts +++ b/apps/auth/src/main.ts @@ -40,7 +40,7 @@ async function bootstrap(): Promise { // bodyLimit: +process.env.MAX_PAYLOAD_SIZE || 5, // maxParamLength: 100, }), - { bufferLogs: true, abortOnError: false } + { bufferLogs: true, abortOnError: false }, ); const configService = app.get(ConfigService); @@ -60,7 +60,7 @@ async function bootstrap(): Promise { // }); // Fastify - app.register(fastifyHelmet, { + await app.register(fastifyHelmet, { contentSecurityPolicy: { directives: { defaultSrc: [`'self'`], @@ -70,14 +70,14 @@ async function bootstrap(): Promise { }, }, }); - app.register(fastifySecureSession, { + await app.register(fastifySecureSession, { key: configService.get('SESSION_KEY'), cookie: getCookieOptions(environment), }); - app.register(fastifyPassport.initialize()); - app.register(fastifyPassport.secureSession()); + await app.register(fastifyPassport.initialize()); + await app.register(fastifyPassport.secureSession()); if (!proxyServerUrls.length) { - app.register(fastifyCors, { + await app.register(fastifyCors, { origin: '*', // allowedHeaders: ALLOWED_HEADERS, // exposedHeaders: EXPOSED_HEADERS, @@ -126,9 +126,12 @@ async function bootstrap(): Promise { await app.listen(port, '0.0.0.0', () => { logger.log(`Listening at http://localhost:${port}/${GLOBAL_API_PREFIX}`); logger.log( - `Access SwaggerUI at http://localhost:${port}/${swaggerUiPrefix}` + `Access SwaggerUI at http://localhost:${port}/${swaggerUiPrefix}`, ); }); } -bootstrap(); +bootstrap().catch((error) => { + console.error(error); + process.exit(1); +}); diff --git a/apps/auth/test/users.e2e-spec.ts b/apps/auth/test/users.e2e-spec.ts index dd95b210..fc18603d 100644 --- a/apps/auth/test/users.e2e-spec.ts +++ b/apps/auth/test/users.e2e-spec.ts @@ -48,15 +48,15 @@ describe('UsersController (e2e)', () => { app = moduleFixture.createNestApplication(new FastifyAdapter()); const configService = app.get(ConfigService); - app.register(fastifySecureSession, { + await app.register(fastifySecureSession, { key: configService.get('SESSION_KEY'), cookie: { secure: false, signed: false, }, }); - app.register(fastifyPassport.initialize()); - app.register(fastifyPassport.secureSession()); + await app.register(fastifyPassport.initialize()); + await app.register(fastifyPassport.secureSession()); await app.init(); }); @@ -116,7 +116,7 @@ describe('UsersController (e2e)', () => { expect(statusCode).toBe(400); expect(body).toHaveProperty('errors'); expect(body.errors[0].message).toBe( - 'password must be longer than or equal to 4 characters' + 'password must be longer than or equal to 4 characters', ); }); @@ -176,7 +176,7 @@ describe('UsersController (e2e)', () => { expect.objectContaining({ name: 'session', value: expect.any(String), - }) + }), ); }); @@ -252,7 +252,7 @@ describe('UsersController (e2e)', () => { }); // const sessionCookie = response.cookies.find( - (cookie) => (cookie as any).name === 'session' + (cookie) => (cookie as any).name === 'session', ); expect(response.statusCode).toBe(200); expect((sessionCookie as any)?.value).toBe(''); diff --git a/apps/ng-client/src/app/app.component.ts b/apps/ng-client/src/app/app.component.ts index d082a7ac..ee39d9c2 100644 --- a/apps/ng-client/src/app/app.component.ts +++ b/apps/ng-client/src/app/app.component.ts @@ -29,7 +29,7 @@ export class AppComponent implements OnInit, OnDestroy { constructor( private store: Store, private router: Router, - private alertService: AlertService + private alertService: AlertService, ) {} ngOnInit(): void { @@ -37,7 +37,6 @@ export class AppComponent implements OnInit, OnDestroy { this.error$ = this.store.select(RootStoreSelectors.selectError); this.isLoading$ = this.store.select(RootStoreSelectors.selectIsLoading); this.user$ = this.store.select(UserStoreSelectors.selectCurrentUser); - // TODO: only dispatch LoadCurrentUserAction if !!currentToken this.store.dispatch(new UserStoreActions.LoadCurrentUserAction()); this.error$.pipe(takeUntil(this.destroy$)).subscribe({ next: (error) => { @@ -54,6 +53,6 @@ export class AppComponent implements OnInit, OnDestroy { logout(): void { this.store.dispatch(new UserStoreActions.SignOutAction()); - this.router.navigate(['/']); + void this.router.navigate(['/']); } } diff --git a/apps/ng-client/src/app/orders/list/list.component.ts b/apps/ng-client/src/app/orders/list/list.component.ts index 784b344b..15418b65 100644 --- a/apps/ng-client/src/app/orders/list/list.component.ts +++ b/apps/ng-client/src/app/orders/list/list.component.ts @@ -24,19 +24,19 @@ export class OrderListComponent implements OnInit { constructor( private store: Store, - private router: Router + private router: Router, ) {} ngOnInit(): void { this.orders$ = this.store.select(OrderStoreSelectors.selectAllOrderItems); this.isLoading$ = this.store.select( - OrderStoreSelectors.selectOrderIsLoading + OrderStoreSelectors.selectOrderIsLoading, ); this.store.dispatch(new OrderStoreActions.LoadOrdersAction()); } onViewOrder(orderId: string): void { - this.router.navigate([`/${Resources.ORDERS}`, orderId]); + void this.router.navigate([`/${Resources.ORDERS}`, orderId]); } onCancelOrder(orderId: string): void { diff --git a/apps/ng-client/src/app/tickets/details/details.component.ts b/apps/ng-client/src/app/tickets/details/details.component.ts index 33f18b14..f5fbb6dd 100644 --- a/apps/ng-client/src/app/tickets/details/details.component.ts +++ b/apps/ng-client/src/app/tickets/details/details.component.ts @@ -29,19 +29,19 @@ export class TicketDetailsComponent implements OnInit, OnDestroy { private router: Router, private actionsSubj: ActionsSubject, private route: ActivatedRoute, - private alertService: AlertService + private alertService: AlertService, ) {} ngOnInit(): void { this.ticket$ = this.store.select( - TicketStoreSelectors.selectCurrentTicket() + TicketStoreSelectors.selectCurrentTicket(), ); const ticketId = this.route.snapshot.paramMap.get('id'); if (ticketId) { this.store.dispatch( // new TicketStoreActions.LoadTicketAction({ ticketId }) - new TicketStoreActions.SelectTicketAction({ ticketId }) + new TicketStoreActions.SelectTicketAction({ ticketId }), ); } @@ -49,8 +49,8 @@ export class TicketDetailsComponent implements OnInit, OnDestroy { .pipe( takeUntil(this.destroy$), ofType( - OrderStoreActions.ActionTypes.CREATE_ORDER_SUCCESS - ) + OrderStoreActions.ActionTypes.CREATE_ORDER_SUCCESS, + ), ) .subscribe({ next: ({ payload }) => { @@ -58,7 +58,10 @@ export class TicketDetailsComponent implements OnInit, OnDestroy { keepAfterRouteChange: true, autoClose: true, }); - this.router.navigate([`/${Resources.ORDERS}/`, payload.order.id]); + void this.router.navigate([ + `/${Resources.ORDERS}/`, + payload.order.id, + ]); }, }); } @@ -70,7 +73,7 @@ export class TicketDetailsComponent implements OnInit, OnDestroy { purchaseTicket(ticket: Ticket): void { this.store.dispatch( - new OrderStoreActions.CreateOrderAction({ ticketId: ticket.id }) + new OrderStoreActions.CreateOrderAction({ ticketId: ticket.id }), ); } diff --git a/apps/ng-client/src/app/tickets/list/list.component.ts b/apps/ng-client/src/app/tickets/list/list.component.ts index ee97149e..9398b8a0 100644 --- a/apps/ng-client/src/app/tickets/list/list.component.ts +++ b/apps/ng-client/src/app/tickets/list/list.component.ts @@ -52,11 +52,11 @@ export class TicketListComponent implements OnInit { } onViewTicket(ticketId: string): void { - this.router.navigate([`/${Resources.TICKETS}`, ticketId]); + void this.router.navigate([`/${Resources.TICKETS}`, ticketId]); } // eslint-disable-next-line @typescript-eslint/no-unused-vars - onUpdateTicket(ticketId: string): void { + onUpdateTicket(_ticketId: string): void { // const modalRef = this.modalService.open(UpdateTicketModalComponent); // modalRef.componentInstance.ticketId = ticketId; } diff --git a/apps/ng-client/src/app/user/sign-in.component.ts b/apps/ng-client/src/app/user/sign-in.component.ts index 0922067d..d70082e2 100644 --- a/apps/ng-client/src/app/user/sign-in.component.ts +++ b/apps/ng-client/src/app/user/sign-in.component.ts @@ -29,7 +29,7 @@ export class SignInComponent implements OnInit, OnDestroy { private route: ActivatedRoute, private router: Router, private store: Store, - private actionsSubj: ActionsSubject + private actionsSubj: ActionsSubject, ) {} ngOnInit(): void { @@ -45,11 +45,11 @@ export class SignInComponent implements OnInit, OnDestroy { .select(UserStoreSelectors.selectCurrentUser) .pipe( takeUntil(this.destroy$), - filter((user) => !!user?.email) + filter((user) => !!user?.email), ) .subscribe({ next: () => { - this.router.navigate([this.returnUrl]); + void this.router.navigate([this.returnUrl]); }, }); @@ -57,9 +57,9 @@ export class SignInComponent implements OnInit, OnDestroy { .pipe( takeUntil(this.destroy$), ofType( - UserStoreActions.ActionTypes.SIGN_IN_SUCCESS + UserStoreActions.ActionTypes.SIGN_IN_SUCCESS, ), - take(1) + take(1), ) .subscribe({ next: () => { diff --git a/apps/ng-client/src/app/user/sign-up.component.ts b/apps/ng-client/src/app/user/sign-up.component.ts index 7e953010..3fd4e5c1 100644 --- a/apps/ng-client/src/app/user/sign-up.component.ts +++ b/apps/ng-client/src/app/user/sign-up.component.ts @@ -30,7 +30,7 @@ export class SignUpComponent implements OnInit, OnDestroy { private router: Router, private actionsSubj: ActionsSubject, private store: Store, - private alertService: AlertService + private alertService: AlertService, ) {} ngOnInit(): void { @@ -45,16 +45,14 @@ export class SignUpComponent implements OnInit, OnDestroy { .pipe(takeUntil(this.destroy$), first()) .subscribe({ next: (user) => { - if (user) { - this.router.navigate(['/']); - } + user && void this.router.navigate(['/']); }, }); this.actionsSubj .pipe( takeUntil(this.destroy$), - ofType(UserStoreActions.ActionTypes.SIGN_UP_SUCCESS) + ofType(UserStoreActions.ActionTypes.SIGN_UP_SUCCESS), ) .subscribe({ next: () => { @@ -62,7 +60,7 @@ export class SignUpComponent implements OnInit, OnDestroy { keepAfterRouteChange: true, autoClose: true, }); - this.router.navigate(['../sign-in'], { relativeTo: this.route }); + void this.router.navigate(['../sign-in'], { relativeTo: this.route }); }, }); } @@ -87,7 +85,7 @@ export class SignUpComponent implements OnInit, OnDestroy { this.store.dispatch( new UserStoreActions.SignUpAction({ credentials: this.form.value, - }) + }), ); } } diff --git a/apps/orders/src/app/orders/orders-ms.controller.spec.ts b/apps/orders/src/app/orders/orders-ms.controller.spec.ts index 4f44fe10..c815f21f 100644 --- a/apps/orders/src/app/orders/orders-ms.controller.spec.ts +++ b/apps/orders/src/app/orders/orders-ms.controller.spec.ts @@ -35,7 +35,7 @@ describe('OrdersMSController', () => { }); describe('onExpiration()', () => { - it('should call "OrdersService.expireById" and in case of success ack NATS message', async () => { + it('should call "OrdersService.expireById" and in case of success ack RMQ message', async () => { // order coming from expiration-service const order = { id: new Types.ObjectId().toHexString() }; const context = createRmqContext(); @@ -49,7 +49,7 @@ describe('OrdersMSController', () => { expect(context.getChannelRef().ack).toBeCalled(); }); - it('should call "OrdersService.expireById" and in case of error NOT ack NATS message', async () => { + it('should call "OrdersService.expireById" and in case of error NOT ack RMQ message', async () => { // order coming from expiration-service const order = { id: new Types.ObjectId().toHexString() }; const context = createRmqContext(); diff --git a/libs/microservices/ory-client/src/lib/ory.module.ts b/libs/microservices/ory-client/src/lib/ory.module.ts index 2b76f4d2..568e2c5c 100644 --- a/libs/microservices/ory-client/src/lib/ory.module.ts +++ b/libs/microservices/ory-client/src/lib/ory.module.ts @@ -16,7 +16,7 @@ import { OryService } from './ory.service'; export class OryModule { static forRoot( options: IOryModuleOptions, - isGlobal?: boolean + isGlobal?: boolean, ): DynamicModule { return { module: OryModule, @@ -28,7 +28,7 @@ export class OryModule { static forRootAsync( options: OryModuleAsyncOptions, - isGlobal?: boolean + isGlobal?: boolean, ): DynamicModule { return { module: OryModule, @@ -40,7 +40,7 @@ export class OryModule { } private static createAsyncProviders( - options: OryModuleAsyncOptions + options: OryModuleAsyncOptions, ): Provider[] { if (options.useExisting || options.useFactory) { return [this.createAsyncOptionsProvider(options)]; @@ -58,7 +58,7 @@ export class OryModule { } private static createAsyncOptionsProvider( - options: OryModuleAsyncOptions + options: OryModuleAsyncOptions, ): Provider { if (options.useFactory) { return { @@ -72,8 +72,8 @@ export class OryModule { } return { provide: OryModuleOptions, - useFactory: async (optionsFactory: OryModuleOptionsFactory) => - await optionsFactory.createOryOptions(), + useFactory: (optionsFactory: OryModuleOptionsFactory) => + optionsFactory.createOryOptions(), inject: [ (options.useExisting ?? options.useClass) as Type, diff --git a/libs/microservices/shared/fastify-passport/src/auth.guard.ts b/libs/microservices/shared/fastify-passport/src/auth.guard.ts index e0abb37d..47b7de36 100644 --- a/libs/microservices/shared/fastify-passport/src/auth.guard.ts +++ b/libs/microservices/shared/fastify-passport/src/auth.guard.ts @@ -52,6 +52,7 @@ function createAuthGuard(type?: string | string[]): Type { const handler = passport.authenticate( type, options, + // eslint-disable-next-line require-await async function ( _req: FastifyRequest, _res: FastifyReply, diff --git a/libs/microservices/shared/fastify-passport/src/passport.module.ts b/libs/microservices/shared/fastify-passport/src/passport.module.ts index 15f535c9..f4dbb1e5 100644 --- a/libs/microservices/shared/fastify-passport/src/passport.module.ts +++ b/libs/microservices/shared/fastify-passport/src/passport.module.ts @@ -27,7 +27,7 @@ export class PassportModule { } private static createAsyncProviders( - options: AuthModuleAsyncOptions + options: AuthModuleAsyncOptions, ): Provider[] { if (options.useExisting || options.useFactory) { return [this.createAsyncOptionsProvider(options)]; @@ -42,7 +42,7 @@ export class PassportModule { } private static createAsyncOptionsProvider( - options: AuthModuleAsyncOptions + options: AuthModuleAsyncOptions, ): Provider { if (options.useFactory) { return { @@ -53,8 +53,8 @@ export class PassportModule { } return { provide: AuthModuleOptions, - useFactory: async (optionsFactory: AuthOptionsFactory) => - await optionsFactory.createAuthOptions(), + useFactory: (optionsFactory: AuthOptionsFactory) => + optionsFactory.createAuthOptions(), inject: [options.useExisting || options.useClass], }; } diff --git a/libs/microservices/shared/filters/src/http-error.filter.ts b/libs/microservices/shared/filters/src/http-error.filter.ts index 74f10af2..0200c730 100644 --- a/libs/microservices/shared/filters/src/http-error.filter.ts +++ b/libs/microservices/shared/filters/src/http-error.filter.ts @@ -33,7 +33,7 @@ export class HttpErrorFilter implements ExceptionFilter { if (response.sent) { return; } - response.status(status).send(errorResponse); + void response.status(status).send(errorResponse); } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -52,7 +52,7 @@ export class HttpErrorFilter implements ExceptionFilter { return exception.serializeErrors(); } else if (isHttpException(exception)) { return [{ message: exception.message }]; - } else if (Object.prototype.hasOwnProperty.call(exception, 'message')) { + } else if (Object.hasOwn(exception, 'message')) { return [{ message: exception.message }]; } return [{ message: 'Internal Server Error' }]; diff --git a/libs/microservices/shared/guards/src/ory-action-auth.guard.ts b/libs/microservices/shared/guards/src/ory-action-auth.guard.ts index 6df562a1..e241ef0b 100644 --- a/libs/microservices/shared/guards/src/ory-action-auth.guard.ts +++ b/libs/microservices/shared/guards/src/ory-action-auth.guard.ts @@ -21,7 +21,7 @@ export class OryActionAuthGuard implements CanActivate { @Inject(ConfigService) configService: ConfigService< BaseEnvironmentVariables & OryActionEnvironmentVariables - > + >, ) { this.apiKey = configService.get('ORY_ACTION_API_KEY'); } @@ -30,7 +30,7 @@ export class OryActionAuthGuard implements CanActivate { return context.switchToHttp().getRequest(); } - async canActivate(context: ExecutionContext): Promise { + canActivate(context: ExecutionContext): boolean { const req = this.getRequest(context); const authHeader = req.headers['x-ory-api-key']; return authHeader && authHeader === this.apiKey; diff --git a/libs/microservices/shared/redis/src/redis.healthcheck.ts b/libs/microservices/shared/redis/src/redis.healthcheck.ts index cb10adc2..11104b4b 100644 --- a/libs/microservices/shared/redis/src/redis.healthcheck.ts +++ b/libs/microservices/shared/redis/src/redis.healthcheck.ts @@ -24,21 +24,17 @@ export class RedisHealthCheckTimeoutError extends Error { // @Injectable({ scope: Scope.TRANSIENT }) @Injectable() export class RedisHealthCheck extends HealthIndicator { - constructor() { - super(); - } - promiseTimeout( - delay = 1000, + delay: number, client: Redis.Redis, - fn: Promise + fn: Promise, ): Promise { const timeoutError = new RedisHealthCheckTimeoutError( - 'Redis connection timed out' + 'Redis connection timed out', ); return new Promise((resolve, reject) => { const timeout = setTimeout(() => { - client.quit().finally(() => reject(timeoutError)); + void client.quit().finally(() => reject(timeoutError)); }, delay); fn.then(() => { @@ -51,7 +47,7 @@ export class RedisHealthCheck extends HealthIndicator { }); } - private async pingMicroservice(client: Redis.Redis): Promise { + private pingMicroservice(client: Redis.Redis): Promise { const checkConnection = async (): Promise => { if (!client.status.includes('connect')) { await client.connect(); @@ -63,7 +59,7 @@ export class RedisHealthCheck extends HealthIndicator { async pingCheck( key: string, - options: RedisHealthCheckOptions + options: RedisHealthCheckOptions, ): Promise { let isHealthy = false; const timeout = options.timeout || 1000; @@ -86,14 +82,14 @@ export class RedisHealthCheck extends HealthIndicator { timeout, this.getStatus(key, false, { message: `timeout of ${timeout}ms exceeded`, - }) + }), ); } throw new HealthCheckError( error.message, this.getStatus(key, false, { message: error.message, - }) + }), ); } }