chore: Improves linting rule to catch mishandled promises (#5506)

This commit is contained in:
Tom Moor
2023-07-01 13:25:51 -04:00
committed by GitHub
parent 7aec0e24ef
commit f843a20a54
13 changed files with 265 additions and 269 deletions

View File

@@ -5,6 +5,14 @@
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": true
}
]
},
"overrides": [
{
"files": ["scripts/*"],

View File

@@ -53,6 +53,7 @@ export class ViewsExtension implements Extension {
// Set up an interval to update the last viewed at timestamp continuously
// while the user is connected. This should only be done once per socket.
// eslint-disable-next-line @typescript-eslint/no-misused-promises
const interval = setInterval(updateView, 30 * Second);
this.intervalsBySocket.set(socketId, interval);

View File

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
/* eslint-disable import/order */
import env from "./env";
@@ -69,8 +70,8 @@ async function start(id: number, disconnect: () => void) {
const app = new Koa();
const server = stoppable(
useHTTPS
? https.createServer(ssl, app.callback())
: http.createServer(app.callback()),
? https.createServer(ssl, void app.callback())
: http.createServer(void app.callback()),
ShutdownHelper.connectionGraceTimeout
);
const router = new Router();
@@ -162,8 +163,8 @@ async function start(id: number, disconnect: () => void) {
ShutdownHelper.add("metrics", ShutdownOrder.last, () => Metrics.flush());
// Handle shutdown signals
process.once("SIGTERM", () => ShutdownHelper.execute());
process.once("SIGINT", () => ShutdownHelper.execute());
process.once("SIGTERM", () => void ShutdownHelper.execute());
process.once("SIGINT", () => void ShutdownHelper.execute());
}
void throng({

View File

@@ -1573,21 +1573,18 @@ describe("#documents.search", () => {
},
});
return new Promise((resolve) => {
// setTimeout is needed here because SearchQuery is saved asynchronously
// in order to not slow down the response time.
setTimeout(async () => {
const searchQuery = await SearchQuery.findAll({
where: {
query: "my term",
},
});
expect(searchQuery.length).toBe(1);
expect(searchQuery[0].results).toBe(0);
expect(searchQuery[0].source).toBe("app");
resolve(undefined);
}, 100);
// setTimeout is needed here because SearchQuery is saved asynchronously
// in order to not slow down the response time.
await new Promise((resolve) => setTimeout(resolve, 100));
const searchQuery = await SearchQuery.findAll({
where: {
query: "my term",
},
});
expect(searchQuery.length).toBe(1);
expect(searchQuery[0].results).toBe(0);
expect(searchQuery[0].source).toBe("app");
});
});

View File

@@ -12,8 +12,8 @@ export default function init() {
}
}
setInterval(() => run(TaskSchedule.Daily), Day);
setInterval(() => run(TaskSchedule.Hourly), Hour);
setInterval(() => void run(TaskSchedule.Daily), Day);
setInterval(() => void run(TaskSchedule.Hourly), Hour);
// Just give everything time to startup before running the first time. Not
// _technically_ required to function.

View File

@@ -86,7 +86,7 @@ export default function init(app: Koa = new Koa(), server?: Server) {
// Monitor server connections
if (server) {
setInterval(async () => {
setInterval(() => {
server.getConnections((err, count) => {
if (err) {
return;

View File

@@ -53,6 +53,7 @@ export function createQueue(
});
if (env.ENVIRONMENT !== "test") {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setInterval(async () => {
Metrics.gauge(`${prefix}.count`, await queue.count());
Metrics.gauge(`${prefix}.delayed_count`, await queue.getDelayedCount());