From 21ae14b38ee882584d9ab15fed3e2548fabbf102 Mon Sep 17 00:00:00 2001 From: Bas Meeuwissen Date: Fri, 3 Jan 2025 21:24:24 +0100 Subject: [PATCH] #362: fixed linting issues --- .eslintrc.json => .eslintrc.jsonnnn | 0 eslint.config.mjs | 37 ------------------- src/domain/creator/definitions.ts | 4 +- src/domain/creator/getOthers/feature.ts | 4 +- src/domain/definitions.ts | 6 +-- src/domain/notification/definitions.ts | 6 +-- src/domain/post/toggleRating/feature.ts | 4 +- src/domain/reaction/create/feature.ts | 4 +- src/domain/reaction/toggleRating/feature.ts | 4 +- src/domain/relation/definitions.ts | 5 ++- src/domain/relation/establish/feature.ts | 4 +- .../authentication/definitions/types.ts | 1 + .../database/definitions/types.ts | 2 + .../database/implementations/memory/Memory.ts | 3 +- .../implementations/mongodb/MongoDb.ts | 6 +-- .../implementations/memory/Memory.ts | 2 +- src/integrations/logging/Logger.ts | 2 +- .../healthchecks/DatabaseHealthCheck.ts | 6 ++- .../healthchecks/FileStoreHealthCheck.ts | 6 ++- .../healthchecks/NotificationHealthCheck.ts | 6 ++- .../middlewares/AuthenticationMiddleware.ts | 2 +- .../definitions/ValidationResult.ts | 2 +- .../validation/definitions/types.ts | 2 + .../validation/implementations/zod/Zod.ts | 2 +- .../common/hooks/useLoadOnScroll.ts | 1 + .../components/rating/hooks/useEngagement.ts | 1 + .../relation/elementary/FollowRow.tsx | 1 + .../designsystem/elements/modal/Modal.tsx | 1 + src/webui/editor/model/Bubble.ts | 2 +- src/webui/features/CreatorFollowers.tsx | 1 + src/webui/features/CreatorFollowing.tsx | 1 + src/webui/features/ExploreCreators.tsx | 1 + src/webui/features/hooks/useLogin.ts | 1 + src/webui/hooks/useDebouncedValue.ts | 2 +- src/webui/hooks/usePathParam.ts | 2 + .../creator/fixtures/records.fixture.ts | 2 +- test/domain/notification/create.spec.ts | 26 ++++++------- .../notification/fixtures/records.fixture.ts | 14 +++---- .../notification/getRecentAggregated.spec.ts | 10 ++--- test/domain/post/fixtures/records.fixture.ts | 2 +- .../reaction/fixtures/records.fixture.ts | 2 +- .../domain/relation/exploreAggregated.spec.ts | 14 +++---- .../relation/fixtures/records.fixture.ts | 2 +- .../database/fixtures/results.fixture.ts | 2 +- .../notification/implementation.spec.ts | 2 +- 45 files changed, 97 insertions(+), 113 deletions(-) rename .eslintrc.json => .eslintrc.jsonnnn (100%) delete mode 100644 eslint.config.mjs diff --git a/.eslintrc.json b/.eslintrc.jsonnnn similarity index 100% rename from .eslintrc.json rename to .eslintrc.jsonnnn diff --git a/eslint.config.mjs b/eslint.config.mjs deleted file mode 100644 index 09181610..00000000 --- a/eslint.config.mjs +++ /dev/null @@ -1,37 +0,0 @@ -import eslint from '@eslint/js'; -import tsparser from '@typescript-eslint/parser'; -import sonarjs from 'eslint-plugin-sonarjs'; -import tseslint from 'typescript-eslint'; - -export default tseslint.config({ - ignores: [ - "**/dist/**/*", - "**/node_modules/**/*", - "**/coverage/**/*", - "**/templates/**/*", - "**/test/**/fixtures/**/*", - "*config*" - ], - extends: [ - eslint.configs.recommended, - ...tseslint.configs.recommended, - ...tseslint.configs.stylistic, - sonarjs.configs.recommended, - ], - languageOptions: { - parser: tsparser - }, - plugins: {}, - rules: { - "@typescript-eslint/no-unsafe-function-type": "off", - "@typescript-eslint/consistent-type-definitions": "off", - "no-return-await": "error", - "semi": ["error", "always"], - "eol-last": ["error", "always"], - "brace-style": ["error", "allman", { "allowSingleLine": true }], - - "sonarjs/assertions-in-tests": "off", - // "sonarjs/slow-regex": "off", - // "sonarjs/duplicates-in-character-class": "off" - } -}); \ No newline at end of file diff --git a/src/domain/creator/definitions.ts b/src/domain/creator/definitions.ts index 695bc7b8..76a853fa 100644 --- a/src/domain/creator/definitions.ts +++ b/src/domain/creator/definitions.ts @@ -1,7 +1,7 @@ import type { Validation } from '^/integrations/validation/module'; -import { SortOrder } from '../definitions'; +import { SortOrder, SortOrderEnum } from '../definitions'; export const RECORD_TYPE = 'creator'; export const IMAGE_TYPE = 'portrait'; @@ -18,4 +18,4 @@ export const fullNameValidation: Validation = { } }; -export { SortOrder }; +export { SortOrderEnum, type SortOrder }; diff --git a/src/domain/creator/getOthers/feature.ts b/src/domain/creator/getOthers/feature.ts index f0637c5a..2131a920 100644 --- a/src/domain/creator/getOthers/feature.ts +++ b/src/domain/creator/getOthers/feature.ts @@ -1,7 +1,7 @@ import database, { QueryStatement, RecordQuery, RecordSort, SortDirections } from '^/integrations/database/module'; -import { RECORD_TYPE, SortOrder } from '../definitions'; +import { RECORD_TYPE, SortOrder, SortOrderEnum } from '../definitions'; import type { DataModel } from '../types'; export default async function feature(ids: string[], order: SortOrder, search: string | undefined = undefined, limit: number, offset: number): Promise @@ -14,7 +14,7 @@ export default async function feature(ids: string[], order: SortOrder, search: s ] }; - const sortField = order === SortOrder.POPULAR ? 'popularity' : 'joinedAt'; + const sortField = order === SortOrderEnum.POPULAR ? 'popularity' : 'joinedAt'; const query: QueryStatement = search !== undefined ? { ...defaultQuery, ...searchQuery } : defaultQuery; const recordSort: RecordSort = { [sortField]: SortDirections.ASCENDING }; diff --git a/src/domain/definitions.ts b/src/domain/definitions.ts index f9e2f671..65ecbd7a 100644 --- a/src/domain/definitions.ts +++ b/src/domain/definitions.ts @@ -1,7 +1,7 @@ import type { Validation } from '^/integrations/validation/module'; -export const SortOrder = { +export const SortOrderEnum = { POPULAR: 'popular', RECENT: 'recent' } as const; @@ -26,6 +26,6 @@ export const optionalIdValidation: Validation = } }; -type SortOrderKeys = keyof typeof SortOrder; +type SortOrderKeys = keyof typeof SortOrderEnum; -export type SortOrder = typeof SortOrder[SortOrderKeys]; +export type SortOrder = typeof SortOrderEnum[SortOrderKeys]; diff --git a/src/domain/notification/definitions.ts b/src/domain/notification/definitions.ts index b6b9a732..b46cead9 100644 --- a/src/domain/notification/definitions.ts +++ b/src/domain/notification/definitions.ts @@ -1,13 +1,13 @@ export const RECORD_TYPE = 'notification'; -export const Types = { +export const TypesEnum = { STARTED_FOLLOWING: 'started-following', RATED_POST: 'rated-post', RATED_REACTION: 'rated-reaction', ADDED_REACTION: 'added-reaction' } as const; -type TypeKeys = keyof typeof Types; +type TypeKeys = keyof typeof TypesEnum; -export type Types = typeof Types[TypeKeys]; +export type Types = typeof TypesEnum[TypeKeys]; diff --git a/src/domain/post/toggleRating/feature.ts b/src/domain/post/toggleRating/feature.ts index 58e4d289..dfccc400 100644 --- a/src/domain/post/toggleRating/feature.ts +++ b/src/domain/post/toggleRating/feature.ts @@ -3,7 +3,7 @@ import logger from '^/integrations/logging/module'; import type { Requester } from '^/domain/authentication/types'; import createNotification from '^/domain/notification/create/feature'; -import { Types } from '^/domain/notification/definitions'; +import { TypesEnum } from '^/domain/notification/definitions'; import getPost from '^/domain/post/getById/feature'; import updateRating from '^/domain/rating/update/feature'; @@ -28,7 +28,7 @@ export default async function feature(requester: Requester, postId: string): Pro const post = await getPost(postId); - await createNotification(Types.RATED_POST, requester.id, post.creatorId, postId); + await createNotification(TypesEnum.RATED_POST, requester.id, post.creatorId, postId); return true; } diff --git a/src/domain/reaction/create/feature.ts b/src/domain/reaction/create/feature.ts index 712af85b..6c08811d 100644 --- a/src/domain/reaction/create/feature.ts +++ b/src/domain/reaction/create/feature.ts @@ -4,7 +4,7 @@ import logger from '^/integrations/logging/module'; import updateReactionCount from '^/domain/post/updateReactionCount/feature'; import createNotification from '^/domain/notification/create/feature'; -import { Types } from '^/domain/notification/definitions'; +import { TypesEnum } from '^/domain/notification/definitions'; import retrievePost from '^/domain/post/getById/feature'; import createData from './createData'; import eraseData from './eraseData'; @@ -27,7 +27,7 @@ export default async function feature(creatorId: string, postId: string, comicId const post = await retrievePost(postId); - await createNotification(Types.ADDED_REACTION, creatorId, post.creatorId, postId, id); + await createNotification(TypesEnum.ADDED_REACTION, creatorId, post.creatorId, postId, id); return id; } diff --git a/src/domain/reaction/toggleRating/feature.ts b/src/domain/reaction/toggleRating/feature.ts index 794e900b..e7a78a21 100644 --- a/src/domain/reaction/toggleRating/feature.ts +++ b/src/domain/reaction/toggleRating/feature.ts @@ -3,7 +3,7 @@ import logger from '^/integrations/logging/module'; import type { Requester } from '^/domain/authentication/types'; import createNotification from '^/domain/notification/create/feature'; -import { Types } from '^/domain/notification/definitions'; +import { TypesEnum } from '^/domain/notification/definitions'; import updateRating from '^/domain/rating/update/feature'; import getReaction from '^/domain/reaction/getById/feature'; @@ -28,7 +28,7 @@ export default async function feature(requester: Requester, reactionId: string): const reaction = await getReaction(reactionId); - await createNotification(Types.RATED_REACTION, requester.id, reaction.creatorId, undefined, reactionId); + await createNotification(TypesEnum.RATED_REACTION, requester.id, reaction.creatorId, undefined, reactionId); return true; } diff --git a/src/domain/relation/definitions.ts b/src/domain/relation/definitions.ts index ee62f523..2f755141 100644 --- a/src/domain/relation/definitions.ts +++ b/src/domain/relation/definitions.ts @@ -1,6 +1,7 @@ -import { SortOrder } from '../definitions'; +import { SortOrder, SortOrderEnum } from '../definitions'; export const RECORD_TYPE = 'relation'; -export { SortOrder }; +export { SortOrderEnum, type SortOrder }; + diff --git a/src/domain/relation/establish/feature.ts b/src/domain/relation/establish/feature.ts index 9547cd10..9d8c2f99 100644 --- a/src/domain/relation/establish/feature.ts +++ b/src/domain/relation/establish/feature.ts @@ -6,7 +6,7 @@ import updateFollowerCount from '^/domain/creator/updateFollowerCount/feature'; import updateFollowingCount from '^/domain/creator/updateFollowingCount/feature'; import createNotification from '^/domain/notification/create/feature'; -import { Types } from '^/domain/notification/definitions'; +import { TypesEnum } from '^/domain/notification/definitions'; import createData from './createData'; import dataExists from './dataExists'; import eraseData from './eraseData'; @@ -37,7 +37,7 @@ export default async function feature(requester: Requester, followingId: string) await updateFollowingCount(requester.id, 'increase'); - await createNotification(Types.STARTED_FOLLOWING, requester.id, followingId); + await createNotification(TypesEnum.STARTED_FOLLOWING, requester.id, followingId); } catch (error: unknown) { diff --git a/src/integrations/authentication/definitions/types.ts b/src/integrations/authentication/definitions/types.ts index c83a251b..f9de8c3e 100644 --- a/src/integrations/authentication/definitions/types.ts +++ b/src/integrations/authentication/definitions/types.ts @@ -7,6 +7,7 @@ type Identity = { email_verified: boolean; }; +// eslint-disable-next-line sonarjs/redundant-type-aliases type Token = string; type Session = { diff --git a/src/integrations/database/definitions/types.ts b/src/integrations/database/definitions/types.ts index 46f2c90a..4775f420 100644 --- a/src/integrations/database/definitions/types.ts +++ b/src/integrations/database/definitions/types.ts @@ -1,4 +1,6 @@ +/* eslint sonarjs/redundant-type-aliases: "off" */ + import { QueryOperators, SortDirections } from './constants'; export type RecordType = string; diff --git a/src/integrations/database/implementations/memory/Memory.ts b/src/integrations/database/implementations/memory/Memory.ts index 3751d5bc..b47aa104 100644 --- a/src/integrations/database/implementations/memory/Memory.ts +++ b/src/integrations/database/implementations/memory/Memory.ts @@ -26,7 +26,7 @@ const LOGICAL_OPERATORS = export default class Memory implements Driver { - #memory: Map = new Map(); + #memory = new Map(); #connected = false; recordId = 0; @@ -168,6 +168,7 @@ export default class Memory implements Driver const statementCode = this.#buildStatementCode(query); const functionCode = statementCode === '' ? 'true' : statementCode; + // eslint-disable-next-line sonarjs/code-eval return new Function('record', `return ${functionCode}`) as FilterFunction; } diff --git a/src/integrations/database/implementations/mongodb/MongoDb.ts b/src/integrations/database/implementations/mongodb/MongoDb.ts index 00ee1fd4..45516fcc 100644 --- a/src/integrations/database/implementations/mongodb/MongoDb.ts +++ b/src/integrations/database/implementations/mongodb/MongoDb.ts @@ -1,4 +1,6 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + import { Collection, Db, Document, Filter, MongoClient, Sort } from 'mongodb'; import { ID, LogicalOperators, QueryOperators, SortDirections } from '../../definitions/constants.js'; @@ -182,10 +184,8 @@ export default class MongoDB implements Driver return; // Deliberately not implemented } - // eslint-disable-next-line @typescript-eslint/no-explicit-any, sonarjs/cognitive-complexity #buildMongoQuery(query: RecordQuery): Filter { - // eslint-disable-next-line @typescript-eslint/no-explicit-any const mongoQuery: Filter = {}; const multiStatements = query as QueryMultiExpressionStatement; const singleStatements = query as QuerySingleExpressionStatement; @@ -195,7 +195,6 @@ export default class MongoDB implements Driver if (key === 'AND' || key === 'OR') { const singleMultiStatements = multiStatements[key] ?? []; - // eslint-disable-next-line @typescript-eslint/no-explicit-any const multiMongoQuery: Filter[] = []; for (const statement of singleMultiStatements) @@ -246,7 +245,6 @@ export default class MongoDB implements Driver return mongoSort; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any async #getCollection(name: RecordType): Promise> { if (this.#database === undefined) diff --git a/src/integrations/filestore/implementations/memory/Memory.ts b/src/integrations/filestore/implementations/memory/Memory.ts index a2319107..b12c527e 100644 --- a/src/integrations/filestore/implementations/memory/Memory.ts +++ b/src/integrations/filestore/implementations/memory/Memory.ts @@ -5,7 +5,7 @@ import NotConnected from '../../errors/NotConnected.js'; export default class Memory implements FileStore { - #files: Map = new Map(); + #files = new Map(); #connected = false; get connected() { return this.#connected; } diff --git a/src/integrations/logging/Logger.ts b/src/integrations/logging/Logger.ts index 4f42063d..ece5fa64 100644 --- a/src/integrations/logging/Logger.ts +++ b/src/integrations/logging/Logger.ts @@ -6,7 +6,7 @@ export default class Logger implements LogProcessor #processor: LogProcessor; #debugEnabled: boolean; - constructor(processor: LogProcessor, debugEnabled: boolean = false) + constructor(processor: LogProcessor, debugEnabled = false) { this.#processor = processor; this.#debugEnabled = debugEnabled; diff --git a/src/integrations/runtime/healthchecks/DatabaseHealthCheck.ts b/src/integrations/runtime/healthchecks/DatabaseHealthCheck.ts index 49c63901..66c79564 100644 --- a/src/integrations/runtime/healthchecks/DatabaseHealthCheck.ts +++ b/src/integrations/runtime/healthchecks/DatabaseHealthCheck.ts @@ -6,15 +6,17 @@ import type { Database } from '^/integrations/database/module'; export default class DatabaseHealthCheck implements HealthCheck { #database: Database; + #name = 'database'; + #timeout = 5000; constructor(database: Database) { this.#database = database; } - get name() { return 'database'; } + get name() { return this.#name; } - get timeout() { return 5000; } + get timeout() { return this.#timeout; } async isHealthy(): Promise { diff --git a/src/integrations/runtime/healthchecks/FileStoreHealthCheck.ts b/src/integrations/runtime/healthchecks/FileStoreHealthCheck.ts index bcdb1454..03bde53d 100644 --- a/src/integrations/runtime/healthchecks/FileStoreHealthCheck.ts +++ b/src/integrations/runtime/healthchecks/FileStoreHealthCheck.ts @@ -6,15 +6,17 @@ import { FileStore } from '^/integrations/filestore/definitions/interfaces'; export default class FileStoreHealthCheck implements HealthCheck { #fileStore: FileStore; + #name = 'filestore'; + #timeout = 5000; constructor(fileStore: FileStore) { this.#fileStore = fileStore; } - get name() { return 'filestore'; } + get name() { return this.#name; } - get timeout() { return 5000; } + get timeout() { return this.#timeout; } async isHealthy(): Promise { diff --git a/src/integrations/runtime/healthchecks/NotificationHealthCheck.ts b/src/integrations/runtime/healthchecks/NotificationHealthCheck.ts index 27c80adc..8c86ddd3 100644 --- a/src/integrations/runtime/healthchecks/NotificationHealthCheck.ts +++ b/src/integrations/runtime/healthchecks/NotificationHealthCheck.ts @@ -6,15 +6,17 @@ import { NotificationService } from '^/integrations/notification/definitions/int export default class NotificationHealthCheck implements HealthCheck { #notificationService: NotificationService; + #name = 'notifications'; + #timeout = 5000; constructor(notificationService: NotificationService) { this.#notificationService = notificationService; } - get name() { return 'notifications'; } + get name() { return this.#name; } - get timeout() { return 5000; } + get timeout() { return this.#timeout; } async isHealthy(): Promise { diff --git a/src/integrations/runtime/middlewares/AuthenticationMiddleware.ts b/src/integrations/runtime/middlewares/AuthenticationMiddleware.ts index 978aec81..8115f479 100644 --- a/src/integrations/runtime/middlewares/AuthenticationMiddleware.ts +++ b/src/integrations/runtime/middlewares/AuthenticationMiddleware.ts @@ -176,7 +176,7 @@ export default class AuthenticationMiddleware implements Middleware return newSession; } - catch (error) + catch { throw new Unauthorized('Session expired'); } diff --git a/src/integrations/validation/definitions/ValidationResult.ts b/src/integrations/validation/definitions/ValidationResult.ts index 488333ae..97a25e68 100644 --- a/src/integrations/validation/definitions/ValidationResult.ts +++ b/src/integrations/validation/definitions/ValidationResult.ts @@ -4,7 +4,7 @@ export default class ValidationResult #invalid: boolean; #messages: Map; - constructor(invalid: boolean, messages: Map = new Map()) + constructor(invalid: boolean, messages = new Map()) { this.#invalid = invalid; this.#messages = messages; diff --git a/src/integrations/validation/definitions/types.ts b/src/integrations/validation/definitions/types.ts index 8395a20c..83154839 100644 --- a/src/integrations/validation/definitions/types.ts +++ b/src/integrations/validation/definitions/types.ts @@ -1,4 +1,6 @@ +/* eslint sonarjs/redundant-type-aliases: "off" */ + import { FieldTypes } from './constants'; export type ValidationType = keyof typeof FieldTypes; diff --git a/src/integrations/validation/implementations/zod/Zod.ts b/src/integrations/validation/implementations/zod/Zod.ts index 1317b3fa..799febff 100644 --- a/src/integrations/validation/implementations/zod/Zod.ts +++ b/src/integrations/validation/implementations/zod/Zod.ts @@ -14,7 +14,7 @@ type ValidatorFunction = (value: ValidationTypes[keyof ValidationTypes]) => z.Zo export default class Zod implements Validator { - #validations: Map = new Map(); + #validations = new Map(); constructor() { diff --git a/src/webui/components/common/hooks/useLoadOnScroll.ts b/src/webui/components/common/hooks/useLoadOnScroll.ts index b8369e39..c4f87b63 100644 --- a/src/webui/components/common/hooks/useLoadOnScroll.ts +++ b/src/webui/components/common/hooks/useLoadOnScroll.ts @@ -32,6 +32,7 @@ export default function useLoadOnScroll(onLoad: LoadHandler, isLoading: boolean, } }; + // eslint-disable-next-line @typescript-eslint/no-unused-expressions isFinished ? container.removeEventListener('scroll', handleScroll) : container.addEventListener('scroll', handleScroll); diff --git a/src/webui/components/rating/hooks/useEngagement.ts b/src/webui/components/rating/hooks/useEngagement.ts index 321e8439..34d4b734 100644 --- a/src/webui/components/rating/hooks/useEngagement.ts +++ b/src/webui/components/rating/hooks/useEngagement.ts @@ -12,6 +12,7 @@ export default function useEngagement(isEngaged: boolean, count: number, engage: { const isRated = await engage(); + // eslint-disable-next-line @typescript-eslint/no-unused-expressions isRated ? setRatingCount(ratingCount + 1) : setRatingCount(ratingCount - 1); diff --git a/src/webui/components/relation/elementary/FollowRow.tsx b/src/webui/components/relation/elementary/FollowRow.tsx index db568b1e..02b85040 100644 --- a/src/webui/components/relation/elementary/FollowRow.tsx +++ b/src/webui/components/relation/elementary/FollowRow.tsx @@ -19,6 +19,7 @@ export default function Component({ isFollowing, isSelf, onFollowClick, onEditCl return {children} {isSelf + // eslint-disable-next-line sonarjs/no-nested-conditional ? onEditClick !== undefined ? : <> diff --git a/src/webui/designsystem/elements/modal/Modal.tsx b/src/webui/designsystem/elements/modal/Modal.tsx index 39255e7d..b405c79e 100644 --- a/src/webui/designsystem/elements/modal/Modal.tsx +++ b/src/webui/designsystem/elements/modal/Modal.tsx @@ -18,6 +18,7 @@ export default function Element({ open, sizing = 'content', children }: Props) useEffect(() => { + // eslint-disable-next-line @typescript-eslint/no-unused-expressions open ? ref.current?.showModal() : ref.current?.close(); diff --git a/src/webui/editor/model/Bubble.ts b/src/webui/editor/model/Bubble.ts index 8f16757f..6ed51248 100644 --- a/src/webui/editor/model/Bubble.ts +++ b/src/webui/editor/model/Bubble.ts @@ -5,7 +5,7 @@ import { type Point } from '../utils/Geometry'; export default abstract class Bubble extends Element { #pointer: Point = { x: 0, y: 0 }; - #text: string = ''; + #text = ''; get pointer() { return this.#pointer; } diff --git a/src/webui/features/CreatorFollowers.tsx b/src/webui/features/CreatorFollowers.tsx index 5e40189e..63891be0 100644 --- a/src/webui/features/CreatorFollowers.tsx +++ b/src/webui/features/CreatorFollowers.tsx @@ -24,6 +24,7 @@ export default function Feature({ creator }: Props) const [relations, isLoading, isFinished, getMoreRelations, , refresh] = useCreatorFollowers(creator); return + { /* eslint-disable-next-line @typescript-eslint/no-empty-function */} {}} /> diff --git a/src/webui/features/CreatorFollowing.tsx b/src/webui/features/CreatorFollowing.tsx index c8f1421f..1752e3ee 100644 --- a/src/webui/features/CreatorFollowing.tsx +++ b/src/webui/features/CreatorFollowing.tsx @@ -24,6 +24,7 @@ export default function Feature({ creator }: Props) const [relations, isLoading, isFinished, getMoreRelations, , refresh] = useCreatorFollowing(creator); return + { /* eslint-disable-next-line @typescript-eslint/no-empty-function */} {}} /> diff --git a/src/webui/features/ExploreCreators.tsx b/src/webui/features/ExploreCreators.tsx index 11c69652..9226d378 100644 --- a/src/webui/features/ExploreCreators.tsx +++ b/src/webui/features/ExploreCreators.tsx @@ -20,6 +20,7 @@ export default function Feature() const [relations, isLoading, isFinished, getMoreRelations, , refresh] = useExploreCreators(); return + { /* eslint-disable-next-line @typescript-eslint/no-empty-function */} {}} /> diff --git a/src/webui/features/hooks/useLogin.ts b/src/webui/features/hooks/useLogin.ts index 677a439a..90c8355d 100644 --- a/src/webui/features/hooks/useLogin.ts +++ b/src/webui/features/hooks/useLogin.ts @@ -19,6 +19,7 @@ export default function useLogin() const currentLocation = pathname + search + hash; + // eslint-disable-next-line @typescript-eslint/no-unused-expressions IGNORE_PATHS.includes(pathname) ? window.sessionStorage.removeItem('redirect') : window.sessionStorage.setItem('redirect', currentLocation); diff --git a/src/webui/hooks/useDebouncedValue.ts b/src/webui/hooks/useDebouncedValue.ts index f6a3b9f9..516af9e6 100644 --- a/src/webui/hooks/useDebouncedValue.ts +++ b/src/webui/hooks/useDebouncedValue.ts @@ -3,7 +3,7 @@ import { useEffect, useState } from 'react'; type ChangeHandler = (value: T) => void; -export function useDebouncedValue(initialValue: T, onChange: ChangeHandler, delay: number = 500) +export function useDebouncedValue(initialValue: T, onChange: ChangeHandler, delay = 500) { const [value, setValue] = useState(initialValue); const [debouncedValue, setDebouncedValue] = useState(initialValue); diff --git a/src/webui/hooks/usePathParam.ts b/src/webui/hooks/usePathParam.ts index 36782abe..47792663 100644 --- a/src/webui/hooks/usePathParam.ts +++ b/src/webui/hooks/usePathParam.ts @@ -29,8 +29,10 @@ export function usePathParam(paramName: string, defaultValue?: string) const newParameters = [...parameters]; + // eslint-disable-next-line @typescript-eslint/no-unused-expressions paramIndex === -1 ? newParameters.push(value) + // eslint-disable-next-line sonarjs/no-nested-assignment : newParameters[paramIndex] = value; return newParameters.join('/'); diff --git a/test/domain/creator/fixtures/records.fixture.ts b/test/domain/creator/fixtures/records.fixture.ts index e7623f4c..a9fa63f9 100644 --- a/test/domain/creator/fixtures/records.fixture.ts +++ b/test/domain/creator/fixtures/records.fixture.ts @@ -6,7 +6,7 @@ import { VALUES } from './values.fixture'; const DEFAULT_DATA = { portraitId: undefined, postCount: 0, followerCount: 0, followingCount: 0 }; -export const RECORDS: Record> = +export const RECORDS: Record = { CREATORS: [ { id: VALUES.IDS.CREATOR, fullName: VALUES.FULL_NAMES.CREATOR, nickname: VALUES.NICKNAMES.CREATOR, ...DEFAULT_DATA } diff --git a/test/domain/notification/create.spec.ts b/test/domain/notification/create.spec.ts index 86d3acc2..6a778ee4 100644 --- a/test/domain/notification/create.spec.ts +++ b/test/domain/notification/create.spec.ts @@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it } from 'vitest'; import create from '^/domain/notification/create/feature'; -import { RECORD_TYPE as NOTIFICATION_RECORD_TYPE, Types } from '^/domain/notification/definitions'; +import { RECORD_TYPE as NOTIFICATION_RECORD_TYPE, TypesEnum } from '^/domain/notification/definitions'; import database from '^/integrations/database/module'; @@ -20,14 +20,14 @@ describe('domain/notification/create', () => { it('should create a notification by liking a post', async () => { - await create(Types.RATED_POST, VALUES.IDS.CREATOR1, VALUES.IDS.CREATOR2, VALUES.IDS.POST_RATED); + await create(TypesEnum.RATED_POST, VALUES.IDS.CREATOR1, VALUES.IDS.CREATOR2, VALUES.IDS.POST_RATED); const notifications = await database.searchRecords(NOTIFICATION_RECORD_TYPE, {}); expect(notifications).toHaveLength(1); const notification = notifications[0]; - expect(notification.type).toBe(Types.RATED_POST); - expect(notification.createdAt).toBeDefined; + expect(notification.type).toBe(TypesEnum.RATED_POST); + expect(notification.createdAt).toBeDefined(); expect(notification.senderId).toBe(REQUESTERS.CREATOR1.id); expect(notification.receiverId).toBe(VALUES.IDS.CREATOR2); expect(notification?.postId).toBe(VALUES.IDS.POST_RATED); @@ -36,14 +36,14 @@ describe('domain/notification/create', () => it('should create a notification by liking a comic reaction', async () => { - await create(Types.RATED_REACTION, VALUES.IDS.CREATOR1, VALUES.IDS.CREATOR2, undefined, VALUES.IDS.REACTION_LIKED); + await create(TypesEnum.RATED_REACTION, VALUES.IDS.CREATOR1, VALUES.IDS.CREATOR2, undefined, VALUES.IDS.REACTION_LIKED); const notifications = await database.searchRecords(NOTIFICATION_RECORD_TYPE, {}); expect(notifications).toHaveLength(1); const notification = notifications[0]; - expect(notification.type).toBe(Types.RATED_REACTION); - expect(notification.createdAt).toBeDefined; + expect(notification.type).toBe(TypesEnum.RATED_REACTION); + expect(notification.createdAt).toBeDefined(); expect(notification.senderId).toBe(REQUESTERS.CREATOR1.id); expect(notification.receiverId).toBe(VALUES.IDS.CREATOR2); expect(notification?.postId).toBe(undefined); @@ -52,28 +52,28 @@ describe('domain/notification/create', () => it('should create a notification when someone gets followed', async () => { - await create(Types.STARTED_FOLLOWING, VALUES.IDS.CREATOR1, VALUES.IDS.CREATOR2); + await create(TypesEnum.STARTED_FOLLOWING, VALUES.IDS.CREATOR1, VALUES.IDS.CREATOR2); const notifications = await database.searchRecords(NOTIFICATION_RECORD_TYPE, {}); expect(notifications).toHaveLength(1); const notification = notifications[0]; - expect(notification.type).toBe(Types.STARTED_FOLLOWING); - expect(notification.createdAt).toBeDefined; + expect(notification.type).toBe(TypesEnum.STARTED_FOLLOWING); + expect(notification.createdAt).toBeDefined(); expect(notification.senderId).toBe(REQUESTERS.CREATOR1.id); expect(notification.receiverId).toBe(VALUES.IDS.CREATOR2); }); it('should create a notification when a reaction is added to a post', async () => { - await create(Types.ADDED_REACTION, VALUES.IDS.CREATOR1, VALUES.IDS.CREATOR2); + await create(TypesEnum.ADDED_REACTION, VALUES.IDS.CREATOR1, VALUES.IDS.CREATOR2); const notifications = await database.searchRecords(NOTIFICATION_RECORD_TYPE, {}); expect(notifications).toHaveLength(1); const notification = notifications[0]; - expect(notification.type).toBe(Types.ADDED_REACTION); - expect(notification.createdAt).toBeDefined; + expect(notification.type).toBe(TypesEnum.ADDED_REACTION); + expect(notification.createdAt).toBeDefined(); expect(notification.senderId).toBe(VALUES.IDS.CREATOR1); expect(notification.receiverId).toBe(VALUES.IDS.CREATOR2); }); diff --git a/test/domain/notification/fixtures/records.fixture.ts b/test/domain/notification/fixtures/records.fixture.ts index b71f5eac..48029fb1 100644 --- a/test/domain/notification/fixtures/records.fixture.ts +++ b/test/domain/notification/fixtures/records.fixture.ts @@ -1,11 +1,11 @@ import { RecordData } from '^/integrations/database/module'; -import { Types } from '^/domain/notification/definitions'; +import { TypesEnum } from '^/domain/notification/definitions'; import { REQUESTERS } from './requesters.fixture'; import { VALUES } from './values.fixture'; -export const RECORDS: Record> = +export const RECORDS: Record = { CREATORS: [ { id: VALUES.IDS.CREATOR1, fullName: VALUES.FULL_NAMES.CREATOR1, nickname: VALUES.NICKNAMES.CREATOR1, email: VALUES.EMAILS.CREATOR1, portraitId: undefined, joinedAt: new Date(), postCount: 0, followerCount: 1, followingCount: 1, popularity: 0 }, @@ -36,11 +36,11 @@ export const RECORDS: Record> = ], NOTIFICATIONS: [ - { id: VALUES.IDS.NOTIFICATION1, createdAt: new Date(), type: Types.STARTED_FOLLOWING, senderId: VALUES.IDS.CREATOR1, receiverId: VALUES.IDS.CREATOR2, postId: undefined, reactionId: undefined }, - { id: VALUES.IDS.NOTIFICATION2, createdAt: new Date(), type: Types.STARTED_FOLLOWING, senderId: VALUES.IDS.CREATOR2, receiverId: VALUES.IDS.CREATOR1, postId: undefined, reactionId: undefined }, - { id: VALUES.IDS.NOTIFICATION3, createdAt: new Date('01-05-2024'), type: Types.RATED_POST, senderId: VALUES.IDS.CREATOR3, receiverId: VALUES.IDS.CREATOR2, postId: VALUES.IDS.POST_RATED, reactionId: undefined }, - { id: VALUES.IDS.NOTIFICATION4, createdAt: new Date('01-04-2024'), type: Types.RATED_REACTION, senderId: VALUES.IDS.CREATOR2, receiverId: VALUES.IDS.CREATOR1, postId: undefined, reactionId: VALUES.IDS.REACTION_LIKED }, - { id: VALUES.IDS.NOTIFICATION5, createdAt: new Date('01-03-2024'), type: Types.RATED_POST, senderId: VALUES.IDS.CREATOR1, receiverId: VALUES.IDS.CREATOR1, postId: VALUES.IDS.POST_DELETED, reactionId: undefined }, + { id: VALUES.IDS.NOTIFICATION1, createdAt: new Date(), type: TypesEnum.STARTED_FOLLOWING, senderId: VALUES.IDS.CREATOR1, receiverId: VALUES.IDS.CREATOR2, postId: undefined, reactionId: undefined }, + { id: VALUES.IDS.NOTIFICATION2, createdAt: new Date(), type: TypesEnum.STARTED_FOLLOWING, senderId: VALUES.IDS.CREATOR2, receiverId: VALUES.IDS.CREATOR1, postId: undefined, reactionId: undefined }, + { id: VALUES.IDS.NOTIFICATION3, createdAt: new Date('01-05-2024'), type: TypesEnum.RATED_POST, senderId: VALUES.IDS.CREATOR3, receiverId: VALUES.IDS.CREATOR2, postId: VALUES.IDS.POST_RATED, reactionId: undefined }, + { id: VALUES.IDS.NOTIFICATION4, createdAt: new Date('01-04-2024'), type: TypesEnum.RATED_REACTION, senderId: VALUES.IDS.CREATOR2, receiverId: VALUES.IDS.CREATOR1, postId: undefined, reactionId: VALUES.IDS.REACTION_LIKED }, + { id: VALUES.IDS.NOTIFICATION5, createdAt: new Date('01-03-2024'), type: TypesEnum.RATED_POST, senderId: VALUES.IDS.CREATOR1, receiverId: VALUES.IDS.CREATOR1, postId: VALUES.IDS.POST_DELETED, reactionId: undefined }, ], }; diff --git a/test/domain/notification/getRecentAggregated.spec.ts b/test/domain/notification/getRecentAggregated.spec.ts index 776a9574..e0c5d455 100644 --- a/test/domain/notification/getRecentAggregated.spec.ts +++ b/test/domain/notification/getRecentAggregated.spec.ts @@ -1,7 +1,7 @@ import { beforeEach, describe, expect, it } from 'vitest'; -import { Types } from '^/domain/notification/definitions'; +import { TypesEnum } from '^/domain/notification/definitions'; import getRecentAggregated from '^/domain/notification/getRecentAggregated/feature'; import { DATABASES, FILE_STORES, REQUESTERS, VALUES } from './fixtures'; @@ -24,12 +24,12 @@ describe('domain/notification/getallAggregated', () => const notification1 = result[0]; const notification2 = result[1]; - expect(notification1.type).toBe(Types.STARTED_FOLLOWING); + expect(notification1.type).toBe(TypesEnum.STARTED_FOLLOWING); expect(notification1.post).toBe(undefined); expect(notification1.reaction).toBe(undefined); expect(notification1.relation.following.id).toBe(VALUES.IDS.CREATOR1); - expect(notification2.type).toBe(Types.RATED_POST); + expect(notification2.type).toBe(TypesEnum.RATED_POST); expect(notification2.post?.id).toBe(VALUES.IDS.POST_RATED); expect(notification2.reaction).toBe(undefined); expect(notification2.relation.following.id).toBe(VALUES.IDS.CREATOR3); @@ -45,12 +45,12 @@ describe('domain/notification/getallAggregated', () => const notification1 = result[0]; const notification2 = result[1]; - expect(notification1.type).toBe(Types.STARTED_FOLLOWING); + expect(notification1.type).toBe(TypesEnum.STARTED_FOLLOWING); expect(notification1.post).toBe(undefined); expect(notification1.reaction).toBe(undefined); expect(notification1.relation.following.id).toBe(VALUES.IDS.CREATOR2); - expect(notification2.type).toBe(Types.RATED_REACTION); + expect(notification2.type).toBe(TypesEnum.RATED_REACTION); expect(notification2.post).toBe(undefined); expect(notification2.reaction?.id).toBe(VALUES.IDS.REACTION_LIKED); expect(notification2.relation.following.id).toBe(VALUES.IDS.CREATOR2); diff --git a/test/domain/post/fixtures/records.fixture.ts b/test/domain/post/fixtures/records.fixture.ts index be8ca8fd..74f9205e 100644 --- a/test/domain/post/fixtures/records.fixture.ts +++ b/test/domain/post/fixtures/records.fixture.ts @@ -4,7 +4,7 @@ import { RecordData } from '^/integrations/database/module'; import { REQUESTERS } from './requesters.fixture'; import { VALUES } from './values.fixture'; -export const RECORDS: Record> = +export const RECORDS: Record = { CREATORS: [ { id: VALUES.IDS.CREATOR1, fullName: VALUES.FULL_NAMES.CREATOR1, nickname: VALUES.NICKNAMES.CREATOR1, email: VALUES.EMAILS.CREATOR1 }, diff --git a/test/domain/reaction/fixtures/records.fixture.ts b/test/domain/reaction/fixtures/records.fixture.ts index c7a4d70c..a6797053 100644 --- a/test/domain/reaction/fixtures/records.fixture.ts +++ b/test/domain/reaction/fixtures/records.fixture.ts @@ -4,7 +4,7 @@ import { RecordData } from '^/integrations/database/module'; import { REQUESTERS } from './requesters.fixture'; import { VALUES } from './values.fixture'; -export const RECORDS: Record> = +export const RECORDS: Record = { COMICS: [ { id: VALUES.IDS.COMIC, imageId: VALUES.IDS.IMAGE } diff --git a/test/domain/relation/exploreAggregated.spec.ts b/test/domain/relation/exploreAggregated.spec.ts index 02e437ef..7e868a4b 100644 --- a/test/domain/relation/exploreAggregated.spec.ts +++ b/test/domain/relation/exploreAggregated.spec.ts @@ -1,7 +1,7 @@ import { beforeEach, describe, expect, it } from 'vitest'; -import { SortOrder } from '^/domain/relation/definitions'; +import { SortOrderEnum } from '^/domain/relation/definitions'; import explore from '^/domain/relation/exploreAggregated/feature'; import { DATABASES, REQUESTERS, VALUES } from './fixtures'; @@ -15,7 +15,7 @@ describe('domain/relation/exploreAggregated', () => { it('should explore relations based on popularity', async () => { - const relations = await explore(REQUESTERS.FIRST, SortOrder.POPULAR, undefined, VALUES.RANGE); + const relations = await explore(REQUESTERS.FIRST, SortOrderEnum.POPULAR, undefined, VALUES.RANGE); expect(relations).toHaveLength(3); expect(relations[0].following?.id).toBe(VALUES.IDS.CREATOR5); expect(relations[1].following?.id).toBe(VALUES.IDS.CREATOR4); @@ -24,7 +24,7 @@ describe('domain/relation/exploreAggregated', () => it('should explore relations based on recent', async () => { - const relations = await explore(REQUESTERS.FIRST, SortOrder.RECENT, undefined, VALUES.RANGE); + const relations = await explore(REQUESTERS.FIRST, SortOrderEnum.RECENT, undefined, VALUES.RANGE); expect(relations).toHaveLength(3); expect(relations[0].following?.id).toBe(VALUES.IDS.CREATOR4); expect(relations[1].following?.id).toBe(VALUES.IDS.CREATOR6); @@ -33,27 +33,27 @@ describe('domain/relation/exploreAggregated', () => it('should find no relations based on search', async () => { - const relations = await explore(REQUESTERS.FIRST, SortOrder.POPULAR, 'or2', VALUES.RANGE); + const relations = await explore(REQUESTERS.FIRST, SortOrderEnum.POPULAR, 'or2', VALUES.RANGE); expect(relations).toHaveLength(0); }); it('should find relations based on search full name', async () => { - const relations = await explore(REQUESTERS.FIRST, SortOrder.POPULAR, 'or 4', VALUES.RANGE); + const relations = await explore(REQUESTERS.FIRST, SortOrderEnum.POPULAR, 'or 4', VALUES.RANGE); expect(relations).toHaveLength(1); expect(relations[0].following?.id).toBe(VALUES.IDS.CREATOR4); }); it('should find relations based on search nickname', async () => { - const relations = await explore(REQUESTERS.FIRST, SortOrder.POPULAR, 'creator4', VALUES.RANGE); + const relations = await explore(REQUESTERS.FIRST, SortOrderEnum.POPULAR, 'creator4', VALUES.RANGE); expect(relations).toHaveLength(1); expect(relations[0].following?.id).toBe(VALUES.IDS.CREATOR4); }); it('should find relations based on search full name and nickname', async () => { - const relations = await explore(REQUESTERS.FIRST, SortOrder.POPULAR, 'five', VALUES.RANGE); + const relations = await explore(REQUESTERS.FIRST, SortOrderEnum.POPULAR, 'five', VALUES.RANGE); expect(relations).toHaveLength(2); expect(relations[0].following?.id).toBe(VALUES.IDS.CREATOR5); expect(relations[1].following?.id).toBe(VALUES.IDS.CREATOR6); diff --git a/test/domain/relation/fixtures/records.fixture.ts b/test/domain/relation/fixtures/records.fixture.ts index 7b8dfe9a..6fde3cb5 100644 --- a/test/domain/relation/fixtures/records.fixture.ts +++ b/test/domain/relation/fixtures/records.fixture.ts @@ -5,7 +5,7 @@ import { VALUES } from './values.fixture'; const DEFAULT_DATA = { portraitId: undefined, postCount: 0, followerCount: 0, followingCount: 0 }; -export const RECORDS: Record> = +export const RECORDS: Record = { CREATORS: [ { id: VALUES.IDS.CREATOR1, fullName: 'Creator 1', nickname: 'creator1', email: 'creator1@mail.com', joinedAt: new Date(2024, 5, 23), popularity: 0, ...DEFAULT_DATA }, diff --git a/test/integrations/database/fixtures/results.fixture.ts b/test/integrations/database/fixtures/results.fixture.ts index db05db41..c3a83f09 100644 --- a/test/integrations/database/fixtures/results.fixture.ts +++ b/test/integrations/database/fixtures/results.fixture.ts @@ -5,7 +5,7 @@ import { RECORDS } from './records.fixture'; const { MARGHERITA, CALZONE, PEPPERONI, VEGETARIAN, HAWAII } = RECORDS.PIZZAS; -export const RESULTS: Record> = +export const RESULTS: Record = { EQUAL: [CALZONE, HAWAII], NOT_EQUAL: [CALZONE, VEGETARIAN], diff --git a/test/integrations/notification/implementation.spec.ts b/test/integrations/notification/implementation.spec.ts index f630024c..f10a4991 100644 --- a/test/integrations/notification/implementation.spec.ts +++ b/test/integrations/notification/implementation.spec.ts @@ -55,7 +55,7 @@ describe('integrations/notification/implementation', () => { it('should send a notification to an existing subscription', async () => { - const notifications = notificationService.subscriptions.get(VALUES.RECIPIENTS.FIRST) as Array; + const notifications = notificationService.subscriptions.get(VALUES.RECIPIENTS.FIRST) as unknown[]; await notificationService.sendNotification(VALUES.RECIPIENTS.FIRST, VALUES.NOTIFICATION.TITLE, VALUES.NOTIFICATION.BODY);