From 2ee582a5974bb81a1b358a3eb843a1a44c12940a Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 9 Dec 2025 22:38:27 +0100 Subject: [PATCH] chore: configure eslint/curly rule --- backend/__tests__/__testData__/auth.ts | 3 ++- backend/src/api/controllers/dev.ts | 9 +++++--- backend/src/api/controllers/user.ts | 3 ++- backend/src/api/controllers/webhooks.ts | 3 ++- backend/src/dal/connections.ts | 3 ++- backend/src/dal/user.ts | 18 ++++++++++------ backend/src/middlewares/configuration.ts | 12 +++++++---- backend/src/middlewares/permission.ts | 9 +++++--- .../src/ts/controllers/chart-controller.ts | 3 ++- frontend/src/ts/elements/keymap.ts | 3 ++- frontend/src/ts/elements/profile.ts | 3 ++- .../src/ts/elements/result-word-highlight.ts | 6 ++++-- .../src/ts/elements/test-activity-calendar.ts | 3 ++- frontend/src/ts/modals/simple-modals.ts | 12 +++++++---- frontend/src/ts/pages/friends.ts | 3 ++- frontend/src/ts/test/custom-text.ts | 6 ++++-- frontend/src/ts/test/replay.ts | 3 ++- frontend/src/ts/test/test-config.ts | 3 ++- frontend/src/ts/test/test-ui.ts | 21 ++++++++++++------- frontend/src/ts/utils/format.ts | 6 ++++-- frontend/src/ts/utils/ip-addresses.ts | 6 ++++-- frontend/src/ts/utils/misc.ts | 3 ++- frontend/src/ts/utils/simple-modal.ts | 3 ++- packages/oxlint-config/index.jsonc | 2 ++ 24 files changed, 98 insertions(+), 48 deletions(-) diff --git a/backend/__tests__/__testData__/auth.ts b/backend/__tests__/__testData__/auth.ts index e185d8b00..ec5a44629 100644 --- a/backend/__tests__/__testData__/auth.ts +++ b/backend/__tests__/__testData__/auth.ts @@ -12,8 +12,9 @@ export async function mockAuthenticateWithApeKey( uid: string, config: Configuration, ): Promise { - if (!config.apeKeys.acceptKeys) + if (!config.apeKeys.acceptKeys) { throw Error("config.apeKeys.acceptedKeys needs to be set to true"); + } const { apeKeyBytes, apeKeySaltRounds } = config.apeKeys; const apiKey = randomBytes(apeKeyBytes).toString("base64url"); diff --git a/backend/src/api/controllers/dev.ts b/backend/src/api/controllers/dev.ts index cbc762c55..31bd30d98 100644 --- a/backend/src/api/controllers/dev.ts +++ b/backend/src/api/controllers/dev.ts @@ -96,8 +96,9 @@ async function createTestResults( const results = createArray(day.amount, () => createResult(user, day.timestamp), ); - if (results.length > 0) + if (results.length > 0) { await ResultDal.getResultCollection().insertMany(results); + } } } @@ -222,8 +223,9 @@ async function updateUser(uid: string): Promise { )) as DBResult; personalBests[mode.mode] ??= {}; - if (personalBests[mode.mode][mode.mode2] === undefined) + if (personalBests[mode.mode][mode.mode2] === undefined) { personalBests[mode.mode][mode.mode2] = []; + } const entry = { acc: best.acc, @@ -241,8 +243,9 @@ async function updateUser(uid: string): Promise { (personalBests[mode.mode][mode.mode2] as PersonalBest[]).push(entry); if (mode.mode === "time") { - if (lbPersonalBests[mode.mode][mode.mode2] === undefined) + if (lbPersonalBests[mode.mode][mode.mode2] === undefined) { lbPersonalBests[mode.mode][mode.mode2] = {}; + } // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access lbPersonalBests[mode.mode][mode.mode2][mode.language] = entry; diff --git a/backend/src/api/controllers/user.ts b/backend/src/api/controllers/user.ts index 6620abf08..c0d5213d1 100644 --- a/backend/src/api/controllers/user.ts +++ b/backend/src/api/controllers/user.ts @@ -1207,8 +1207,9 @@ export function generateCurrentTestActivity( let thisYearData = testActivity?.[thisYear.getFullYear().toString()]; let lastYearData = testActivity?.[lastYear.getFullYear().toString()]; - if (lastYearData === undefined && thisYearData === undefined) + if (lastYearData === undefined && thisYearData === undefined) { return undefined; + } lastYearData = lastYearData ?? []; thisYearData = thisYearData ?? []; diff --git a/backend/src/api/controllers/webhooks.ts b/backend/src/api/controllers/webhooks.ts index 1f3f052de..b079ecb74 100644 --- a/backend/src/api/controllers/webhooks.ts +++ b/backend/src/api/controllers/webhooks.ts @@ -11,8 +11,9 @@ export async function githubRelease( if (action === "published") { const releaseId = req.body.release?.id; - if (releaseId === undefined) + if (releaseId === undefined) { throw new MonkeyError(422, 'Missing property "release.id".'); + } await GeorgeQueue.sendReleaseAnnouncement(releaseId); return new MonkeyResponse("Added release announcement task to queue", null); diff --git a/backend/src/dal/connections.ts b/backend/src/dal/connections.ts index 4945943d0..0500dc181 100644 --- a/backend/src/dal/connections.ts +++ b/backend/src/dal/connections.ts @@ -20,8 +20,9 @@ export async function getConnections(options: { }): Promise { const { initiatorUid, receiverUid, status } = options; - if (initiatorUid === undefined && receiverUid === undefined) + if (initiatorUid === undefined && receiverUid === undefined) { throw new Error("Missing filter"); + } let filter: Filter = { $or: [] }; diff --git a/backend/src/dal/user.ts b/backend/src/dal/user.ts index 7190644d6..67905f643 100644 --- a/backend/src/dal/user.ts +++ b/backend/src/dal/user.ts @@ -459,8 +459,9 @@ export async function checkIfPb( "stopOnLetter" in result && result.stopOnLetter === true && result.acc < 100 - ) + ) { return false; + } if (mode === "quote") { return false; @@ -510,8 +511,9 @@ export async function checkIfTagPb( "stopOnLetter" in result && result.stopOnLetter === true && result.acc < 100 - ) + ) { return []; + } if (mode === "quote") { return []; @@ -605,8 +607,9 @@ export async function linkDiscord( discordAvatar?: string, ): Promise { const updates: Partial = { discordId }; - if (discordAvatar !== undefined && discordAvatar !== null) + if (discordAvatar !== undefined && discordAvatar !== null) { updates.discordAvatar = discordAvatar; + } await updateUser({ uid }, { $set: updates }, { stack: "link discord" }); } @@ -1055,10 +1058,11 @@ export async function updateInbox( // mongo doesnt support ??= i think // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - if (inventory === null) + if (inventory === null) { inventory = { badges: [], }; + } // mongo doesnt support ??= i think // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing if (inventory.badges === null) inventory.badges = []; @@ -1104,8 +1108,9 @@ export async function updateInbox( { $unset: "tmp" }, ]); - if (update.matchedCount !== 1) + if (update.matchedCount !== 1) { throw new MonkeyError(404, "User not found", "update inbox"); + } } export async function updateStreak( @@ -1229,12 +1234,13 @@ async function updateUser( ): Promise { const result = await getUsersCollection().updateOne(filter, update); - if (result.matchedCount !== 1) + if (result.matchedCount !== 1) { throw new MonkeyError( error.statusCode ?? 404, error.message ?? "User not found", error.stack, ); + } } export async function getFriends(uid: string): Promise { diff --git a/backend/src/middlewares/configuration.ts b/backend/src/middlewares/configuration.ts index 2993df397..c14badbc5 100644 --- a/backend/src/middlewares/configuration.ts +++ b/backend/src/middlewares/configuration.ts @@ -62,26 +62,30 @@ function getValue( result = result[key]; } - if (result === undefined || result === null) + if (result === undefined || result === null) { throw new MonkeyError( 500, `Required configuration doesnt exist: "${path}"`, ); - if (typeof result !== "boolean") + } + if (typeof result !== "boolean") { throw new MonkeyError( 500, `Required configuration is not a boolean: "${path}"`, ); + } return result; } function getRequireConfigurations( metadata: EndpointMetadata | undefined, ): RequireConfiguration[] | undefined { - if (metadata === undefined || metadata.requireConfiguration === undefined) + if (metadata === undefined || metadata.requireConfiguration === undefined) { return undefined; + } - if (Array.isArray(metadata.requireConfiguration)) + if (Array.isArray(metadata.requireConfiguration)) { return metadata.requireConfiguration; + } return [metadata.requireConfiguration]; } diff --git a/backend/src/middlewares/permission.ts b/backend/src/middlewares/permission.ts index 805ce0727..ec1fad970 100644 --- a/backend/src/middlewares/permission.ts +++ b/backend/src/middlewares/permission.ts @@ -136,11 +136,13 @@ export function verifyPermissions< function getRequiredPermissionIds( metadata: EndpointMetadata | undefined, ): PermissionId[] | undefined { - if (metadata === undefined || metadata.requirePermission === undefined) + if (metadata === undefined || metadata.requirePermission === undefined) { return undefined; + } - if (Array.isArray(metadata.requirePermission)) + if (Array.isArray(metadata.requirePermission)) { return metadata.requirePermission; + } return [metadata.requirePermission]; } @@ -186,11 +188,12 @@ async function checkUserPermissions( )) as DBUser; for (const check of checks) { - if (!check.criteria(user)) + if (!check.criteria(user)) { return { passed: false, invalidMessage: check.invalidMessage, }; + } } return { diff --git a/frontend/src/ts/controllers/chart-controller.ts b/frontend/src/ts/controllers/chart-controller.ts index 424a41057..32e4de9d6 100644 --- a/frontend/src/ts/controllers/chart-controller.ts +++ b/frontend/src/ts/controllers/chart-controller.ts @@ -1360,8 +1360,9 @@ async function updateColors< ao10accDataset === undefined || ao100wpmDataset === undefined || ao100accDataset === undefined - ) + ) { return; + } if (avg10On && avg100On) { wpmDataset.pointBackgroundColor = main02; diff --git a/frontend/src/ts/elements/keymap.ts b/frontend/src/ts/elements/keymap.ts index 66f7557e7..afbe14c94 100644 --- a/frontend/src/ts/elements/keymap.ts +++ b/frontend/src/ts/elements/keymap.ts @@ -563,8 +563,9 @@ async function updateLegends(): Promise { layoutKey === undefined || lowerCaseCharacter === undefined || upperCaseCharacter === undefined - ) + ) { continue; + } const keyIsSymbol = [lowerCaseCharacter, upperCaseCharacter].some( (character) => symbolsPattern.test(character ?? ""), diff --git a/frontend/src/ts/elements/profile.ts b/frontend/src/ts/elements/profile.ts index 40a13c649..6db378ad3 100644 --- a/frontend/src/ts/elements/profile.ts +++ b/frontend/src/ts/elements/profile.ts @@ -48,8 +48,9 @@ export async function update( profile === undefined || profile.name === undefined || profile.addedAt === undefined - ) + ) { return; + } const avatar = details.find(".avatarAndName .avatar"); avatar.replaceWith(getAvatarElement(profile, { size: 256 })); diff --git a/frontend/src/ts/elements/result-word-highlight.ts b/frontend/src/ts/elements/result-word-highlight.ts index e29b7f5e2..fb2905fea 100644 --- a/frontend/src/ts/elements/result-word-highlight.ts +++ b/frontend/src/ts/elements/result-word-highlight.ts @@ -418,8 +418,9 @@ function getHighlightElementPositions( line === undefined || nextPosition === undefined || container === undefined - ) + ) { continue; + } if (!isRTL) { position.highlightLeft = @@ -460,8 +461,9 @@ function getHighlightElementPositions( line === undefined || prevHighlightPosition === undefined || container === undefined - ) + ) { continue; + } if (!isRTL) { position.highlightLeft = diff --git a/frontend/src/ts/elements/test-activity-calendar.ts b/frontend/src/ts/elements/test-activity-calendar.ts index a9b0c7495..01b72b158 100644 --- a/frontend/src/ts/elements/test-activity-calendar.ts +++ b/frontend/src/ts/elements/test-activity-calendar.ts @@ -125,8 +125,9 @@ export class TestActivityCalendar implements TestActivityCalendar { const getValue = (v: number | null | undefined): string => { if (v === undefined) return "0"; if (v === null || v === 0) return "0"; - for (let b = 0; b < 4; b++) + for (let b = 0; b < 4; b++) { if (v <= (buckets[b] ?? 0)) return (1 + b).toString(); + } return "4"; }; diff --git a/frontend/src/ts/modals/simple-modals.ts b/frontend/src/ts/modals/simple-modals.ts index c7ec89d5a..367d3ab5d 100644 --- a/frontend/src/ts/modals/simple-modals.ts +++ b/frontend/src/ts/modals/simple-modals.ts @@ -1259,14 +1259,18 @@ list.devGenerateData = new SimpleModal({ username, createUser: createUser === "true", }; - if (firstTestTimestamp !== undefined && firstTestTimestamp.length > 0) + if (firstTestTimestamp !== undefined && firstTestTimestamp.length > 0) { request.firstTestTimestamp = Date.parse(firstTestTimestamp); - if (lastTestTimestamp !== undefined && lastTestTimestamp.length > 0) + } + if (lastTestTimestamp !== undefined && lastTestTimestamp.length > 0) { request.lastTestTimestamp = Date.parse(lastTestTimestamp); - if (minTestsPerDay !== undefined && minTestsPerDay.length > 0) + } + if (minTestsPerDay !== undefined && minTestsPerDay.length > 0) { request.minTestsPerDay = Number.parseInt(minTestsPerDay); - if (maxTestsPerDay !== undefined && maxTestsPerDay.length > 0) + } + if (maxTestsPerDay !== undefined && maxTestsPerDay.length > 0) { request.maxTestsPerDay = Number.parseInt(maxTestsPerDay); + } const result = await Ape.dev.generateData({ body: request }); diff --git a/frontend/src/ts/pages/friends.ts b/frontend/src/ts/pages/friends.ts index ae3739b44..31d72ad9f 100644 --- a/frontend/src/ts/pages/friends.ts +++ b/frontend/src/ts/pages/friends.ts @@ -42,8 +42,9 @@ export function getReceiverUid( connection: Pick, ): string { const me = getAuthenticatedUser(); - if (me === null) + if (me === null) { throw new Error("expected to be authenticated in getReceiverUid"); + } if (me.uid === connection.initiatorUid) return connection.receiverUid; return connection.initiatorUid; diff --git a/frontend/src/ts/test/custom-text.ts b/frontend/src/ts/test/custom-text.ts index 63e065a77..41fa55953 100644 --- a/frontend/src/ts/test/custom-text.ts +++ b/frontend/src/ts/test/custom-text.ts @@ -140,13 +140,15 @@ export function getCustomText(name: string, long = false): string[] { if (long) { const customTextLong = getLocalStorageLong(); const customText = customTextLong[name]; - if (customText === undefined) + if (customText === undefined) { throw new Error(`Custom text ${name} not found`); + } return customText.text.split(/ +/); } else { const customText = getLocalStorage()[name]; - if (customText === undefined) + if (customText === undefined) { throw new Error(`Custom text ${name} not found`); + } return customText.split(/ +/); } } diff --git a/frontend/src/ts/test/replay.ts b/frontend/src/ts/test/replay.ts index 4aa3cc104..0e24c4c61 100644 --- a/frontend/src/ts/test/replay.ts +++ b/frontend/src/ts/test/replay.ts @@ -149,8 +149,9 @@ function handleDisplayLogic(item: Replay, nosound = false): void { const replayWords = document.getElementById("replayWords"); - if (replayWords !== null) + if (replayWords !== null) { activeWord = replayWords.children[wordPos] as HTMLElement; + } curPos = activeWord.children.length; while (activeWord.children[curPos - 1]?.className === "") curPos--; diff --git a/frontend/src/ts/test/test-config.ts b/frontend/src/ts/test/test-config.ts index ab928ae61..adde4037d 100644 --- a/frontend/src/ts/test/test-config.ts +++ b/frontend/src/ts/test/test-config.ts @@ -342,8 +342,9 @@ ConfigEvent.subscribe((eventKey, eventValue, _nosave, eventPreviousValue) => { eventKey, ) ) { - if (eventValue !== undefined) + if (eventValue !== undefined) { updateActiveExtraButtons(eventKey, eventValue); + } } }); diff --git a/frontend/src/ts/test/test-ui.ts b/frontend/src/ts/test/test-ui.ts index 26d69fa00..f05bc21ac 100644 --- a/frontend/src/ts/test/test-ui.ts +++ b/frontend/src/ts/test/test-ui.ts @@ -110,12 +110,13 @@ ConfigEvent.subscribe((eventKey, eventValue, nosave) => { if (eventValue === undefined) return; if (eventKey === "highlightMode") { - if (ActivePage.get() === "test") + if (ActivePage.get() === "test") { void updateWordLetters({ input: TestInput.input.current, wordIndex: TestState.activeWordIndex, compositionData: CompositionState.getData(), }); + } } if ( @@ -384,8 +385,9 @@ async function updateHintsPosition(): Promise { ActivePage.get() !== "test" || TestState.resultVisible || (Config.indicateTypos !== "below" && Config.indicateTypos !== "both") - ) + ) { return; + } let previousHintsContainer: HTMLElement | undefined; let hintIndices: number[][] = []; @@ -465,9 +467,10 @@ function buildWordHTML(word: string, wordIndex: number): string { } } retval += ""; - if (newlineafter) + if (newlineafter) { retval += "
"; + } return retval; } @@ -863,9 +866,11 @@ export async function updateWordLetters({ Config.indicateTypos === "both" ) { const lastBlock = hintIndices[hintIndices.length - 1]; - if (lastBlock && lastBlock[lastBlock.length - 1] === i - 1) + if (lastBlock && lastBlock[lastBlock.length - 1] === i - 1) { lastBlock.push(i); - else hintIndices.push([i]); + } else { + hintIndices.push([i]); + } } } } @@ -923,11 +928,12 @@ export async function updateWordLetters({ ); } - if (newlineafter) + if (newlineafter) { wordAtIndex.insertAdjacentHTML( "afterend", "
", ); + } if (Config.tapeMode !== "off") { void scrollTape(); } @@ -1126,8 +1132,9 @@ export async function scrollTape(noAnimation = false): Promise { if (letterOuterWidth > 0) lastPositiveLetterWidth = letterOuterWidth; } // if current letter has zero width move the tape to previous positive width letter - if (letters[inputLength]?.offsetWidth === 0) + if (letters[inputLength]?.offsetWidth === 0) { currentWordWidth -= lastPositiveLetterWidth; + } } /* change to new #words & .afterNewline margins */ diff --git a/frontend/src/ts/utils/format.ts b/frontend/src/ts/utils/format.ts index 8ee9f4fd5..c8ebab24b 100644 --- a/frontend/src/ts/utils/format.ts +++ b/frontend/src/ts/utils/format.ts @@ -69,8 +69,9 @@ export class Formatting { value: number | null | undefined, formatOptions: FormatOptions, ): string { - if (value === undefined || value === null) + if (value === undefined || value === null) { return formatOptions.fallback ?? ""; + } const suffix = formatOptions.suffix ?? ""; if ( @@ -88,8 +89,9 @@ export class Formatting { ): string { const options = { fallback: "-", ...formatOptions }; - if (position === undefined || position === null) + if (position === undefined || position === null) { return options.fallback ?? ""; + } let numend = "th"; const t = position % 10; const h = position % 100; diff --git a/frontend/src/ts/utils/ip-addresses.ts b/frontend/src/ts/utils/ip-addresses.ts index fa25468a3..ffa1be81e 100644 --- a/frontend/src/ts/utils/ip-addresses.ts +++ b/frontend/src/ts/utils/ip-addresses.ts @@ -118,9 +118,11 @@ export function compressIpv6(ip: string): string { index >= longestStartIndex && index <= longestEndIndex && longestStartIndex !== longestEndIndex - ) + ) { return ":"; - else return "0"; + } else { + return "0"; + } } return word; diff --git a/frontend/src/ts/utils/misc.ts b/frontend/src/ts/utils/misc.ts index 8f63926cb..e3e17c6a7 100644 --- a/frontend/src/ts/utils/misc.ts +++ b/frontend/src/ts/utils/misc.ts @@ -69,8 +69,9 @@ export function findGetParameter( .split("&") .forEach(function (item) { tmp = item.split("="); - if (tmp[0] === parameterName) + if (tmp[0] === parameterName) { result = decodeURIComponent(tmp[1] as string); + } }); return result; } diff --git a/frontend/src/ts/utils/simple-modal.ts b/frontend/src/ts/utils/simple-modal.ts index 633644676..ae0d19154 100644 --- a/frontend/src/ts/utils/simple-modal.ts +++ b/frontend/src/ts/utils/simple-modal.ts @@ -330,8 +330,9 @@ export class SimpleModal { }; input.currentValue = () => { - if (element.type === "checkbox") + if (element.type === "checkbox") { return element.checked ? "true" : "false"; + } return element.value; }; diff --git a/packages/oxlint-config/index.jsonc b/packages/oxlint-config/index.jsonc index ed86cd723..c72da54c0 100644 --- a/packages/oxlint-config/index.jsonc +++ b/packages/oxlint-config/index.jsonc @@ -96,6 +96,8 @@ }, ], "unicorn/prefer-includes": "error", + "unicorn/prefer-structured-clone": "error", + "eslint/curly": ["error", "multi-line", "consistent"], // todo: enable "no-array-for-each": "off",