chore: configure eslint/curly rule

This commit is contained in:
Miodec 2025-12-09 22:38:27 +01:00
parent b5a03e0040
commit 2ee582a597
24 changed files with 98 additions and 48 deletions

View file

@ -12,8 +12,9 @@ export async function mockAuthenticateWithApeKey(
uid: string,
config: Configuration,
): Promise<string> {
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");

View file

@ -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<void> {
)) 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<void> {
(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;

View file

@ -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 ?? [];

View file

@ -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);

View file

@ -20,8 +20,9 @@ export async function getConnections(options: {
}): Promise<DBConnection[]> {
const { initiatorUid, receiverUid, status } = options;
if (initiatorUid === undefined && receiverUid === undefined)
if (initiatorUid === undefined && receiverUid === undefined) {
throw new Error("Missing filter");
}
let filter: Filter<DBConnection> = { $or: [] };

View file

@ -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<void> {
const updates: Partial<DBUser> = { 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<void> {
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<DBFriend[]> {

View file

@ -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];
}

View file

@ -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 {

View file

@ -1360,8 +1360,9 @@ async function updateColors<
ao10accDataset === undefined ||
ao100wpmDataset === undefined ||
ao100accDataset === undefined
)
) {
return;
}
if (avg10On && avg100On) {
wpmDataset.pointBackgroundColor = main02;

View file

@ -563,8 +563,9 @@ async function updateLegends(): Promise<void> {
layoutKey === undefined ||
lowerCaseCharacter === undefined ||
upperCaseCharacter === undefined
)
) {
continue;
}
const keyIsSymbol = [lowerCaseCharacter, upperCaseCharacter].some(
(character) => symbolsPattern.test(character ?? ""),

View file

@ -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 }));

View file

@ -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 =

View file

@ -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";
};

View file

@ -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 });

View file

@ -42,8 +42,9 @@ export function getReceiverUid(
connection: Pick<Connection, "initiatorUid" | "receiverUid">,
): 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;

View file

@ -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(/ +/);
}
}

View file

@ -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--;

View file

@ -342,8 +342,9 @@ ConfigEvent.subscribe((eventKey, eventValue, _nosave, eventPreviousValue) => {
eventKey,
)
) {
if (eventValue !== undefined)
if (eventValue !== undefined) {
updateActiveExtraButtons(eventKey, eventValue);
}
}
});

View file

@ -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<void> {
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 += "</div>";
if (newlineafter)
if (newlineafter) {
retval +=
"<div class='beforeNewline'></div><div class='newline'></div><div class='afterNewline'></div>";
}
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",
"<div class='beforeNewline'></div><div class='newline'></div><div class='afterNewline'></div>",
);
}
if (Config.tapeMode !== "off") {
void scrollTape();
}
@ -1126,8 +1132,9 @@ export async function scrollTape(noAnimation = false): Promise<void> {
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 */

View file

@ -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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
};

View file

@ -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",