mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 07:16:17 +08:00
chore(lint): enable no unsafe return
This commit is contained in:
parent
20c2fbc116
commit
47438fa8d1
|
@ -60,9 +60,9 @@
|
|||
"winston": "3.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@monkeytype/eslint-config": "*",
|
||||
"@monkeytype/shared-types": "*",
|
||||
"@monkeytype/typescript-config": "*",
|
||||
"@monkeytype/eslint-config": "*",
|
||||
"@redocly/cli": "1.18.1",
|
||||
"@types/bcrypt": "5.0.2",
|
||||
"@types/cors": "2.8.12",
|
||||
|
@ -70,6 +70,7 @@
|
|||
"@types/express": "4.17.21",
|
||||
"@types/ioredis": "4.28.10",
|
||||
"@types/lodash": "4.14.178",
|
||||
"@types/mjml": "4.7.4",
|
||||
"@types/mustache": "4.2.2",
|
||||
"@types/node": "20.14.11",
|
||||
"@types/node-fetch": "2.6.1",
|
||||
|
|
|
@ -24,6 +24,8 @@ export async function handleReports(
|
|||
accept: boolean
|
||||
): Promise<MonkeyResponse> {
|
||||
const { reports } = req.body;
|
||||
// TODO: remove once this gets converted to ts-rest
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
const reportIds = reports.map(({ reportId }) => reportId);
|
||||
|
||||
const reportsFromDb = await ReportDAL.getReports(reportIds);
|
||||
|
|
|
@ -185,8 +185,11 @@ async function updateUser(uid: string): Promise<void> {
|
|||
])
|
||||
.toArray();
|
||||
|
||||
const timeTyping = stats.reduce((a, c) => a + c["timeTyping"], 0);
|
||||
const completedTests = stats.reduce((a, c) => a + c["completedTests"], 0);
|
||||
const timeTyping = stats.reduce((a, c) => (a + c["timeTyping"]) as number, 0);
|
||||
const completedTests = stats.reduce(
|
||||
(a, c) => (a + c["completedTests"]) as number,
|
||||
0
|
||||
);
|
||||
|
||||
//update PBs
|
||||
const lbPersonalBests: MonkeyTypes.LbPersonalBests = {
|
||||
|
@ -203,7 +206,15 @@ async function updateUser(uid: string): Promise<void> {
|
|||
zen: {},
|
||||
quote: {},
|
||||
};
|
||||
const modes = stats.map((it) => it["_id"]);
|
||||
const modes = stats.map(
|
||||
(it) =>
|
||||
it["_id"] as {
|
||||
language: string;
|
||||
mode: "time" | "custom" | "words" | "quote" | "zen";
|
||||
mode2: `${number}` | "custom" | "zen";
|
||||
}
|
||||
);
|
||||
|
||||
for (const mode of modes) {
|
||||
const best = (
|
||||
await ResultDal.getResultCollection()
|
||||
|
|
|
@ -75,7 +75,7 @@ const usernameValidation = joi
|
|||
return helpers.error("string.pattern.base");
|
||||
}
|
||||
|
||||
return value;
|
||||
return value as string;
|
||||
})
|
||||
.messages({
|
||||
"string.profanity":
|
||||
|
@ -537,7 +537,7 @@ const profileDetailsBase = joi
|
|||
return helpers.error("string.profanity");
|
||||
}
|
||||
|
||||
return value;
|
||||
return value as string;
|
||||
})
|
||||
.messages({
|
||||
"string.profanity":
|
||||
|
|
|
@ -35,12 +35,21 @@ export async function getSpeedHistogram(
|
|||
language: string,
|
||||
mode: string,
|
||||
mode2: string
|
||||
): Promise<Record<string, number>> {
|
||||
const key = `${language}_${mode}_${mode2}`;
|
||||
): Promise<SpeedHistogram> {
|
||||
const key = `${language}_${mode}_${mode2}` as keyof PublicSpeedStatsDB;
|
||||
|
||||
if (key === "_id") {
|
||||
throw new MonkeyError(
|
||||
400,
|
||||
"Invalid speed histogram key",
|
||||
"get speed histogram"
|
||||
);
|
||||
}
|
||||
|
||||
const stats = await db
|
||||
.collection<PublicSpeedStatsDB>("public")
|
||||
.findOne({ _id: "speedStatsHistogram" }, { projection: { [key]: 1 } });
|
||||
|
||||
return stats?.[key] ?? {};
|
||||
}
|
||||
|
||||
|
|
|
@ -742,10 +742,10 @@ export async function getPersonalBests(
|
|||
]);
|
||||
|
||||
if (mode2 !== undefined) {
|
||||
return user.personalBests?.[mode]?.[mode2];
|
||||
return user.personalBests?.[mode]?.[mode2] as PersonalBest;
|
||||
}
|
||||
|
||||
return user.personalBests?.[mode];
|
||||
return user.personalBests?.[mode] as PersonalBest;
|
||||
}
|
||||
|
||||
export async function getStats(
|
||||
|
|
|
@ -42,9 +42,12 @@ export function withApeRateLimiter(
|
|||
return (req: MonkeyTypes.Request, res: Response, next: NextFunction) => {
|
||||
if (req.ctx.decodedToken.type === "ApeKey") {
|
||||
const rateLimiter = apeRateLimiterOverride ?? apeRateLimiter;
|
||||
// TODO: bump version?
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return rateLimiter(req, res, next);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return defaultRateLimiter(req, res, next);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ export class WeeklyXpLeaderboard {
|
|||
entry.uid,
|
||||
xpGained,
|
||||
JSON.stringify({ ...entry, timeTypedSeconds: totalTimeTypedSeconds })
|
||||
),
|
||||
) as Promise<number>,
|
||||
LaterQueue.scheduleForNextWeek(
|
||||
"weekly-xp-leaderboard-results",
|
||||
"weekly-xp"
|
||||
|
@ -155,11 +155,16 @@ export class WeeklyXpLeaderboard {
|
|||
}
|
||||
|
||||
const resultsWithRanks: WeeklyXpLeaderboardEntry[] = results.map(
|
||||
(resultJSON: string, index: number) => ({
|
||||
...JSON.parse(resultJSON),
|
||||
rank: minRank + index + 1,
|
||||
totalXp: parseInt(scores[index] as string, 10),
|
||||
})
|
||||
(resultJSON: string, index: number) => {
|
||||
//TODO parse with zod?
|
||||
const parsed = JSON.parse(resultJSON) as WeeklyXpLeaderboardEntry;
|
||||
|
||||
return {
|
||||
...parsed,
|
||||
rank: minRank + index + 1,
|
||||
totalXp: parseInt(scores[index] as string, 10),
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
return resultsWithRanks;
|
||||
|
@ -193,11 +198,17 @@ export class WeeklyXpLeaderboard {
|
|||
return null;
|
||||
}
|
||||
|
||||
//TODO parse with zod?
|
||||
const parsed = JSON.parse(result ?? "null") as Omit<
|
||||
WeeklyXpLeaderboardEntry,
|
||||
"rank" | "count" | "totalXp"
|
||||
>;
|
||||
|
||||
return {
|
||||
rank: rank + 1,
|
||||
count: count ?? 0,
|
||||
totalXp: parseInt(totalXp, 10),
|
||||
...JSON.parse(result ?? "null"),
|
||||
...parsed,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ export class DailyLeaderboard {
|
|||
const resultScore = kogascore(entry.wpm, entry.acc, entry.timestamp);
|
||||
|
||||
// @ts-expect-error
|
||||
const rank = await connection.addResult(
|
||||
const rank = (await connection.addResult(
|
||||
2,
|
||||
leaderboardScoresKey,
|
||||
leaderboardResultsKey,
|
||||
|
@ -100,7 +100,7 @@ export class DailyLeaderboard {
|
|||
entry.uid,
|
||||
resultScore,
|
||||
JSON.stringify(entry)
|
||||
);
|
||||
)) as number;
|
||||
|
||||
if (
|
||||
isValidModeRule(
|
||||
|
@ -153,10 +153,15 @@ export class DailyLeaderboard {
|
|||
}
|
||||
|
||||
const resultsWithRanks: LbEntryWithRank[] = results.map(
|
||||
(resultJSON, index) => ({
|
||||
...JSON.parse(resultJSON),
|
||||
rank: minRank + index + 1,
|
||||
})
|
||||
(resultJSON, index) => {
|
||||
// TODO: parse with zod?
|
||||
const parsed = JSON.parse(resultJSON) as LbEntryWithRank;
|
||||
|
||||
return {
|
||||
...parsed,
|
||||
rank: minRank + index + 1,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
if (!premiumFeaturesEnabled) {
|
||||
|
|
|
@ -101,10 +101,12 @@ function apeifyClientMethod(
|
|||
errorMessage = typedError.message;
|
||||
|
||||
if (isAxiosError(typedError)) {
|
||||
const data = typedError.response?.data as { data: TData };
|
||||
|
||||
return {
|
||||
status: typedError.response?.status ?? 500,
|
||||
message: typedError.message,
|
||||
...typedError.response?.data,
|
||||
...data,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,5 +36,6 @@ export function getResponse(id: string): string {
|
|||
}
|
||||
|
||||
//@ts-expect-error
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return grecaptcha.getResponse(captchas[id]);
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ class ChartWithUpdateColors<
|
|||
id: DatasetIds extends never ? never : "x" | DatasetIds
|
||||
): DatasetIds extends never ? never : CartesianScaleOptions {
|
||||
//@ts-expect-error
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return this.options.scales[id];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ function getParams(match: {
|
|||
(result) => result[1]
|
||||
);
|
||||
|
||||
return Object.fromEntries(keys.map((key, index) => [key, values[index]]));
|
||||
const a = keys.map((key, index) => [key, values[index]]);
|
||||
return Object.fromEntries(a) as Record<string, string>;
|
||||
}
|
||||
|
||||
type Route = {
|
||||
|
|
|
@ -221,7 +221,7 @@ export async function setFilterPreset(id: string): Promise<void> {
|
|||
}
|
||||
|
||||
function deepCopyFilter(filter: ResultFilters): ResultFilters {
|
||||
return JSON.parse(JSON.stringify(filter));
|
||||
return JSON.parse(JSON.stringify(filter)) as ResultFilters;
|
||||
}
|
||||
|
||||
function addFilterPresetToSnapshot(filter: ResultFilters): void {
|
||||
|
|
|
@ -11,7 +11,12 @@ function clearMemory(): void {
|
|||
}
|
||||
|
||||
function getMemory(): string[] {
|
||||
return JSON.parse(window.localStorage.getItem("confirmedPSAs") ?? "[]") ?? [];
|
||||
//TODO verify with zod?
|
||||
return (
|
||||
(JSON.parse(
|
||||
window.localStorage.getItem("confirmedPSAs") ?? "[]"
|
||||
) as string[]) ?? []
|
||||
);
|
||||
}
|
||||
|
||||
function setMemory(id: string): void {
|
||||
|
|
|
@ -57,7 +57,9 @@ export class TestActivityCalendar implements MonkeyTypes.TestActivityCalendar {
|
|||
lastDay: Date
|
||||
): (number | null | undefined)[] {
|
||||
//fill calendar with enough values
|
||||
const values = new Array(Math.max(0, 386 - data.length)).fill(undefined);
|
||||
const values: (number | null | undefined)[] = new Array(
|
||||
Math.max(0, 386 - data.length)
|
||||
).fill(undefined);
|
||||
values.push(...data);
|
||||
|
||||
//discard values outside the calendar range
|
||||
|
|
|
@ -13,7 +13,8 @@ type Accepted = {
|
|||
function getAcceptedObject(): Accepted | null {
|
||||
const acceptedCookies = localStorage.getItem("acceptedCookies") ?? "";
|
||||
if (acceptedCookies) {
|
||||
return JSON.parse(acceptedCookies);
|
||||
//TODO verify with zod?
|
||||
return JSON.parse(acceptedCookies) as Accepted;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@ import { Mode, Mode2 } from "@monkeytype/contracts/schemas/shared";
|
|||
import { CustomTextData } from "@monkeytype/shared-types";
|
||||
|
||||
function getCheckboxValue(checkbox: string): boolean {
|
||||
return $(`#shareTestSettingsModal label.${checkbox} input`).prop("checked");
|
||||
return $(`#shareTestSettingsModal label.${checkbox} input`).prop(
|
||||
"checked"
|
||||
) as boolean;
|
||||
}
|
||||
|
||||
type SharedTestSettings = [
|
||||
|
|
|
@ -874,7 +874,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
|
|||
return 1;
|
||||
} else if (typeof input === "object" && input !== null) {
|
||||
return Object.values(input).reduce(
|
||||
(a, b) => a + countUndefined(b),
|
||||
(a, b) => (a + countUndefined(b)) as number,
|
||||
0
|
||||
) as number;
|
||||
} else {
|
||||
|
|
|
@ -11,7 +11,7 @@ async function fetchJson<T>(url: string): Promise<T> {
|
|||
if (!url) throw new Error("No URL");
|
||||
const res = await fetch(url);
|
||||
if (res.ok) {
|
||||
return await res.json();
|
||||
return (await res.json()) as T;
|
||||
} else {
|
||||
throw new Error(`${res.status} ${res.statusText}`);
|
||||
}
|
||||
|
|
18
package-lock.json
generated
18
package-lock.json
generated
|
@ -93,6 +93,7 @@
|
|||
"@types/express": "4.17.21",
|
||||
"@types/ioredis": "4.28.10",
|
||||
"@types/lodash": "4.14.178",
|
||||
"@types/mjml": "4.7.4",
|
||||
"@types/mustache": "4.2.2",
|
||||
"@types/node": "20.14.11",
|
||||
"@types/node-fetch": "2.6.1",
|
||||
|
@ -6884,6 +6885,23 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/mjml": {
|
||||
"version": "4.7.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/mjml/-/mjml-4.7.4.tgz",
|
||||
"integrity": "sha512-vyi1vzWgMzFMwZY7GSZYX0GU0dmtC8vLHwpgk+NWmwbwRSrlieVyJ9sn5elodwUfklJM7yGl0zQeet1brKTWaQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/mjml-core": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/mjml-core": {
|
||||
"version": "4.15.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/mjml-core/-/mjml-core-4.15.0.tgz",
|
||||
"integrity": "sha512-jSRWTOpwRS/uHIBfGdvLl0a7MaoBZZYHKI+HhsFYChrUOKVJTnjSYsuV6wx0snv6ZaX3TUo5OP/gNsz/uzZz1A==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/mustache": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/mustache/-/mustache-4.2.2.tgz",
|
||||
|
|
|
@ -70,7 +70,6 @@ module.exports = {
|
|||
"@typescript-eslint/restrict-plus-operands": "off",
|
||||
|
||||
// TODO: enable at some point
|
||||
"@typescript-eslint/no-unsafe-return": "off", //~12
|
||||
"@typescript-eslint/no-unsafe-assignment": "off", //~63
|
||||
"@typescript-eslint/no-unsafe-argument": "off", //~37
|
||||
"@typescript-eslint/no-unsafe-call": "off", //~76
|
||||
|
|
Loading…
Reference in a new issue