fix: pass linting

This commit is contained in:
zkldi
2023-01-19 16:39:59 +00:00
parent 7a826b27f5
commit 4475caaf8b
17 changed files with 30 additions and 29 deletions
+4
View File
@@ -16,6 +16,8 @@ const formatExcessProperties = (meta: Record<string, unknown>, limit = false) =>
let i = 0;
for (const [key, val] of Object.entries(meta)) {
// this is probably fine
// eslint-disable-next-line cadence/no-instanceof
if (val instanceof Error) {
meta[key] = { message: val.message, stack: val.stack };
}
@@ -52,6 +54,8 @@ const formatExcessPropertiesNoStack = (
continue;
}
// this is probably fine
// eslint-disable-next-line cadence/no-instanceof
if (val instanceof Error) {
realMeta[key] = { message: val.message };
} else if (!key.startsWith("__") && !key.startsWith("!")) {
@@ -51,6 +51,8 @@ export async function ExpressWrappedScoreImportMain<I extends ImportTypes>(
},
};
} catch (err) {
// this is definitely fine, as the errors are emitted from the same place.
// eslint-disable-next-line cadence/no-instanceof
if (err instanceof ScoreImportFatalError) {
logger.info(err.message);
return {
@@ -103,6 +103,8 @@ export function IIDXCSVParse(csvBuffer: Buffer, playtype: Playtypes["iidx"], log
try {
({ rawHeaders, rawRows } = NaiveCSVParse(csvBuffer, logger));
} catch (e) {
// this is probably fine
// eslint-disable-next-line cadence/no-instanceof
if (e instanceof CSVParseError) {
throw new ScoreImportFatalError(400, e.message);
}
@@ -33,6 +33,8 @@ export default function ParseEamusementSDVXCSV(
try {
({ rawHeaders, rawRows } = NaiveCSVParse(fileData.buffer, logger));
} catch (e) {
// This is probably fine.
// eslint-disable-next-line cadence/no-instanceof
if (e instanceof CSVParseError) {
throw new ScoreImportFatalError(400, e.message);
}
@@ -199,8 +199,8 @@ export const ConverterIRBeatoraja: ConverterFunction<BeatorajaScore, BeatorajaCo
optional[k] = data[k];
}
optional.epr = (optional.epr ?? 0) + (data.ems ?? 0);
optional.lpr = (optional.lpr ?? 0) + (data.lms ?? 0);
optional.epr = (optional.epr ?? 0) + data.ems;
optional.lpr = (optional.lpr ?? 0) + data.lms;
const judgements = {
[game === "pms" ? "cool" : "pgreat"]: data.epg + data.lpg,
@@ -26,10 +26,13 @@ t.test("#ParseIRUSC", (t) => {
});
t.test("Should reject empty bodies", (t) => {
t.throws(() => ParseIRUSC({}, TestingUSCChart.data.hashSHA1 as string, "Controller", logger), {
statusCode: 400,
message: /invalid usc score/iu,
});
t.throws(
() => ParseIRUSC({}, TestingUSCChart.data.hashSHA1 as string, "Controller", logger),
{
statusCode: 400,
message: /invalid usc score/iu,
}
);
t.end();
});
@@ -19,6 +19,8 @@ export const CreateMulterSingleUploadMiddleware = (
return (req, res, next) => {
UploadMW(req, res, (err: unknown) => {
// this use is fine... ish.. probably.
// eslint-disable-next-line cadence/no-instanceof
if (err instanceof MulterError) {
logger.info(`Multer Error.`, { err });
@@ -7,11 +7,10 @@ import {
SearchUsersRegExp,
} from "lib/search/search";
import { TachiConfig } from "lib/setup/config";
import { RequireBokutachi } from "server/middleware/type-require";
import { IsString } from "utils/misc";
import { GetAllUserRivals, GetUserPlayedGPTs } from "utils/user";
import type { FilterQuery } from "mongodb";
import type { FolderDocument, Game, integer, UserDocument, SongDocument } from "tachi-common";
import type { FolderDocument, Game, SongDocument, UserDocument, integer } from "tachi-common";
const router: Router = Router({ mergeParams: true });
@@ -156,20 +156,6 @@ router.get(
chartID: { $in: charts.map((e) => e.chartID) },
};
if (!conf) {
// not possible?
return res.status(500).json({
success: false,
description: `Invalid criteria ${req.query.criteriaType}.`,
});
}
if (conf.type === "ENUM") {
matchCriteria[`scoreData.enumIndexes.${metric}`] = { $gte: criteriaValue };
} else {
matchCriteria[`scoreData.${metric}`] = { $gte: criteriaValue };
}
// Returns a unique score per-chart that was the first score to achieve
// this criteria on that chart.
const scoresAgg: Array<{ doc: ScoreDocument }> = await db.scores.aggregate([
@@ -112,7 +112,7 @@ router.get("/best", prValidate({ alg: "*string" }), async (req, res) => {
});
}
const alg = req.query.alg ?? gptConfig.defaultScoreRatingAlg;
const alg = (req.query.alg as string | undefined) ?? gptConfig.defaultScoreRatingAlg;
const pbs = await db["personal-bests"].find(
{
@@ -266,7 +266,7 @@ router.get("/leaderboard-adjacent", async (req, res) => {
const gptConfig = GetGamePTConfig(game, playtype);
let alg = gptConfig.defaultProfileRatingAlg as ProfileRatingAlgorithms[GPTString];
let alg = gptConfig.defaultProfileRatingAlg;
if (IsString(req.query.alg)) {
const temp = CheckStrProfileAlg(game, playtype, req.query.alg);
@@ -3,8 +3,6 @@ import { Router } from "express";
import db from "external/mongo/db";
import prValidate from "server/middleware/prudence-validate";
import { RequireKamaitachi } from "server/middleware/type-require";
import { DeleteUndefinedProps } from "utils/misc";
import { optNull } from "utils/prudence";
import { GetTachiData } from "utils/req-tachi-data";
const router: Router = Router({ mergeParams: true });
@@ -3,7 +3,7 @@ import type { RequestHandler } from "express";
export const ValidateIRClientVersion: RequestHandler = (req, res, next) => {
const header = req.header("X-TachiIR-Version");
if (!header || !header.startsWith("v2")) {
if (!header?.startsWith("v2")) {
return res.status(400).json({
success: false,
description: `Invalid X-TachiIR-Version.`,
@@ -126,7 +126,7 @@ const ValidateCards: RequestHandler = async (req, res, next) => {
const cardFilters = await db["fer-settings"].findOne({ userID });
if (!cardFilters || !cardFilters.cards) {
if (!cardFilters?.cards) {
next();
return;
}
@@ -110,7 +110,7 @@ router.post("/score/export", async (req, res) => {
const settings = await db["kshook-sv6c-settings"].findOne({ userID });
if (!settings || !settings.forceStaticImport) {
if (!settings?.forceStaticImport) {
return res.status(200).json({
success: true,
description: "Static importing is disabled. Ignoring static import request.",
+2
View File
@@ -178,6 +178,8 @@ interface ExpressJSONErr extends SyntaxError {
const MAIN_ERR_HANDLER: express.ErrorRequestHandler = (err, req, res, _next) => {
logger.info(`MAIN_ERR_HANDLER hit by request.`, { url: req.originalUrl });
// this use of instanceof is fine.
// eslint-disable-next-line cadence/no-instanceof
if (err instanceof SyntaxError) {
const expErr: ExpressJSONErr = err as ExpressJSONErr;
@@ -0,0 +1 @@
[]