Skip to content

Commit 177a524

Browse files
NONE eslint config util directories (#2470)
* NONE eslint config util directories * Add middleware directory
1 parent 51930b3 commit 177a524

25 files changed

+205
-103
lines changed

Diff for: .eslintrc.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,11 @@
120120
},
121121
{
122122
"files": [
123-
"src/*.ts",
124-
"src/config/**",
125123
"src/github/**",
126124
"src/jira/**",
127-
"src/middleware/**",
128125
"src/models/**",
129126
"src/sync/**",
130-
"src/transforms/**",
131-
"src/util/**"
127+
"src/transforms/**"
132128
],
133129
"rules": {
134130
// To be removed later

Diff for: db/config.json

+40-19
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,63 @@
11
{
2-
"development": {
3-
"dialect": "postgres",
4-
"use_env_variable": "DATABASE_URL",
2+
"development": {
3+
"dialect": "postgres",
4+
"use_env_variable": "DATABASE_URL",
5+
"disable_sql_logging": false,
6+
"ssl": false,
7+
"dialectOptions": {
8+
"ssl": false
9+
},
510
"pool": {
611
"acquire": 60000,
712
"max": 15,
813
"min": 0,
914
"idle": 10000
1015
}
11-
},
12-
"test": {
13-
"dialect": "postgres",
14-
"use_env_variable": "DATABASE_URL"
15-
},
16+
},
17+
"test": {
18+
"dialect": "postgres",
19+
"use_env_variable": "DATABASE_URL",
20+
"disable_sql_logging": false,
21+
"ssl": false,
22+
"dialectOptions": {
23+
"ssl": false
24+
},
25+
"pool": {
26+
"acquire": 60000,
27+
"max": 15,
28+
"min": 0,
29+
"idle": 10000
30+
}
31+
},
1632
"e2e": {
1733
"dialect": "postgres",
1834
"use_env_variable": "DATABASE_URL",
35+
"disable_sql_logging": false,
36+
"ssl": false,
37+
"dialectOptions": {
38+
"ssl": false
39+
},
1940
"pool": {
2041
"acquire": 60000,
2142
"max": 15,
2243
"min": 0,
2344
"idle": 10000
2445
}
2546
},
26-
"production": {
27-
"dialect": "postgres",
28-
"use_env_variable": "DATABASE_URL",
29-
"disable_sql_logging": true,
30-
"ssl": false,
31-
"dialectOptions": {
32-
"ssl": false
33-
},
34-
"pool": {
47+
"production": {
48+
"dialect": "postgres",
49+
"use_env_variable": "DATABASE_URL",
50+
"disable_sql_logging": true,
51+
"ssl": false,
52+
"dialectOptions": {
53+
"ssl": false
54+
},
55+
"pool": {
3556
"max": 15,
3657
"min": 0,
3758
"idle": 10000
38-
}
39-
},
59+
}
60+
},
4061
"production-migrate": {
4162
"dialect": "postgres",
4263
"use_env_variable": "PG_DATABASE_URL",

Diff for: package.json

+4
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@
6464
"@octokit/graphql-schema": "^10.73.0",
6565
"@sentry/node": "^6.8.0",
6666
"@types/event-loop-lag": "^1.0.30",
67+
"@types/express-sslify": "^1.2.3",
68+
"@types/glob": "^8.1.0",
69+
"@types/http-proxy": "^1.17.12",
6770
"@types/safe-json-stringify": "^1.1.2",
6871
"@types/sanitize-html": "^2.9.0",
72+
"@types/throng": "^5.0.5",
6973
"@types/yaml": "^1.9.7",
7074
"atlassian-jwt": "^2.0.0",
7175
"aws-sdk": "^2.1015.0",

Diff for: src/app.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-call */
2+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
13
import express, { Express, NextFunction, Request, Response } from "express";
24
import path from "path";
35
import { registerHandlebarsPartials } from "utils/handlebars/handlebar-partials";
46
import { registerHandlebarsHelpers } from "utils/handlebars/handlebar-helpers";
57
import crypto from "crypto";
68
import { elapsedTimeMetrics } from "config/statsd";
7-
import sslify from "express-sslify";
9+
import { HTTPS } from "express-sslify";
810
import helmet from "helmet";
911
import { RootRouter } from "routes/router";
1012
import { proxyLocalUIForDev } from "~/src/spa-proxy";
@@ -37,16 +39,17 @@ const secureHeaders = (app: Express) => {
3739
next();
3840
});
3941

42+
const appUrl = process.env.APP_URL || "";
4043
// Content Security Policy
4144
app.use(helmet.contentSecurityPolicy({
4245
useDefaults: true,
4346
directives: {
4447
defaultSrc: ["'self'"],
4548
// Allow <script> tags hosted by ourselves and from atlassian when inserted into an iframe
46-
scriptSrc: ["'self'", process.env.APP_URL, "https://*.atlassian.net", "https://*.jira.com", "https://connect-cdn.atl-paas.net/",
49+
scriptSrc: ["'self'", appUrl, "https://*.atlassian.net", "https://*.jira.com", "https://connect-cdn.atl-paas.net/",
4750
"'unsafe-inline'", "'strict-dynamic'", (_: Request, res: Response): string => `'nonce-${res.locals.nonce as string}'`],
4851
// Allow XMLHttpRequest/fetch requests
49-
connectSrc: ["'self'", process.env.APP_URL],
52+
connectSrc: ["'self'", appUrl],
5053
// Allow <style> tags hosted by ourselves as well as style="" attributes
5154
styleSrc: ["'self'", "'unsafe-inline'"],
5255
// Allow using github-for-jira pages as iframes only in jira
@@ -89,7 +92,7 @@ export const getFrontendApp = (): Express => {
8992
app.use(elapsedTimeMetrics);
9093

9194
if (process.env.FORCE_HTTPS) {
92-
app.use(sslify.HTTPS({ trustProtoHeader: true }));
95+
app.use(HTTPS({ trustProtoHeader: true }));
9396
}
9497

9598
setupFrontendApp(app);

Diff for: src/config/cidr-validator.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @param {string} ip - The IP to convert to an integer
1212
* @returns {number} Integer representation of the IP Address
1313
*/
14-
const ip4ToInt = (ip) =>
14+
const ip4ToInt = (ip: string): number =>
1515
ip.split(".").reduce((int, oct) => (int << 8) + parseInt(oct, 10), 0) >>> 0;
1616

1717
/**
@@ -20,9 +20,9 @@ const ip4ToInt = (ip) =>
2020
* @param {string} ip - The IP Address in question
2121
* @returns {Function} A function to compare an IP to the CIDR
2222
*/
23-
const isIp4InCidr = (ip) => (cidr) => {
24-
const [range, bits = 32] = cidr.split("/");
25-
const mask = ~(2 ** (32 - bits) - 1);
23+
const isIp4InCidr = (ip: string) => (cidr: string) => {
24+
const [range, bits = "32"] = cidr.split("/");
25+
const mask = ~(2 ** (32 - parseInt(bits)) - 1);
2626
return (ip4ToInt(ip) & mask) === (ip4ToInt(range) & mask);
2727
};
2828

Diff for: src/config/env.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getNodeEnv } from "utils/is-node-env";
66
import { EnvironmentEnum, MicrosEnvTypeEnum } from "interfaces/common";
77
import { envCheck } from "utils/env-utils";
88

9-
const nodeEnv: EnvironmentEnum = EnvironmentEnum[getNodeEnv()];
9+
const nodeEnv: EnvironmentEnum = getNodeEnv();
1010

1111
// Load environment files
1212
[
@@ -23,7 +23,7 @@ type Transforms<T, K extends keyof T = keyof T> = {
2323
};
2424

2525
const transforms: Transforms<EnvVars> = {
26-
MICROS_ENV: (value?: string) => EnvironmentEnum[value || EnvironmentEnum.development],
26+
MICROS_ENV: (value?: string) => EnvironmentEnum[value || ""] as EnvironmentEnum || EnvironmentEnum.development,
2727
MICROS_GROUP: (value?: string) => value || "",
2828
NODE_ENV: () => nodeEnv,
2929
S3_DUMPS_BUCKET_NAME: (value?: string) => value ?? "",

Diff for: src/config/feature-flags.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const getLaunchDarklyValue = async <T = boolean | string | number>(flag: Boolean
7070
try {
7171
await launchdarklyClient.waitForInitialization();
7272
const user = createLaunchdarklyUser(key);
73-
return launchdarklyClient.variation(flag, user, defaultValue);
73+
return launchdarklyClient.variation(flag, user, defaultValue) as Promise<T>;
7474
} catch (err: unknown) {
7575
logger.error({ flag, err }, "Error resolving value for feature flag");
7676
return defaultValue;
@@ -102,7 +102,7 @@ export const shouldSendAll = async (type: ShouldSendAllStringTypes, jiraHost: st
102102
// Full set:
103103
// ["branches-backfill", "builds-backfill", "commits-backfill", "deployments-backfill", "prs-backfill", "branches", "builds", "commits", "deployments", "prs"]
104104
const sendAllString = await stringFlag(StringFlags.SEND_ALL, "[]", jiraHost);
105-
const sendAllArray: string[] = JSON.parse(sendAllString);
105+
const sendAllArray: string[] = JSON.parse(sendAllString) as string[];
106106
return Array.isArray(sendAllArray) && sendAllArray.includes(type);
107107
} catch (e: unknown) {
108108
logger.error({ err: e, type }, "Cannot define if should send all");
@@ -113,7 +113,7 @@ export const shouldSendAll = async (type: ShouldSendAllStringTypes, jiraHost: st
113113
export const isBlocked = async (jiraHost: string, installationId: number, logger: Logger): Promise<boolean> => {
114114
try {
115115
const blockedInstallationsString = await stringFlag(StringFlags.BLOCKED_INSTALLATIONS, "[]", jiraHost);
116-
const blockedInstallations: number[] = JSON.parse(blockedInstallationsString);
116+
const blockedInstallations: number[] = JSON.parse(blockedInstallationsString) as number[];
117117
return Array.isArray(blockedInstallations) && blockedInstallations.includes(installationId);
118118
} catch (e: unknown) {
119119
logger.error({ err: e, installationId }, "Cannot define if isBlocked");

Diff for: src/config/logger.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-return */
2+
/* eslint-disable @typescript-eslint/no-unsafe-call */
3+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
4+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
5+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
16
import Logger, { createLogger, LogLevel, Serializers, Stream } from "bunyan";
27
import { isArray, isString, merge, omit, mapKeys } from "lodash";
38
import { SafeRawLogStream } from "utils/logger-utils";
@@ -8,7 +13,7 @@ const REPO_URL_REGEX = /^(\/api\/v3)?\/repos\/([^/]+)\/([^/]+)\/(.*)$/;
813

914
const maybeRemoveOrgAndRepo = (url: string) => {
1015
if (url.match(REPO_URL_REGEX)) {
11-
return url.replace(REPO_URL_REGEX, (_, maybeV3Prefix, org, repo, rest) => {
16+
return url.replace(REPO_URL_REGEX, (_, maybeV3Prefix: string, org: string, repo: string, rest: string) => {
1217
return [
1318
maybeV3Prefix,
1419
"repos",
@@ -26,7 +31,7 @@ const COMPARE_URL_REGEX = /^(.*)\/compare\/(.*)\.\.\.(.*)$/;
2631
const isCompareUrl = (url: string) => url.match(COMPARE_URL_REGEX);
2732

2833
const removeBranchesFromCompareUrl = (url: string) =>
29-
url.replace(COMPARE_URL_REGEX, (_, prefix, branch1, branch2) => {
34+
url.replace(COMPARE_URL_REGEX, (_, prefix: string, branch1: string, branch2: string) => {
3035
return [
3136
prefix,
3237
"compare",
@@ -40,7 +45,7 @@ const GIT_REF_URL_REGEX = /^(.*)\/git\/ref\/([^/]+)$/;
4045
const isGitRefUrl = (url: string) => url.match(GIT_REF_URL_REGEX);
4146

4247
const removeGitRefFromUrl = (url: string) =>
43-
url.replace(GIT_REF_URL_REGEX, (_, prefix: string, gitRef) =>
48+
url.replace(GIT_REF_URL_REGEX, (_, prefix: string, gitRef: string) =>
4449
`${prefix}/git/ref/${createHashWithSharedSecret(decodeURIComponent(gitRef))}`
4550
);
4651

@@ -49,7 +54,7 @@ const USERS_URL_REGEX = /^(\/api\/v3)?\/users\/([^/]+)$/;
4954
const isUsersUrl = (url: string) => url.match(USERS_URL_REGEX);
5055

5156
const removeUserFromUrl = (url: string) =>
52-
url.replace(USERS_URL_REGEX, (_, maybeV3Prefix, userName) =>
57+
url.replace(USERS_URL_REGEX, (_, maybeV3Prefix: string, userName: string) =>
5358
[
5459
maybeV3Prefix,
5560
"users",
@@ -62,7 +67,7 @@ const REST_DEVINFO_BRANCH_URL_REGEX = /^\/rest\/devinfo\/([^/]+)\/repository\/([
6267
const isDevInfoBranchUrl = (url: string) => url.match(REST_DEVINFO_BRANCH_URL_REGEX);
6368

6469
const removeBranchFromDevInfoUrl = (url: string) =>
65-
url.replace(REST_DEVINFO_BRANCH_URL_REGEX, (_, version, repoNo, branchaName, updateSequenceId: string) =>
70+
url.replace(REST_DEVINFO_BRANCH_URL_REGEX, (_, version: string, repoNo: string, branchaName: string, updateSequenceId: string) =>
6671
[
6772
"/rest/devinfo",
6873
version,
@@ -85,26 +90,26 @@ const JIRA_HOST_QUERY_PARAM_REGEX = /jiraHost=(https%3A%2F%2F[\w-]+\.atlassian\.
8590

8691
const maybeCensorJiraHostInQueryParams = (url: string) => {
8792
if (url.match(JIRA_HOST_QUERY_PARAM_REGEX)) {
88-
return url.replace(JIRA_HOST_QUERY_PARAM_REGEX, (_, jiraHostEncoded) =>
93+
return url.replace(JIRA_HOST_QUERY_PARAM_REGEX, (_, jiraHostEncoded: string) =>
8994
`jiraHost=${createHashWithSharedSecret(decodeURIComponent(jiraHostEncoded))}`);
9095
}
9196
return url;
9297
};
9398

9499

95100
const removeOwnersAndReposFromUrl = (url: string) =>
96-
url.replace(CREATE_BRANCH_PAGE_BRANCHES_URL_REGEX, (_, prefix, owners, repos, suffix) =>
101+
url.replace(CREATE_BRANCH_PAGE_BRANCHES_URL_REGEX, (_, prefix: string, owners: string, repos: string, suffix: string) =>
97102
[
98103
prefix,
99104
"owners",
100105
createHashWithSharedSecret(decodeURIComponent(owners)),
101106
"repos",
102107
createHashWithSharedSecret(decodeURIComponent(repos)),
103108
"branches"
104-
].join("/") + (suffix as string)
109+
].join("/") + suffix
105110
);
106111

107-
const censorUrl = (url) => {
112+
const censorUrl = (url: string): string => {
108113
if (!url) {
109114
return url;
110115
}
@@ -146,13 +151,13 @@ const censorUrl = (url) => {
146151

147152
const MSG_WITH_REPO_NAME_REGEX = /^(.*) Repository with the name '(.*)\/(.*)'.$/;
148153

149-
const censorMessage = (msg) => {
154+
const censorMessage = (msg: string): string => {
150155
if (!msg) {
151156
return msg;
152157
}
153158
if (typeof msg === "string") {
154159
if (msg.match(MSG_WITH_REPO_NAME_REGEX)) {
155-
return msg.replace(MSG_WITH_REPO_NAME_REGEX, (_, prefix, orgName, repoName) => {
160+
return msg.replace(MSG_WITH_REPO_NAME_REGEX, (_, prefix: string, orgName: string, repoName: string) => {
156161
return [
157162
prefix,
158163
"Repository with the name",

Diff for: src/config/statsd.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const elapsedTimeMetrics = (
103103
res.once("finish", () => {
104104
const elapsedTime = elapsedTimeInMs();
105105
const statusCode = `${res.statusCode}`;
106-
const path = (req.baseUrl || "") + (req.route?.path as string || "/*");
106+
const path = (req.baseUrl || "") + ((req.route as { path?: string; })?.path || "/*");
107107
const tags = { path, method, statusCode };
108108
(req.log || logger).debug(`${method} request executed in ${elapsedTime} with status ${statusCode} path ${path}`);
109109

Diff for: src/main.ts

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ if (isNodeProd()) {
9595
troubleshootUnresponsiveWorkers_worker();
9696
},
9797
lifetime: Infinity
98+
}).catch((err: unknown) => {
99+
getLogger("frontend-app").error({ err }, "Error running frontend-app");
98100
});
99101
} else {
100102
// Dev/test single process, don't need clustering

0 commit comments

Comments
 (0)