Skip to content

Commit 47438fa

Browse files
committed
chore(lint): enable no unsafe return
1 parent 20c2fbc commit 47438fa

22 files changed

Lines changed: 107 additions & 33 deletions

File tree

backend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,17 @@
6060
"winston": "3.6.0"
6161
},
6262
"devDependencies": {
63+
"@monkeytype/eslint-config": "*",
6364
"@monkeytype/shared-types": "*",
6465
"@monkeytype/typescript-config": "*",
65-
"@monkeytype/eslint-config": "*",
6666
"@redocly/cli": "1.18.1",
6767
"@types/bcrypt": "5.0.2",
6868
"@types/cors": "2.8.12",
6969
"@types/cron": "1.7.3",
7070
"@types/express": "4.17.21",
7171
"@types/ioredis": "4.28.10",
7272
"@types/lodash": "4.14.178",
73+
"@types/mjml": "4.7.4",
7374
"@types/mustache": "4.2.2",
7475
"@types/node": "20.14.11",
7576
"@types/node-fetch": "2.6.1",

backend/src/api/controllers/admin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export async function handleReports(
2424
accept: boolean
2525
): Promise<MonkeyResponse> {
2626
const { reports } = req.body;
27+
// TODO: remove once this gets converted to ts-rest
28+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
2729
const reportIds = reports.map(({ reportId }) => reportId);
2830

2931
const reportsFromDb = await ReportDAL.getReports(reportIds);

backend/src/api/controllers/dev.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,11 @@ async function updateUser(uid: string): Promise<void> {
185185
])
186186
.toArray();
187187

188-
const timeTyping = stats.reduce((a, c) => a + c["timeTyping"], 0);
189-
const completedTests = stats.reduce((a, c) => a + c["completedTests"], 0);
188+
const timeTyping = stats.reduce((a, c) => (a + c["timeTyping"]) as number, 0);
189+
const completedTests = stats.reduce(
190+
(a, c) => (a + c["completedTests"]) as number,
191+
0
192+
);
190193

191194
//update PBs
192195
const lbPersonalBests: MonkeyTypes.LbPersonalBests = {
@@ -203,7 +206,15 @@ async function updateUser(uid: string): Promise<void> {
203206
zen: {},
204207
quote: {},
205208
};
206-
const modes = stats.map((it) => it["_id"]);
209+
const modes = stats.map(
210+
(it) =>
211+
it["_id"] as {
212+
language: string;
213+
mode: "time" | "custom" | "words" | "quote" | "zen";
214+
mode2: `${number}` | "custom" | "zen";
215+
}
216+
);
217+
207218
for (const mode of modes) {
208219
const best = (
209220
await ResultDal.getResultCollection()

backend/src/api/routes/users.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const usernameValidation = joi
7575
return helpers.error("string.pattern.base");
7676
}
7777

78-
return value;
78+
return value as string;
7979
})
8080
.messages({
8181
"string.profanity":
@@ -537,7 +537,7 @@ const profileDetailsBase = joi
537537
return helpers.error("string.profanity");
538538
}
539539

540-
return value;
540+
return value as string;
541541
})
542542
.messages({
543543
"string.profanity":

backend/src/dal/public.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,21 @@ export async function getSpeedHistogram(
3535
language: string,
3636
mode: string,
3737
mode2: string
38-
): Promise<Record<string, number>> {
39-
const key = `${language}_${mode}_${mode2}`;
38+
): Promise<SpeedHistogram> {
39+
const key = `${language}_${mode}_${mode2}` as keyof PublicSpeedStatsDB;
40+
41+
if (key === "_id") {
42+
throw new MonkeyError(
43+
400,
44+
"Invalid speed histogram key",
45+
"get speed histogram"
46+
);
47+
}
4048

4149
const stats = await db
4250
.collection<PublicSpeedStatsDB>("public")
4351
.findOne({ _id: "speedStatsHistogram" }, { projection: { [key]: 1 } });
52+
4453
return stats?.[key] ?? {};
4554
}
4655

backend/src/dal/user.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,10 @@ export async function getPersonalBests(
742742
]);
743743

744744
if (mode2 !== undefined) {
745-
return user.personalBests?.[mode]?.[mode2];
745+
return user.personalBests?.[mode]?.[mode2] as PersonalBest;
746746
}
747747

748-
return user.personalBests?.[mode];
748+
return user.personalBests?.[mode] as PersonalBest;
749749
}
750750

751751
export async function getStats(

backend/src/middlewares/ape-rate-limit.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ export function withApeRateLimiter(
4242
return (req: MonkeyTypes.Request, res: Response, next: NextFunction) => {
4343
if (req.ctx.decodedToken.type === "ApeKey") {
4444
const rateLimiter = apeRateLimiterOverride ?? apeRateLimiter;
45+
// TODO: bump version?
46+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
4547
return rateLimiter(req, res, next);
4648
}
4749

50+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
4851
return defaultRateLimiter(req, res, next);
4952
};
5053
}

backend/src/services/weekly-xp-leaderboard.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class WeeklyXpLeaderboard {
109109
entry.uid,
110110
xpGained,
111111
JSON.stringify({ ...entry, timeTypedSeconds: totalTimeTypedSeconds })
112-
),
112+
) as Promise<number>,
113113
LaterQueue.scheduleForNextWeek(
114114
"weekly-xp-leaderboard-results",
115115
"weekly-xp"
@@ -155,11 +155,16 @@ export class WeeklyXpLeaderboard {
155155
}
156156

157157
const resultsWithRanks: WeeklyXpLeaderboardEntry[] = results.map(
158-
(resultJSON: string, index: number) => ({
159-
...JSON.parse(resultJSON),
160-
rank: minRank + index + 1,
161-
totalXp: parseInt(scores[index] as string, 10),
162-
})
158+
(resultJSON: string, index: number) => {
159+
//TODO parse with zod?
160+
const parsed = JSON.parse(resultJSON) as WeeklyXpLeaderboardEntry;
161+
162+
return {
163+
...parsed,
164+
rank: minRank + index + 1,
165+
totalXp: parseInt(scores[index] as string, 10),
166+
};
167+
}
163168
);
164169

165170
return resultsWithRanks;
@@ -193,11 +198,17 @@ export class WeeklyXpLeaderboard {
193198
return null;
194199
}
195200

201+
//TODO parse with zod?
202+
const parsed = JSON.parse(result ?? "null") as Omit<
203+
WeeklyXpLeaderboardEntry,
204+
"rank" | "count" | "totalXp"
205+
>;
206+
196207
return {
197208
rank: rank + 1,
198209
count: count ?? 0,
199210
totalXp: parseInt(totalXp, 10),
200-
...JSON.parse(result ?? "null"),
211+
...parsed,
201212
};
202213
}
203214
}

backend/src/utils/daily-leaderboards.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class DailyLeaderboard {
9191
const resultScore = kogascore(entry.wpm, entry.acc, entry.timestamp);
9292

9393
// @ts-expect-error
94-
const rank = await connection.addResult(
94+
const rank = (await connection.addResult(
9595
2,
9696
leaderboardScoresKey,
9797
leaderboardResultsKey,
@@ -100,7 +100,7 @@ export class DailyLeaderboard {
100100
entry.uid,
101101
resultScore,
102102
JSON.stringify(entry)
103-
);
103+
)) as number;
104104

105105
if (
106106
isValidModeRule(
@@ -153,10 +153,15 @@ export class DailyLeaderboard {
153153
}
154154

155155
const resultsWithRanks: LbEntryWithRank[] = results.map(
156-
(resultJSON, index) => ({
157-
...JSON.parse(resultJSON),
158-
rank: minRank + index + 1,
159-
})
156+
(resultJSON, index) => {
157+
// TODO: parse with zod?
158+
const parsed = JSON.parse(resultJSON) as LbEntryWithRank;
159+
160+
return {
161+
...parsed,
162+
rank: minRank + index + 1,
163+
};
164+
}
160165
);
161166

162167
if (!premiumFeaturesEnabled) {

frontend/src/ts/ape/adapters/axios-adapter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ function apeifyClientMethod(
101101
errorMessage = typedError.message;
102102

103103
if (isAxiosError(typedError)) {
104+
const data = typedError.response?.data as { data: TData };
105+
104106
return {
105107
status: typedError.response?.status ?? 500,
106108
message: typedError.message,
107-
...typedError.response?.data,
109+
...data,
108110
};
109111
}
110112
}

0 commit comments

Comments
 (0)