build: migrate eslint to v10 flat config and upgrade typescript
Replace .eslintrc.json with eslint.config.js using the new flat config format required by ESLint 10. Swap @typescript-eslint/eslint-plugin and @typescript-eslint/parser for the unified typescript-eslint package. Upgrade TypeScript to 5.9 and @types/node to 25. Apply automatic code fixes: remove unused catch bindings and preserve error cause in auth header parsing.
This commit is contained in:
1 parent
4a191afdec
commit
75908e624f
27 files changed
+1146
-1595
No files matched your search
@@ -103,7 +103,7 @@ export async function connectionRequest(
|
||||
let remoteAddress;
|
||||
try {
|
||||
remoteAddress = new URL(connectionRequestUrl).hostname;
|
||||
} catch (err) {
|
||||
} catch {
|
||||
return "Invalid connection request URL";
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ export async function connectionRequest(
|
||||
() => true,
|
||||
() => false,
|
||||
);
|
||||
} catch (err) {
|
||||
} catch {
|
||||
// Ignore invalid address
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ function parseHeaderFeilds(str: string): Record<string, string> {
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch (error) {
|
||||
throw new Error("Unable to parse auth header");
|
||||
throw new Error("Unable to parse auth header", { cause: error });
|
||||
}
|
||||
}
|
||||
res[name.trim()] = value;
|
||||
|
||||
@@ -157,7 +157,7 @@ export async function httpConnectionRequest(
|
||||
authHeader = auth.parseWwwAuthenticateHeader(
|
||||
res.headers["www-authenticate"],
|
||||
);
|
||||
} catch (err) {
|
||||
} catch {
|
||||
return "Connection request error: Error parsing www-authenticate header";
|
||||
}
|
||||
[username, password, authExp] = await extractAuth(authExp, false);
|
||||
|
||||
+4
-4
@@ -89,7 +89,7 @@ async function authenticate(
|
||||
authentication = auth.parseAuthorizationHeader(
|
||||
sessionContext.httpRequest.headers["authorization"],
|
||||
);
|
||||
} catch (err) {
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1274,7 +1274,7 @@ async function clientError(
|
||||
body: string,
|
||||
msg: string,
|
||||
): Promise<void> {
|
||||
let debugEnabled = false;
|
||||
let debugEnabled: boolean;
|
||||
let deviceId: string = null;
|
||||
|
||||
if (sessionContext) {
|
||||
@@ -1312,7 +1312,7 @@ async function clientError(
|
||||
function decodeString(buffer: Buffer, charset: string): string {
|
||||
try {
|
||||
return buffer.toString(charset as BufferEncoding);
|
||||
} catch (err) {
|
||||
} catch {
|
||||
if (encodingExists(charset)) return decode(buffer, charset);
|
||||
}
|
||||
return null;
|
||||
@@ -1383,7 +1383,7 @@ async function listenerAsync(
|
||||
// connection is closed before the stream is finished.
|
||||
// For Node 12.9+ we can just use stream.readableEnded
|
||||
if (!readableEnded) throw new Error("Connection closed");
|
||||
} catch (err) {
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ export async function fetchDevice(
|
||||
|
||||
try {
|
||||
res.push([Path.parse(path), t, attrs]);
|
||||
} catch (err) {
|
||||
} catch {
|
||||
// The path parser is now more strict so we might be in a situation where
|
||||
// the database contains invalid paths from before this change So here we
|
||||
// encode the invalid characters.
|
||||
|
||||
@@ -82,7 +82,7 @@ async function fetchPresets(): Promise<[string, Preset[]]> {
|
||||
try {
|
||||
schedule.duration = +parts.shift() * 1000;
|
||||
schedule.schedule = scheduling.parseCron(parts.join(" "));
|
||||
} catch (err) {
|
||||
} catch {
|
||||
logger.warn({
|
||||
message: "Invalid preset schedule",
|
||||
preset: preset["_id"],
|
||||
@@ -97,7 +97,7 @@ async function fetchPresets(): Promise<[string, Preset[]]> {
|
||||
if (preset["precondition"]) {
|
||||
try {
|
||||
precondition = parse(preset["precondition"]);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
precondition = convertOldPrecondition(
|
||||
JSON.parse(preset["precondition"]),
|
||||
);
|
||||
|
||||
+2
-2
@@ -20,12 +20,12 @@ const cidrs: [IPv4 | IPv6, number][] = [];
|
||||
for (const str of FORWARDED_HEADER.split(",").map((s) => s.trim())) {
|
||||
try {
|
||||
cidrs.push(parseCIDR(str));
|
||||
} catch (err) {
|
||||
} catch {
|
||||
// Not a valid CIDR format, try parsing as IP
|
||||
try {
|
||||
const ip = parse(str);
|
||||
cidrs.push([ip, ip.toByteArray().length * 8]);
|
||||
} catch (err) {
|
||||
} catch {
|
||||
// Not a valid IP either, ignore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ function matchEtag(etag: string, header: string): boolean {
|
||||
if (t.startsWith("W/")) t = t.substring(2);
|
||||
try {
|
||||
t = JSON.parse(t);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
if (t === "*") return true;
|
||||
|
||||
+1
-1
@@ -501,7 +501,7 @@ async function handler(
|
||||
};
|
||||
try {
|
||||
await filesBucket.delete(filename as unknown as ObjectId);
|
||||
} catch (err) {
|
||||
} catch {
|
||||
// Ignore error if file doesn't exist
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ export function start(
|
||||
res.writeHead(500, { Connection: "close" });
|
||||
res.end(`${err.name}: ${err.message}`);
|
||||
}
|
||||
} catch (err) {
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
throw err;
|
||||
|
||||
+3
-3
@@ -119,7 +119,7 @@ function parameterInfoList(xml: Element): [Path, boolean, boolean][] {
|
||||
if (param && !param.endsWith("."))
|
||||
return [Path.parse(param), false, parsed];
|
||||
else return [Path.parse(param.slice(0, -1)), true, parsed];
|
||||
} catch (err) {
|
||||
} catch {
|
||||
warnings.push({
|
||||
message: "Missing or invalid XML node",
|
||||
element: "Name",
|
||||
@@ -201,7 +201,7 @@ function parameterValueList(
|
||||
}
|
||||
try {
|
||||
return [Path.parse(param), parsed, valueType];
|
||||
} catch (err) {
|
||||
} catch {
|
||||
warnings.push({
|
||||
message: "Missing or invalid XML node",
|
||||
element: "Name",
|
||||
@@ -250,7 +250,7 @@ function parameterAttributeList(xml: Element): [Path, number, string[]][] {
|
||||
|
||||
try {
|
||||
return [Path.parse(param), notification, accessList];
|
||||
} catch (err) {
|
||||
} catch {
|
||||
warnings.push({
|
||||
message: "Missing or invalid XML node",
|
||||
element: "Name",
|
||||
|
||||
+1
-1
@@ -519,7 +519,7 @@ router.put("/files/:id", async (ctx) => {
|
||||
|
||||
try {
|
||||
await db.deleteFile(id);
|
||||
} catch (err) {
|
||||
} catch {
|
||||
// File doesn't exist, ignore
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -260,7 +260,7 @@ function flattenPreset(
|
||||
try {
|
||||
// Try parse to check expression validity
|
||||
parse(p.precondition as string);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
p.precondition = convertOldPrecondition(
|
||||
JSON.parse(p.precondition as string),
|
||||
);
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ export function parseXmlDeclaration(buffer: Buffer): Attribute[] {
|
||||
str = str.slice(0, str.indexOf("?>"));
|
||||
try {
|
||||
return parseAttrs(str.slice(5));
|
||||
} catch (err) {
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user