ESLint: Fix more warnings and errors.

This commit is contained in:
baldo 2022-08-23 21:38:37 +02:00
parent 66fb4e5004
commit bfd6ca1d26
9 changed files with 84 additions and 56 deletions

View file

@ -196,21 +196,23 @@ export async function sendPendingMails(): Promise<void> {
const startTime = moment();
while (true) {
let pendingMails = await findPendingMailsBefore(
startTime,
MAIL_QUEUE_DB_BATCH_SIZE
);
while (!_.isEmpty(pendingMails)) {
Logger.tag("mail", "queue").debug("Sending next batch...");
const pendingMails = await findPendingMailsBefore(
startTime,
MAIL_QUEUE_DB_BATCH_SIZE
);
if (_.isEmpty(pendingMails)) {
Logger.tag("mail", "queue").debug("Done sending pending mails.");
return;
}
for (const pendingMail of pendingMails) {
await sendPendingMail(pendingMail);
}
pendingMails = await findPendingMailsBefore(
startTime,
MAIL_QUEUE_DB_BATCH_SIZE
);
}
Logger.tag("mail", "queue").debug("Done sending pending mails.");
}

View file

@ -21,6 +21,7 @@ const templateFunctions: {
| ((unix: number) => string);
} = {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function renderSnippet(this: any, name: string, data: MailData): string {
const snippetFile = snippetsBasePath + "/" + name + ".html";
@ -34,7 +35,9 @@ function renderSnippet(this: any, name: string, data: MailData): string {
);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function snippet(name: string): (this: any, data: MailData) => string {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return function (this: any, data: MailData): string {
return renderSnippet.bind(this)(name, data);
};

View file

@ -25,15 +25,6 @@ beforeEach(() => {
mockedLogger.reset();
});
test("parseNode() should fail parsing node for undefined node data", () => {
// given
const importTimestamp = now();
const nodeData = undefined;
// then
expect(() => parseNode(importTimestamp, nodeData)).toThrowError();
});
test("parseNode() should fail parsing node for empty node data", () => {
// given
const importTimestamp = now();

View file

@ -24,9 +24,11 @@ import {
isDomain,
isMonitoringSortField,
isOnlineState,
isPlainObject,
isSite,
isString,
isUndefined,
JSONValue,
MAC,
MailType,
MonitoringSortField,
@ -35,6 +37,7 @@ import {
NodeId,
NodeStateData,
OnlineState,
parseJSON,
RunResult,
Site,
StoredNode,
@ -206,13 +209,13 @@ const isValidMac = forConstraint(CONSTRAINTS.node.mac, false);
export function parseNode(
importTimestamp: UnixTimestampSeconds,
nodeData: any
nodeData: JSONValue
): ParsedNode {
if (!_.isPlainObject(nodeData)) {
if (!isPlainObject(nodeData)) {
throw new Error("Unexpected node type: " + typeof nodeData);
}
if (!_.isPlainObject(nodeData.nodeinfo)) {
if (!isPlainObject(nodeData.nodeinfo)) {
throw new Error(
"Unexpected nodeinfo type: " + typeof nodeData.nodeinfo
);
@ -225,7 +228,7 @@ export function parseNode(
);
}
if (!_.isPlainObject(nodeData.nodeinfo.network)) {
if (!isPlainObject(nodeData.nodeinfo.network)) {
throw new Error(
"Node " +
nodeId +
@ -239,9 +242,9 @@ export function parseNode(
"Node " + nodeId + ": Invalid MAC: " + nodeData.nodeinfo.network.mac
);
}
const mac = normalizeMac(nodeData.nodeinfo.network.mac) as MAC;
const mac = normalizeMac(nodeData.nodeinfo.network.mac as MAC);
if (!_.isPlainObject(nodeData.flags)) {
if (!isPlainObject(nodeData.flags)) {
throw new Error(
"Node " +
nodeId +
@ -271,7 +274,7 @@ export function parseNode(
let site: Site | undefined;
if (
_.isPlainObject(nodeData.nodeinfo.system) &&
isPlainObject(nodeData.nodeinfo.system) &&
isSite(nodeData.nodeinfo.system.site_code)
) {
site = nodeData.nodeinfo.system.site_code;
@ -279,7 +282,7 @@ export function parseNode(
let domain: Domain | undefined;
if (
_.isPlainObject(nodeData.nodeinfo.system) &&
isPlainObject(nodeData.nodeinfo.system) &&
isDomain(nodeData.nodeinfo.system.domain_code)
) {
domain = nodeData.nodeinfo.system.domain_code;
@ -300,9 +303,9 @@ export function parseNodesJson(body: string): NodesParsingResult {
"Parsing nodes.json..."
);
const json = JSON.parse(body);
const json = parseJSON(body);
if (!_.isPlainObject(json)) {
if (!isPlainObject(json)) {
throw new Error(
`Expecting a JSON object as the nodes.json root, but got: ${typeof json}`
);

View file

@ -405,7 +405,7 @@ function setNodeValue(
case LINE_PREFIX.TOKEN:
node.token = value as Token;
break;
case LINE_PREFIX.MONITORING:
case LINE_PREFIX.MONITORING: {
const active = value === "aktiv";
const pending = value === "pending";
node.monitoringState = active
@ -414,6 +414,7 @@ function setNodeValue(
? MonitoringState.PENDING
: MonitoringState.DISABLED;
break;
}
case LINE_PREFIX.MONITORING_TOKEN:
nodeSecrets.monitoringToken = value as MonitoringToken;
break;