Skip to content

Commit ceedf8a

Browse files
authored
refactor: enable no-unsafe-call rule (@Miodec) (#5883)
### Description <!-- Please describe the change(s) made in your PR --> ### Checks - [ ] Adding quotes? - [ ] Make sure to include translations for the quotes in the description (or another comment) so we can verify their content. - [ ] Adding a language or a theme? - [ ] If is a language, did you edit `_list.json`, `_groups.json` and add `languages.json`? - [ ] If is a theme, did you add the theme.css? - Also please add a screenshot of the theme, it would be extra awesome if you do so! - [ ] Check if any open issues are related to this PR; if so, be sure to tag them below. - [ ] Make sure the PR title follows the Conventional Commits standard. (https://www.conventionalcommits.org for more info) - [ ] Make sure to include your GitHub username prefixed with @ inside parentheses at the end of the PR title. <!-- label(optional scope): pull request title (@your_github_username) --> <!-- I know I know they seem boring but please do them, they help us and you will find out it also helps you.--> Closes # <!-- the issue(s) your PR resolves if any (delete if that is not the case) --> <!-- please also reference any issues and or PRs related to your pull request --> <!-- Also remove it if you are not following any issues. --> <!-- pro tip: you can mention an issue, PR, or discussion on GitHub by referencing its hash number e.g: [#1234](#1234) --> <!-- pro tip: you can press . (dot or period) in the code tab of any GitHub repo to get access to GitHub's VS Code web editor Enjoy! :) -->
1 parent 84166ce commit ceedf8a

File tree

17 files changed

+48
-27
lines changed

17 files changed

+48
-27
lines changed

backend/src/api/controllers/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ async function updateUser(uid: string): Promise<void> {
241241
timestamp: best.timestamp,
242242
} as PersonalBest;
243243

244-
personalBests[mode.mode][mode.mode2].push(entry);
244+
(personalBests[mode.mode][mode.mode2] as PersonalBest[]).push(entry);
245245

246246
if (mode.mode === "time") {
247247
if (lbPersonalBests[mode.mode][mode.mode2] === undefined)

backend/src/dal/new-quotes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { simpleGit } from "simple-git";
1+
import { SimpleGit, simpleGit } from "simple-git";
22
import { Collection, ObjectId } from "mongodb";
33
import path from "path";
44
import { existsSync, writeFileSync } from "fs";
@@ -24,7 +24,7 @@ type QuoteData = {
2424

2525
const PATH_TO_REPO = "../../../../monkeytype-new-quotes";
2626

27-
let git;
27+
let git: SimpleGit | undefined;
2828
try {
2929
git = simpleGit(path.join(__dirname, PATH_TO_REPO));
3030
} catch (e) {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ export class WeeklyXpLeaderboard {
9696
timeTypedSeconds + (currentEntryTimeTypedSeconds ?? 0);
9797

9898
const [rank] = await Promise.all([
99-
// @ts-expect-error
99+
// @ts-expect-error we are doing some weird file to function mapping, thats why its any
100+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
100101
connection.addResultIncrement(
101102
2,
102103
weeklyXpLeaderboardScoresKey,
@@ -128,7 +129,8 @@ export class WeeklyXpLeaderboard {
128129
const { weeklyXpLeaderboardScoresKey, weeklyXpLeaderboardResultsKey } =
129130
this.getThisWeeksXpLeaderboardKeys();
130131

131-
// @ts-expect-error
132+
// @ts-expect-error we are doing some weird file to function mapping, thats why its any
133+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
132134
const [results, scores] = (await connection.getResults(
133135
2, // How many of the arguments are redis keys (https://redis.io/docs/manual/programmability/lua-api/)
134136
weeklyXpLeaderboardScoresKey,

backend/src/utils/daily-leaderboards.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export class DailyLeaderboard {
7474

7575
const resultScore = kogascore(entry.wpm, entry.acc, entry.timestamp);
7676

77-
// @ts-expect-error
77+
// @ts-expect-error we are doing some weird file to function mapping, thats why its any
78+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
7879
const rank = (await connection.addResult(
7980
2,
8081
leaderboardScoresKey,
@@ -120,7 +121,8 @@ export class DailyLeaderboard {
120121
const { leaderboardScoresKey, leaderboardResultsKey } =
121122
this.getTodaysLeaderboardKeys();
122123

123-
// @ts-expect-error
124+
// @ts-expect-error we are doing some weird file to function mapping, thats why its any
125+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
124126
const [results] = (await connection.getResults(
125127
2,
126128
leaderboardScoresKey,
@@ -213,7 +215,8 @@ export async function purgeUserFromDailyLeaderboards(
213215
return;
214216
}
215217

216-
// @ts-expect-error
218+
// @ts-expect-error we are doing some weird file to function mapping, thats why its any
219+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
217220
await connection.purgeResults(0, uid, dailyLeaderboardNamespace);
218221
}
219222

backend/src/utils/pb.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function checkAndUpdatePb(
5555
const didUpdate = updatePersonalBest(personalBestMatch, result);
5656
isPb = didUpdate;
5757
} else {
58-
userPb[mode][mode2].push(buildPersonalBest(result));
58+
(userPb[mode][mode2] as PersonalBest[]).push(buildPersonalBest(result));
5959
}
6060

6161
if (!_.isNil(lbPersonalBests)) {
@@ -186,15 +186,17 @@ export function updateLeaderboardPersonalBests(
186186
lbPb[mode] ??= {};
187187
lbPb[mode][mode2] ??= {};
188188
const bestForEveryLanguage = {};
189-
userPersonalBests[mode][mode2].forEach((pb: PersonalBest) => {
190-
const language = pb.language;
191-
if (
192-
bestForEveryLanguage[language] === undefined ||
193-
bestForEveryLanguage[language].wpm < pb.wpm
194-
) {
195-
bestForEveryLanguage[language] = pb;
189+
(userPersonalBests[mode][mode2] as PersonalBest[]).forEach(
190+
(pb: PersonalBest) => {
191+
const language = pb.language;
192+
if (
193+
bestForEveryLanguage[language] === undefined ||
194+
bestForEveryLanguage[language].wpm < pb.wpm
195+
) {
196+
bestForEveryLanguage[language] = pb;
197+
}
196198
}
197-
});
199+
);
198200
_.each(bestForEveryLanguage, (pb: PersonalBest, language: string) => {
199201
const languageDoesNotExist = lbPb[mode][mode2][language] === undefined;
200202
const languageIsEmpty = _.isEmpty(lbPb[mode][mode2][language]);

frontend/src/ts/controllers/ad-controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export async function checkCookieblocker(): Promise<void> {
175175
return;
176176
}
177177
//@ts-expect-error
178+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
178179
window.__tcfapi("getTCData", 2, (tcData, success) => {
179180
if (success as boolean) {
180181
if (tcData.eventStatus === "cmpuishown") {
@@ -268,11 +269,13 @@ export function updateFooterAndVerticalAds(visible: boolean): void {
268269
export function showConsentPopup(): void {
269270
if (choice === "eg") {
270271
//@ts-expect-error
272+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
271273
window.__tcfapi("displayConsentUi", 2, function () {
272274
//
273275
});
274276
} else {
275277
//@ts-expect-error
278+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
276279
ramp.showCmpModal();
277280
}
278281
}

frontend/src/ts/controllers/captcha-controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function render(
1313
}
1414

1515
//@ts-expect-error
16-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
16+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
1717
const widgetId = grecaptcha.render(element, {
1818
sitekey: siteKey,
1919
callback,
@@ -28,6 +28,7 @@ export function reset(id: string): void {
2828
}
2929

3030
//@ts-expect-error
31+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
3132
grecaptcha.reset(captchas[id]);
3233
}
3334

@@ -37,6 +38,6 @@ export function getResponse(id: string): string {
3738
}
3839

3940
//@ts-expect-error
40-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
41+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
4142
return grecaptcha.getResponse(captchas[id]);
4243
}

frontend/src/ts/controllers/eg-ad-controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function init(): void {
1515
export function renderResult(widerThanBreakpoint: boolean): void {
1616
if (widerThanBreakpoint) {
1717
//@ts-expect-error
18+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
1819
window.egAps.render([
1920
"ad-result",
2021
"ad-vertical-left",
@@ -23,6 +24,7 @@ export function renderResult(widerThanBreakpoint: boolean): void {
2324
]);
2425
} else {
2526
//@ts-expect-error
27+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
2628
window.egAps.render([
2729
"ad-result-small",
2830
"ad-vertical-left",
@@ -35,6 +37,7 @@ export function renderResult(widerThanBreakpoint: boolean): void {
3537
export function reinstate(): boolean {
3638
try {
3739
//@ts-expect-error
40+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
3841
window.egAps.reinstate();
3942
return true;
4043
} catch (e) {

frontend/src/ts/controllers/pw-ad-controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-call */
12
//@ts-nocheck
23

34
import Config from "../config";

frontend/src/ts/controllers/sound-controller.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,8 @@ export async function previewError(val: string): Promise<void> {
412412
const errorSoundIds = Object.keys(safeErrorSounds);
413413
if (!errorSoundIds.includes(val)) return;
414414

415-
//@ts-expect-error
416-
errorClickSounds[val][0].sounds[0].seek(0);
417-
//@ts-expect-error
418-
errorClickSounds[val][0].sounds[0].play();
415+
errorSounds?.[val]?.[0]?.sounds[0]?.seek(0);
416+
errorSounds?.[val]?.[0]?.sounds[0]?.play();
419417
}
420418

421419
let currentCode = "KeyA";

0 commit comments

Comments
 (0)