Skip to content

Commit cac8835

Browse files
authored
chore: add oxlint (@Miodec) (monkeytypegame#6455)
Use oxlint for general linting to provide much quicker feedback. Keep eslint for type-aware rules. Fully switch to oxlint once it supports type-aware.
1 parent 92d97c1 commit cac8835

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+588
-177
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
![ChartJs](https://img.shields.io/badge/Chart.js-FF6384?style=for-the-badge&logo=chartdotjs&logoColor=white)
55
![Eslint](https://img.shields.io/badge/eslint-4B32C3?style=for-the-badge&logo=eslint&logoColor=white)
6+
![OXLint](https://img.shields.io/badge/oxlint-91ede9?style=for-the-badge&logoColor=white)
67
![Express](https://img.shields.io/badge/-Express-373737?style=for-the-badge&logo=Express&logoColor=white)
78
![Firebase](https://img.shields.io/badge/firebase-ffca28?style=for-the-badge&logo=firebase&logoColor=black)
89
![Fontawesome](https://img.shields.io/badge/fontawesome-538DD7?style=for-the-badge&logo=fontawesome&logoColor=white)

backend/.oxlintrc.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": [
3+
"../packages/oxlint-config/index.json"
4+
// "@monkeytype/oxlint-config"
5+
],
6+
"overrides": [
7+
{
8+
"files": ["__tests__/**"],
9+
"plugins": ["jest", "vitest"],
10+
"rules": {
11+
"no-explicit-any": "allow",
12+
"explicit-function-return-type": "off"
13+
}
14+
}
15+
]
16+
}

backend/__tests__/api/controllers/result.spec.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -874,26 +874,24 @@ describe("result controller test", () => {
874874
});
875875
});
876876

877-
it("should fail invalid properties", async () => {
878-
//GIVEN
879-
880-
//WHEN
881-
const { body } = await mockApp
882-
.post("/results")
883-
.set("Authorization", `Bearer ${uid}`)
884-
//TODO add all properties
885-
.send({ result: { acc: 25 } })
886-
.expect(422);
887-
888-
//THEN
889-
/*
877+
// it("should fail invalid properties ", async () => {
878+
//GIVEN
879+
//WHEN
880+
// const { body } = await mockApp
881+
// .post("/results")
882+
// .set("Authorization", `Bearer ${uid}`)
883+
// //TODO add all properties
884+
// .send({ result: { acc: 25 } })
885+
// .expect(422);
886+
//THEN
887+
/*
890888
expect(body).toEqual({
891889
message: "Invalid request data schema",
892890
validationErrors: [
893891
],
894892
});
895893
*/
896-
});
894+
// });
897895
});
898896
});
899897

backend/__tests__/api/controllers/user.spec.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { generateCurrentTestActivity } from "../../../src/api/controllers/user";
55
import * as UserDal from "../../../src/dal/user";
66
import * as AuthUtils from "../../../src/utils/auth";
77
import * as BlocklistDal from "../../../src/dal/blocklist";
8-
import * as ApeKeys from "../../../src/dal/ape-keys";
98
import * as PresetDal from "../../../src/dal/preset";
109
import * as ConfigDal from "../../../src/dal/config";
1110
import * as ResultDal from "../../../src/dal/result";
@@ -586,11 +585,11 @@ describe("user controller test", () => {
586585
expect(testsByDays[371]).toEqual(2024094); //2024-01
587586
});
588587
});
589-
describe("delete user", () => {
588+
describe("delete user ", () => {
590589
const getUserMock = vi.spyOn(UserDal, "getPartialUser");
591590
const deleteUserMock = vi.spyOn(UserDal, "deleteUser");
592591
const firebaseDeleteUserMock = vi.spyOn(AuthUtils, "deleteUser");
593-
const deleteAllApeKeysMock = vi.spyOn(ApeKeys, "deleteAllApeKeys");
592+
const deleteAllApeKeysMock = vi.spyOn(ApeKeysDal, "deleteAllApeKeys");
594593
const deleteAllPresetsMock = vi.spyOn(PresetDal, "deleteAllPresets");
595594
const deleteConfigMock = vi.spyOn(ConfigDal, "deleteConfig");
596595
const deleteAllResultMock = vi.spyOn(ResultDal, "deleteAll");
@@ -894,13 +893,15 @@ describe("user controller test", () => {
894893
data: null,
895894
});
896895

897-
[
896+
for (const it of [
898897
resetUserMock,
899898
deleteAllApeKeysMock,
900899
deleteAllPresetsMock,
901900
deleteAllResultsMock,
902901
deleteConfigMock,
903-
].forEach((it) => expect(it).toHaveBeenCalledWith(uid));
902+
]) {
903+
expect(it).toHaveBeenCalledWith(uid);
904+
}
904905
expect(purgeUserFromDailyLeaderboardsMock).toHaveBeenCalledWith(
905906
uid,
906907
(await Configuration.getLiveConfiguration()).dailyLeaderboards
@@ -1178,19 +1179,18 @@ describe("user controller test", () => {
11781179
uid
11791180
);
11801181
});
1181-
it("should fail with unknown properties", async () => {
1182-
//WHEN
1183-
const { body } = await mockApp
1184-
.post("/users/optOutOfLeaderboards")
1185-
.set("Authorization", `Bearer ${uid}`)
1186-
.send({ extra: "value" });
1187-
//TODO.expect(422);
1188-
1189-
//THEN
1190-
/* TODO:
1182+
// it("should fail with unknown properties", async () => {
1183+
//WHEN
1184+
// const { body } = await mockApp
1185+
// .post("/users/optOutOfLeaderboards")
1186+
// .set("Authorization", `Bearer ${uid}`)
1187+
// .send({ extra: "value" });
1188+
//TODO.expect(422);
1189+
//THEN
1190+
/* TODO:
11911191
expect(body).toEqual({});
11921192
*/
1193-
});
1193+
// });
11941194
});
11951195
describe("update email", () => {
11961196
const authUpdateEmailMock = vi.spyOn(AuthUtils, "updateUserEmail");
@@ -2280,7 +2280,7 @@ describe("user controller test", () => {
22802280
updateLbMemoryMock.mockReset();
22812281
});
22822282

2283-
it("should update lb ", async () => {
2283+
it("should update lb", async () => {
22842284
//WHEN
22852285
const { body } = await mockApp
22862286
.patch("/users/leaderboardMemory")
@@ -2388,7 +2388,7 @@ describe("user controller test", () => {
23882388
addThemeMock.mockReset();
23892389
});
23902390

2391-
it("should add ", async () => {
2391+
it("should add", async () => {
23922392
//GIVEN
23932393
const addedTheme: UserDal.DBCustomTheme = {
23942394
_id: new ObjectId(),
@@ -3812,6 +3812,7 @@ async function enablePremiumFeatures(premium: boolean): Promise<void> {
38123812
);
38133813
}
38143814

3815+
// eslint-disable-next-line no-unused-vars
38153816
async function enableAdminFeatures(enabled: boolean): Promise<void> {
38163817
const mockConfig = _.merge(await configuration, {
38173818
admin: { endpointsEnabled: enabled },

backend/__tests__/dal/leaderboards.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe("LeaderboardsDal", () => {
9393
});
9494
it("should not include discord properties for users without discord connection", async () => {
9595
//GIVEN
96-
const rank1 = await createUser(lbBests(pb(90), pb(100, 90, 2)), {
96+
await createUser(lbBests(pb(90), pb(100, 90, 2)), {
9797
discordId: undefined,
9898
discordAvatar: undefined,
9999
});
@@ -138,10 +138,10 @@ describe("LeaderboardsDal", () => {
138138

139139
it("should update public speedHistogram for time english 15", async () => {
140140
//GIVEN
141-
const rank1 = await createUser(lbBests(pb(10), pb(60)));
142-
const rank2 = await createUser(lbBests(pb(24)));
143-
const rank3 = await createUser(lbBests(pb(28)));
144-
const rank4 = await createUser(lbBests(pb(31)));
141+
await createUser(lbBests(pb(10), pb(60)));
142+
await createUser(lbBests(pb(24)));
143+
await createUser(lbBests(pb(28)));
144+
await createUser(lbBests(pb(31)));
145145

146146
//WHEN
147147
await LeaderboardsDal.update("time", "15", "english");
@@ -153,10 +153,10 @@ describe("LeaderboardsDal", () => {
153153

154154
it("should update public speedHistogram for time english 60", async () => {
155155
//GIVEN
156-
const rank1 = await createUser(lbBests(pb(60), pb(20)));
157-
const rank2 = await createUser(lbBests(undefined, pb(21)));
158-
const rank3 = await createUser(lbBests(undefined, pb(110)));
159-
const rank4 = await createUser(lbBests(undefined, pb(115)));
156+
await createUser(lbBests(pb(60), pb(20)));
157+
await createUser(lbBests(undefined, pb(21)));
158+
await createUser(lbBests(undefined, pb(110)));
159+
await createUser(lbBests(undefined, pb(115)));
160160

161161
//WHEN
162162
await LeaderboardsDal.update("time", "60", "english");
@@ -253,7 +253,7 @@ describe("LeaderboardsDal", () => {
253253
it("should create leaderboard without premium if feature disabled", async () => {
254254
await enablePremiumFeatures(false);
255255
//GIVEN
256-
const lifetime = await createUser(lbBests(pb(3)), premium(-1));
256+
// const lifetime = await createUser(lbBests(pb(3)), premium(-1));
257257

258258
//WHEN
259259
await LeaderboardsDal.update("time", "15", "english");
@@ -358,12 +358,12 @@ function premium(expirationDeltaSeconds: number) {
358358
};
359359
}
360360

361-
interface ExpectedLbEntry {
361+
type ExpectedLbEntry = {
362362
rank: number;
363363
user: UserDal.DBUser;
364364
badgeId?: number;
365365
isPremium?: boolean;
366-
}
366+
};
367367

368368
async function enablePremiumFeatures(premium: boolean): Promise<void> {
369369
const mockConfig = _.merge(await configuration, {

backend/__tests__/middlewares/auth.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from "@monkeytype/contracts/schemas/api";
1616
import * as Prometheus from "../../src/utils/prometheus";
1717
import { TsRestRequestWithContext } from "../../src/api/types";
18-
import { error } from "console";
1918

2019
const mockDecodedToken: DecodedIdToken = {
2120
uid: "123456789",

backend/__tests__/setup-tests.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Collection, Db, MongoClient, WithId } from "mongodb";
22
import { afterAll, beforeAll, afterEach } from "vitest";
33
import * as MongoDbMock from "vitest-mongodb";
44
import { MongoDbMockConfig } from "./global-setup";
5-
import { enableRateLimitExpects } from "./__testData__/rate-limit";
65

76
process.env["MODE"] = "dev";
87
//process.env["MONGOMS_DISTRO"] = "ubuntu-22.04";
@@ -29,7 +28,9 @@ beforeAll(async () => {
2928
getDb: (): Db => db,
3029
collection: <T>(name: string): Collection<WithId<T>> =>
3130
db.collection<WithId<T>>(name),
32-
close: () => {},
31+
close: () => {
32+
//
33+
},
3334
}));
3435

3536
vi.mock("../src/utils/logger", () => ({

backend/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"license": "GPL-3.0",
55
"private": true,
66
"scripts": {
7-
"lint": "eslint \"./src/**/*.ts\"",
7+
"eslint": "eslint \"./src/**/*.ts\"",
8+
"oxlint": "oxlint .",
9+
"lint": "npm run oxlint && npm run eslint",
810
"build": "npm run gen-docs && tsc --build",
911
"watch": "tsc --build --watch",
1012
"clean": "tsc --build --clean",
@@ -63,6 +65,7 @@
6365
},
6466
"devDependencies": {
6567
"@monkeytype/eslint-config": "workspace:*",
68+
"@monkeytype/oxlint-config": "workspace:*",
6669
"@monkeytype/typescript-config": "workspace:*",
6770
"@redocly/cli": "1.28.5",
6871
"@types/bcrypt": "5.0.2",
@@ -89,6 +92,7 @@
8992
"eslint-watch": "8.0.0",
9093
"ioredis-mock": "7.4.0",
9194
"openapi3-ts": "2.0.2",
95+
"oxlint": "0.16.6",
9296
"readline-sync": "1.4.10",
9397
"supertest": "6.2.3",
9498
"tsx": "4.16.2",

backend/src/api/controllers/admin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ export async function handleReports(
7474
const reportsFromDb = await ReportDAL.getReports(reportIds);
7575
const reportById = new Map(reportsFromDb.map((it) => [it.id, it]));
7676

77-
const existingReportIds = reportsFromDb.map((report) => report.id);
77+
const existingReportIds = new Set(reportsFromDb.map((report) => report.id));
7878
const missingReportIds = reportIds.filter(
79-
(reportId) => !existingReportIds.includes(reportId)
79+
(reportId) => !existingReportIds.has(reportId)
8080
);
8181

8282
if (missingReportIds.length > 0) {

backend/src/api/controllers/leaderboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
GetLeaderboardQuery,
1414
GetLeaderboardRankQuery,
1515
GetLeaderboardRankResponse,
16-
GetLeaderboardResponse as GetLeaderboardResponse,
16+
GetLeaderboardResponse,
1717
GetWeeklyXpLeaderboardQuery,
1818
GetWeeklyXpLeaderboardRankQuery,
1919
GetWeeklyXpLeaderboardRankResponse,

0 commit comments

Comments
 (0)