From c6e4b244d3abff119a7b71a004bbcda6745b027d Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Mon, 16 Oct 2023 13:30:43 +0545 Subject: [PATCH] fix: sonar lint issues --- .vscode/settings.json | 1 + README.md | 12 ++- eslint.config.js | 1 + src/_mocks_/index.ts | 17 ++-- src/app.module.ts | 4 +- src/common/database/base.repository.ts | 15 ++-- src/common/database/mikro-orm.encrypted.ts | 2 +- src/common/database/user.subscriber.ts | 8 +- src/common/decorators/api-file.decorator.ts | 2 +- .../decorators/swagger-api.decorator.ts | 4 +- .../validation/is-after.validator.spec.ts | 2 +- .../validation/is-after.validator.ts | 2 +- .../validation/is-date-field.validator.ts | 2 +- .../validation/is-equal-to.validator.ts | 2 +- .../validation/is-greater-than.validator.ts | 2 +- .../validation/is-number-field.decorator.ts | 2 +- .../validation/is-string-field.decorator.ts | 2 +- .../validation/is-uuid.validator.ts | 2 +- src/common/dtos/pagination.dto.ts | 12 +-- src/common/guards/auth.guard.ts | 6 +- src/common/guards/throttle.guard.ts | 10 +-- src/common/helpers/helpers.utils.ts | 3 +- src/common/misc/file.ts | 1 + src/common/misc/workers.ts | 13 ++- src/lib/aws/aws.s3.service.ts | 80 +++++++++---------- src/lib/config/config.module.ts | 4 +- src/lib/crud/crud.controller.ts | 2 +- src/lib/crud/crud.service.ts | 4 +- src/lib/i18n/translate.ts | 7 +- src/lib/mailer/index.ts | 3 +- src/lib/mailer/mailer.options.ts | 9 +-- src/lib/minio.module.ts | 2 +- src/main.ts | 13 +-- src/modules/auth/auth.controller.ts | 18 +---- src/modules/auth/auth.service.spec.ts | 1 - src/modules/auth/auth.service.ts | 66 ++++++++------- .../auth/strategies/jwt-2fa.strategy.ts | 5 +- src/modules/auth/strategies/jwt.strategy.ts | 5 +- .../auth/strategies/magic-login.strategy.ts | 10 +-- src/modules/chat/chat.service.ts | 4 +- src/modules/chat/socket-connection.service.ts | 18 ++--- .../newsletter/dto/create-newsletter.dto.ts | 2 + src/modules/newsletter/newsletter.service.ts | 4 +- src/modules/post/post.service.ts | 13 ++- src/modules/profile/profile.service.ts | 4 +- .../token/refresh-tokens.repository.ts | 2 +- src/modules/user/dtos/create-user.dto.ts | 3 +- src/modules/user/user.service.ts | 4 +- src/socket-io.adapter.ts | 2 +- 49 files changed, 198 insertions(+), 214 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 43ed1d2b..fe893c6f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -40,6 +40,7 @@ "rabbitmq", "Requote", "rubiin", + "sonarjs", "SSSZ", "UNAUTHORISED" ] diff --git a/README.md b/README.md index c56f0345..4b0bff26 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,15 @@ More docs found at `docs` folder Also if you are into NestJS ecosystem you may be interested in one of my other libs: -[nestjs-easyconfig](https://github.com/rubiin/nestjs-pino) + +[helper-fns](https://github.com/rubiin/helper-fns) + +[![GitHub stars](https://img.shields.io/github/stars/rubiin/helper-fns?style=flat-square)](https://github.com/rubiin/helper-fns) +[![npm](https://img.shields.io/npm/dm/helper-fns?style=flat-square)](https://www.npmjs.com/package/helper-fns) + +A collection of helper functions for typescrip development. It includes functions for array,object,string,etc + +[nestjs-easyconfig](https://github.com/rubiin/nestjs-easyconfig) [![GitHub stars](https://img.shields.io/github/stars/rubiin/nestjs-easyconfig?style=flat-square)](https://github.com/rubiin/nestjs-easyconfig) [![npm](https://img.shields.io/npm/dm/nestjs-easyconfig?style=flat-square)](https://www.npmjs.com/package/nestjs-easyconfig) @@ -251,7 +259,7 @@ This is a cloudinary module for Nest. --- -[nestjs-pgpromise](https://github.com/segmentstream/nestjs-injectable) +[nestjs-pgpromise](https://github.com/rubiin/nestjs-pgpromise) [![GitHub stars](https://img.shields.io/github/stars/rubiin/nestjs-pgpromise?style=flat-square)](https://github.com/rubiin/nestjs-pgpromise) [![npm](https://img.shields.io/npm/dm/nestjs-pgpromise?style=flat-square)](https://www.npmjs.com/package/nestjs-pgpromise) diff --git a/eslint.config.js b/eslint.config.js index ca08451c..162c2cb2 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -20,6 +20,7 @@ module.exports = rubiin({ "ts/no-unsafe-assignment": "off", // optimize this "ts/no-unsafe-member-access": "off", // optimize this "unicorn/prefer-top-level-await": "off", + "sonarjs/no-duplicate-string": ["error", { "threshold": 10 }], "ts/no-misused-promises": [ "error", { diff --git a/src/_mocks_/index.ts b/src/_mocks_/index.ts index 156ec77d..0f0b6b91 100644 --- a/src/_mocks_/index.ts +++ b/src/_mocks_/index.ts @@ -1,4 +1,3 @@ -/* eslint-disable ts/no-unsafe-return */ import path from "node:path"; import type { Request, Response } from "express"; import type { AmqpConnection } from "@golevelup/nestjs-rabbitmq"; @@ -99,21 +98,23 @@ export const refreshToken = new RefreshToken({ export const protocol = new Protocol(mockedProtocol); export const mockEm = createMock(); + +const payload = { + xss: "