diff --git a/.eslintrc.json b/.eslintrc.json index 234af75290..5c0d6b1b67 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -142,8 +142,6 @@ // TODO: Re-enable gradually "@typescript-eslint/no-confusing-void-expression": "off", "@typescript-eslint/no-throw-literal": "off", - "@typescript-eslint/no-dynamic-delete": "off", - "@typescript-eslint/no-base-to-string": "off", "@typescript-eslint/no-unnecessary-condition": "off" } } diff --git a/src/github/installation.test.ts b/src/github/installation.test.ts index e6b619ac87..c5210c84ad 100644 --- a/src/github/installation.test.ts +++ b/src/github/installation.test.ts @@ -73,7 +73,7 @@ describe("InstallationWebhookHandler", () => { it("should not set security permissions accepted field if the payload doesn't contain secret_scanning_alerts permission", async () => { const webhookContext = getWebhookContext({ cloud: true }); - delete webhookContext.payload.installation.permissions["secret_scanning_alerts"]; + delete webhookContext.payload.installation.permissions.secret_scanning_alerts; await installationWebhookHandler(webhookContext, jiraClient, util, GITHUB_INSTALLATION_ID); const subscription = await Subscription.findOneForGitHubInstallationId(GITHUB_INSTALLATION_ID, undefined); expect(subscription?.isSecurityPermissionsAccepted).toBeFalsy(); @@ -82,7 +82,7 @@ describe("InstallationWebhookHandler", () => { it("should not set security permissions accepted field if the payload doesn't contain security_events permission", async () => { const webhookContext = getWebhookContext({ cloud: true }); - delete webhookContext.payload.installation.permissions["security_events"]; + delete webhookContext.payload.installation.permissions.security_events; await installationWebhookHandler(webhookContext, jiraClient, util, GITHUB_INSTALLATION_ID); const subscription = await Subscription.findOneForGitHubInstallationId(GITHUB_INSTALLATION_ID, undefined); expect(subscription?.isSecurityPermissionsAccepted).toBeFalsy(); @@ -91,7 +91,7 @@ describe("InstallationWebhookHandler", () => { it("should not set security permissions accepted field if the payload doesn't contain vulnerability_alerts permission", async () => { const webhookContext = getWebhookContext({ cloud: true }); - delete webhookContext.payload.installation.permissions["vulnerability_alerts"]; + delete webhookContext.payload.installation.permissions.vulnerability_alerts; await installationWebhookHandler(webhookContext, jiraClient, util, GITHUB_INSTALLATION_ID); const subscription = await Subscription.findOneForGitHubInstallationId(GITHUB_INSTALLATION_ID, undefined); expect(subscription?.isSecurityPermissionsAccepted).toBeFalsy(); diff --git a/src/rest/routes/deferred/deferred-installation-url.ts b/src/rest/routes/deferred/deferred-installation-url.ts index 5905b2e134..a3ddf99d72 100644 --- a/src/rest/routes/deferred/deferred-installation-url.ts +++ b/src/rest/routes/deferred/deferred-installation-url.ts @@ -9,7 +9,7 @@ import { import { envVars } from "config/env"; import { InvalidArgumentError } from "config/errors"; -export const DeferredInstallationUrlRoute = errorWrapper("GetDeferredInstallationUrl", async function DeferredInstallationUrlRoute(req: Request, res: Response) { +export const DeferredInstallationUrlRoute = errorWrapper("GetDeferredInstallationUrl", async function DeferredInstallationUrlRoute(req: Request, res: Response) { const { gitHubInstallationId, gitHubOrgName } = req.query; const { installation } = res.locals; diff --git a/src/routes/api/data-cleanup/cleanup-reposyncstates.ts b/src/routes/api/data-cleanup/cleanup-reposyncstates.ts index 42960e8657..28c242d08d 100644 --- a/src/routes/api/data-cleanup/cleanup-reposyncstates.ts +++ b/src/routes/api/data-cleanup/cleanup-reposyncstates.ts @@ -105,6 +105,6 @@ const safeParseResult = (result: object, commitToDB: boolean) => { return result[0].map((r: object) => safeJsonStringify(r)).join("\n") as string; } } catch (_) { - return result; + return "ERROR Failed to parse result"; } }; diff --git a/src/routes/github/create-branch/github-branches-get.test.ts b/src/routes/github/create-branch/github-branches-get.test.ts index 9f1f9977f4..3f19c18e60 100644 --- a/src/routes/github/create-branch/github-branches-get.test.ts +++ b/src/routes/github/create-branch/github-branches-get.test.ts @@ -56,6 +56,7 @@ describe("GitHub Branches Get", () => { it.each(["owner", "repo"])("Should 400 when missing required fields", async (attribute) => { res.status.mockReturnValue(res); + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete req.params[attribute]; await GithubBranchesGet(req, res); expect(res.status).toHaveBeenCalledWith(400); diff --git a/src/routes/github/create-branch/github-create-branch-post.test.ts b/src/routes/github/create-branch/github-create-branch-post.test.ts index bc3bb60e87..b21f2ec1ca 100644 --- a/src/routes/github/create-branch/github-create-branch-post.test.ts +++ b/src/routes/github/create-branch/github-create-branch-post.test.ts @@ -79,6 +79,7 @@ describe("github-create-branch", () => { it.each(["owner", "repo", "sourceBranchName", "newBranchName"])("Should 400 when missing required fields", async (attribute) => { res.status.mockReturnValue(res); + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete req.body[attribute]; await GithubCreateBranchPost(req , res); expect(res.status).toHaveBeenCalledWith(400); diff --git a/src/routes/github/create-branch/github-remove-session.test.ts b/src/routes/github/create-branch/github-remove-session.test.ts index 51e6c31fd7..0060b2a923 100644 --- a/src/routes/github/create-branch/github-remove-session.test.ts +++ b/src/routes/github/create-branch/github-remove-session.test.ts @@ -21,6 +21,7 @@ describe("GitHub Remove Session", () => { }); it.each(["gitHubAppConfig"])("Should 401 when missing required fields", (attribute) => { + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete res.locals[attribute]; GithubRemoveSession(req, res); expect(res.sendStatus).toHaveBeenCalledWith(401); diff --git a/src/routes/github/github-oauth.ts b/src/routes/github/github-oauth.ts index 64809709ca..9dcef65fea 100644 --- a/src/routes/github/github-oauth.ts +++ b/src/routes/github/github-oauth.ts @@ -160,6 +160,7 @@ export const GithubOAuthCallbackGet = async (req: Request, res: Response, next: next(new UIDisplayableError(400, "No state was found")); return; } + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete req.session[stateKey]; req.log.info({ query: req.query }, `Received request to ${req.url}`); @@ -202,7 +203,7 @@ export const GithubAuthMiddleware = async (req: Request, res: Response, next: Ne req.session.githubToken = undefined; req.session.githubRefreshToken = undefined; - delete query["resetGithubToken"]; + delete query.resetGithubToken; const newUrl = originalUrl.split("?")[0] + "?" + queryToQueryString(query); req.log.info("Github Token reset for URL: ", newUrl); diff --git a/src/routes/github/manifest/github-manifest-complete-get.ts b/src/routes/github/manifest/github-manifest-complete-get.ts index 5e85b733a5..6dc40d51fc 100644 --- a/src/routes/github/manifest/github-manifest-complete-get.ts +++ b/src/routes/github/manifest/github-manifest-complete-get.ts @@ -1,4 +1,5 @@ import { Request, Response } from "express"; +import { ParamsDictionary } from "express-serve-static-core"; import { GitHubServerApp } from "~/src/models/github-server-app"; import { Errors } from "config/errors"; import { createAnonymousClient } from "utils/get-github-client-config"; @@ -6,7 +7,7 @@ import { sendAnalytics } from "utils/analytics-client"; import { AnalyticsEventTypes, AnalyticsTrackEventsEnum, AnalyticsTrackSource } from "interfaces/common"; import { GheConnectConfigTempStorage } from "utils/ghe-connect-config-temp-storage"; -export const GithubManifestCompleteGet = async (req: Request, res: Response) => { +export const GithubManifestCompleteGet = async (req: Request, res: Response) => { const uuid = req.params.uuid; const tempStorage = new GheConnectConfigTempStorage(); diff --git a/src/routes/github/subscription/github-subscription-delete.test.ts b/src/routes/github/subscription/github-subscription-delete.test.ts index 610311b89f..41dbebf9cd 100644 --- a/src/routes/github/subscription/github-subscription-delete.test.ts +++ b/src/routes/github/subscription/github-subscription-delete.test.ts @@ -208,7 +208,9 @@ describe("delete-github-subscription", () => { }); it.each([["installationId"], ["jiraHost"]])("Should 400 when missing body.%s", async (property) => { + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete req.body[property]; + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete res.locals[property]; res.status.mockReturnValue(res); diff --git a/src/routes/jira/jira-connected-repos-get.test.ts b/src/routes/jira/jira-connected-repos-get.test.ts index 748dea46e4..bde9b502b4 100644 --- a/src/routes/jira/jira-connected-repos-get.test.ts +++ b/src/routes/jira/jira-connected-repos-get.test.ts @@ -99,9 +99,9 @@ describe("jira-connected-repos-get", () => { const newRepoSyncStatesData: any[] = []; for (let newRepoStateNo = 1; newRepoStateNo < 50; newRepoStateNo++) { const newRepoSyncState = { ...repoSyncState.dataValues }; - delete newRepoSyncState["id"]; - delete newRepoSyncState["commitStatus"]; - delete newRepoSyncState["branchStatus"]; + delete newRepoSyncState.id; + delete newRepoSyncState.commitStatus; + delete newRepoSyncState.branchStatus; newRepoSyncState["repoId"] = repoSyncState.repoId + newRepoStateNo; newRepoSyncState["repoName"] = repoSyncState.repoName + newRepoStateNo.toString(); newRepoSyncState["repoFullName"] = repoSyncState.repoFullName + String(newRepoStateNo).padStart(3, "0"); diff --git a/src/sync/installation.test.ts b/src/sync/installation.test.ts index dcbc7241f6..14f2dee59c 100644 --- a/src/sync/installation.test.ts +++ b/src/sync/installation.test.ts @@ -386,8 +386,8 @@ describe("sync/installation", () => { const newRepoSyncStatesData: any[] = []; for (let newRepoStateNo = 1; newRepoStateNo < 50; newRepoStateNo++) { const newRepoSyncState = { ...repoSyncState.get() }; - delete newRepoSyncState["id"]; - delete newRepoSyncState["branchStatus"]; + delete newRepoSyncState.id; + delete newRepoSyncState.branchStatus; newRepoSyncState["repoId"] = repoSyncState.repoId + newRepoStateNo; if (newRepoStateNo < 49) { // the last one should be main diff --git a/src/sync/scheduler.test.ts b/src/sync/scheduler.test.ts index 85d13b3781..a1104099aa 100644 --- a/src/sync/scheduler.test.ts +++ b/src/sync/scheduler.test.ts @@ -18,9 +18,9 @@ describe("scheduler", () => { const newRepoSyncStatesData: any[] = []; for (let newRepoStateNo = 1; newRepoStateNo < 500; newRepoStateNo++) { const newRepoSyncState = { ...repoSyncState.get() }; - delete newRepoSyncState["id"]; - delete newRepoSyncState["commitStatus"]; - delete newRepoSyncState["branchStatus"]; + delete newRepoSyncState.id; + delete newRepoSyncState.commitStatus; + delete newRepoSyncState.branchStatus; newRepoSyncState["repoId"] = repoSyncState.repoId + newRepoStateNo; newRepoSyncState["repoName"] = repoSyncState.repoName + newRepoStateNo.toString(); newRepoSyncState["repoFullName"] = repoSyncState.repoFullName + newRepoStateNo.toString(); diff --git a/src/util/workers-health-monitor.ts b/src/util/workers-health-monitor.ts index 886d94b4e6..a92ea3253c 100644 --- a/src/util/workers-health-monitor.ts +++ b/src/util/workers-health-monitor.ts @@ -96,7 +96,7 @@ export const startMonitorOnWorker = (parentLogger: Logger, workerConfig: { const logRunningProcesses = (logger: Logger) => { exec("ps aux", (err, stdout) => { if (err) { - logger.error({ err }, `exec error: ${err.toString()}`); + logger.error({ err }, `exec error: ${err.message}`); return; } @@ -117,7 +117,7 @@ export const startMonitorOnMaster = (parentLogger: Logger, config: { logger.info(config, "master config"); const registeredWorkers: Record = { }; // pid => true - const liveWorkers: Record = { }; // pid => timestamp + const liveWorkers: Map = new Map(); // pid => timestamp const registerNewWorkers = () => { logInfoSampled(logger, "monRegWorkers", `registering workers`, 100); @@ -130,7 +130,7 @@ export const startMonitorOnMaster = (parentLogger: Logger, config: { registeredWorkers[workerPid] = true; worker.on("message", () => { logInfoSampled(logger, "workerIsAlive:" + workerPid.toString(), `received message from worker ${workerPid}, marking as live`, 100); - liveWorkers[workerPid] = Date.now(); + liveWorkers.set(String(workerPid), Date.now()); }); worker.on("exit", (code, signal) => { G("/tmp/*", (err: Error | null, tmpFiles: string[]) => { @@ -210,14 +210,14 @@ export const startMonitorOnMaster = (parentLogger: Logger, config: { logInfoSampled(logger, `removing dead workers`, `removing dead workers`, 100); const keysToKill: Array = []; const now = Date.now(); - Object.keys(liveWorkers).forEach((key) => { - if (now - liveWorkers[key] > config.workerUnresponsiveThresholdMsecs) { + liveWorkers.forEach((value, key) => { + if (now - value > config.workerUnresponsiveThresholdMsecs) { keysToKill.push(key); } }); keysToKill.forEach((key) => { logger.info(`remove worker with pid=${key} from live workers`); - delete liveWorkers[key]; + liveWorkers.delete(key); logRunningProcesses(logger); }); } else { @@ -226,7 +226,7 @@ export const startMonitorOnMaster = (parentLogger: Logger, config: { }; const maybeSendShutdownToAllWorkers = () => { - const nLiveWorkers = Object.keys(liveWorkers).length; + const nLiveWorkers = liveWorkers.size; if (areWorkersReady() && (nLiveWorkers < config.numberOfWorkersThreshold)) { logger.info({ nLiveWorkers diff --git a/test/e2e/utils/jira.ts b/test/e2e/utils/jira.ts index 14d7d2965f..4397790612 100644 --- a/test/e2e/utils/jira.ts +++ b/test/e2e/utils/jira.ts @@ -7,7 +7,7 @@ const data = testData.jira; export const jiraLogin = async (page: Page, roleName: keyof JiraTestDataRoles, saveState = false): Promise => { const role = data.roles[roleName]; if (!role.username || !role.password) { - throw "Jira username or password missing"; + throw new Error("Jira username or password missing"); } await page.goto(data.urls.login); await page.waitForLoadState(); diff --git a/test/setup/env-test.ts b/test/setup/env-test.ts index 105d9726ed..e4b224661e 100644 --- a/test/setup/env-test.ts +++ b/test/setup/env-test.ts @@ -24,5 +24,6 @@ export const resetEnvVars = () => { // Reset original keys back to process.env originalKeys.forEach(key => process.env[key] = originalEnvVars[key]); // Removing keys that's been added during the test + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete difference(newKeys, originalKeys).forEach(key => delete process.env[key]); };