Skip to content

Commit 433ada0

Browse files
NONE: Re-enable more lint rules (#2596)
* NONE: Re-enable more lint rules * Fix broken lint
1 parent 3c5a271 commit 433ada0

15 files changed

+26
-21
lines changed

Diff for: .eslintrc.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@
125125
"src/jira/**",
126126
"src/models/**",
127127
"src/sync/**",
128-
"src/transforms/**",
129-
"src/util/**"
128+
"src/transforms/**"
130129
],
131130
"rules": {
132131
// To be removed later

Diff for: src/models/subscription.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ export class Subscription extends Model {
5050
isSecurityPermissionsAccepted: boolean;
5151

5252
static async getAllForHost(jiraHost: string, gitHubAppId?: number): Promise<Subscription[]> {
53-
return this.findAll({
53+
return await this.findAll({
5454
where: {
5555
...(gitHubAppId !== undefined && { gitHubAppId }), // Add gitHubAppId only if passed
5656
jiraHost
5757
}
58-
});
58+
}) || [];
5959
}
6060

6161
static getAllForInstallation(

Diff for: src/routes/jira/jira-delete.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe("DELETE /jira/configuration", () => {
3434
};
3535

3636
mocked(Subscription.getSingleInstallation).mockResolvedValue(subscription);
37+
mocked(Subscription.getAllForHost).mockResolvedValue([]);
3738
mocked(Installation.getForHost).mockResolvedValue(installation);
3839
});
3940

Diff for: src/util/axios/url-params-middleware.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const logger = getLogger("url-params");
1919
export const urlParamsMiddleware = (config: AxiosRequestConfig): AxiosRequestConfig => {
2020
const uri = () => `${config.baseURL || ""}${config.url || ""}`;
2121
// If uri is empty and there's no url params, just skip this middleware
22-
if (!uri()?.length) {
22+
if (!uri().length) {
2323
return config;
2424
}
2525

@@ -35,7 +35,7 @@ export const urlParamsMiddleware = (config: AxiosRequestConfig): AxiosRequestCon
3535
}
3636
const key = `{${k}}`;
3737
const value = encodeURIComponent(String(v));
38-
if (!value.length || !uri()?.includes(key)) {
38+
if (!value.length || !uri().includes(key)) {
3939
logger.error({ key, value, config }, "URL Param doesn't exist in url path - ignoring");
4040
return;
4141
}

Diff for: src/util/create-url-with-query-string.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Request } from "express";
99
*/
1010
export const createUrlWithQueryString = (req: Request, URL: string): string => {
1111
let queryString = "";
12+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1213
const keys = req.query ? Object.keys(req.query) : [];
1314
const queryStrings = keys.reduce((_, current, index, array) => {
1415
if (req.query[current]) {

Diff for: src/util/filtering-http-logs-stream.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const filteringHttpLogsStream = (filteringLoggerName: string, out: Writab
2020
write: (chunk: unknown, encoding: BufferEncoding, next) => {
2121
//TODO Remove this code when there will be convenient way to do it in Probot.
2222
//See https://github.com/probot/probot/issues/1577
23-
if (String(chunk)?.match(`${filteringLoggerName}.*(GET|POST|DELETE|PUT|PATCH) /`)) {
23+
if (String(chunk).match(`${filteringLoggerName}.*(GET|POST|DELETE|PUT|PATCH) /`)) {
2424
out.write(chunk, encoding);
2525
}
2626
next();

Diff for: src/util/get-github-client-config.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ describe("user client", () => {
127127
gheApiNock.get("/user")
128128
.matchHeader("ApiKeyHeader", "super-key")
129129
.reply(200);
130-
const client = await createUserClient("MY_TOKEN", jiraHost, { trigger: "test" }, getLogger("test"), gitHubServerApp?.id);
130+
const client = await createUserClient("MY_TOKEN", jiraHost, { trigger: "test" }, getLogger("test"), gitHubServerApp.id);
131131
const response = await client.getUser();
132132
expect(response.status).toStrictEqual(200);
133133
});
134134

135135
it("should not inject API key when provided", async () => {
136136
gheApiNock.get("/user")
137137
.reply(200);
138-
const client = await createUserClient("MY_TOKEN", jiraHost, { trigger: "test" }, getLogger("test"), gitHubServerApp?.id);
138+
const client = await createUserClient("MY_TOKEN", jiraHost, { trigger: "test" }, getLogger("test"), gitHubServerApp.id);
139139
const response = await client.getUser();
140140
expect(response.status).toStrictEqual(200);
141141
});
@@ -161,7 +161,7 @@ describe("installation client", () => {
161161
gheApiNock.get("/rate_limit")
162162
.matchHeader("ApiKeyHeader", "super-key")
163163
.reply(200);
164-
const client = await createInstallationClient(subscription!.gitHubInstallationId, jiraHost, { trigger: "test" }, getLogger("test"), gitHubServerApp?.id);
164+
const client = await createInstallationClient(subscription!.gitHubInstallationId, jiraHost, { trigger: "test" }, getLogger("test"), gitHubServerApp.id);
165165
const response = await client.getRateLimit();
166166
expect(response.status).toStrictEqual(200);
167167
});
@@ -172,7 +172,7 @@ describe("installation client", () => {
172172
gheApiNock.get("/rate_limit")
173173
.reply(200);
174174

175-
const client = await createInstallationClient(subscription!.gitHubInstallationId, jiraHost, { trigger: "test" }, getLogger("test"), gitHubServerApp?.id);
175+
const client = await createInstallationClient(subscription!.gitHubInstallationId, jiraHost, { trigger: "test" }, getLogger("test"), gitHubServerApp.id);
176176
const response = await client.getRateLimit();
177177
expect(response.status).toStrictEqual(200);
178178
});
@@ -193,15 +193,15 @@ describe("app client", () => {
193193
gheAppTokenNock()
194194
.matchHeader("ApiKeyHeader", "super-key");
195195

196-
const client = await createAppClient(getLogger("test"), jiraHost, gitHubServerApp?.id, { trigger: "test" });
196+
const client = await createAppClient(getLogger("test"), jiraHost, gitHubServerApp.id, { trigger: "test" });
197197
const response = await client.getApp();
198198
expect(response.status).toStrictEqual(200);
199199
});
200200

201201
it("should not inject API key when not provided", async () => {
202202
gheAppTokenNock();
203203

204-
const client = await createAppClient(getLogger("test"), jiraHost, gitHubServerApp?.id, { trigger: "test" });
204+
const client = await createAppClient(getLogger("test"), jiraHost, gitHubServerApp.id, { trigger: "test" });
205205
const response = await client.getApp();
206206
expect(response.status).toStrictEqual(200);
207207
});

Diff for: src/util/github-installations-helper.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const mapSyncStatus = (syncStatus: SyncStatus = SyncStatus.PENDING): ConnectionS
4545
export const getInstallations = async (subscriptions: Subscription[], log: Logger, gitHubAppId: number | undefined): Promise<InstallationResults> => {
4646
const installations = await Promise.allSettled(subscriptions.map((sub) => getInstallation(sub, gitHubAppId, log)));
4747
// Had to add "unknown" in between type as lodash, types is incorrect for groupBy of `installations`
48-
const connections = groupBy(installations, "status") as unknown as { fulfilled: PromiseFulfilledResult<AppInstallation>[], rejected: PromiseRejectedResult[] };
48+
const connections = groupBy(installations, "status") as unknown as { fulfilled?: PromiseFulfilledResult<AppInstallation>[], rejected?: PromiseRejectedResult[] };
4949
const fulfilled = connections.fulfilled?.map(v => v.value) || [];
5050
const rejected = connections.rejected?.map(v => v.reason as FailedAppInstallation) || [];
5151
return {
@@ -119,8 +119,8 @@ export const getConnectionsAndInstallations = async (subscriptions: Subscription
119119
};
120120

121121
export const countStatus = (connections: SuccessfulConnection[], syncStatus: string): number =>
122-
connections.filter(org => org?.syncStatus === syncStatus).length || 0;
122+
connections.filter(org => org.syncStatus === syncStatus).length || 0;
123123

124124
export const countNumberSkippedRepos = (connections: SuccessfulConnection[]): number => {
125-
return connections.reduce((acc, obj) => acc + (obj?.totalNumberOfRepos || 0) - (obj?.numberOfSyncedRepos || 0) , 0);
125+
return connections.reduce((acc, obj) => acc + (obj.totalNumberOfRepos || 0) - (obj.numberOfSyncedRepos || 0) , 0);
126126
};

Diff for: src/util/handlebars/handlebar-helpers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { isPlainObject } from "lodash";
33
import { ConnectionSyncStatus } from "utils/github-installations-helper";
44

55
export const concatStringHelper = (...strings: string[]) => strings.filter((arg: unknown) => typeof arg !== "object").join(" ");
6+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
67
export const toLowercaseHelper = (str?: string) => !isPlainObject(str) && str?.toString?.().toLowerCase() || "";
8+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
79
export const replaceSpaceWithHyphenHelper = (str?: string) => !isPlainObject(str) && str?.toString?.().replace(/ /g, "-") || "";
810
export const toISOStringHelper = (date?: Date) => date ? date.toISOString() : undefined;
911

@@ -62,7 +64,7 @@ export const registerHandlebarsHelpers = () => {
6264
hbs.registerHelper("isModal", (modalId) => modalId === "jiraDomainModal");
6365

6466

65-
hbs.registerHelper("isMissingPermissions", (syncWarning: string) => syncWarning?.includes("Invalid permissions for"));
67+
hbs.registerHelper("isMissingPermissions", (syncWarning?: string) => syncWarning?.includes("Invalid permissions for"));
6668

6769
hbs.registerHelper(
6870
"disableDeleteSubscription",

Diff for: src/util/handlebars/handlebar-partials.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from "path";
44

55
export const registerHandlebarsPartials = (partialPath: string) => {
66
fs.readdirSync(partialPath)
7-
?.filter(file => file.endsWith(".hbs"))
7+
.filter(file => file.endsWith(".hbs"))
88
.forEach(file => {
99
hbs.registerPartial(
1010
file.replace(/\.hbs$/, ""), // removes extension of file

Diff for: src/util/heap-size-utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const hasEnoughFreeHeap = (notEnoughHeapPctThreshold: number, logger: Log
2020
if (freeHeapPctBeforeGc < notEnoughHeapPctThreshold) {
2121
const timestampBeforeGc = Date.now();
2222
logger.info(`Free heap size is less than ${notEnoughHeapPctThreshold}. Triggering GC...`);
23+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
2324
global.gc?.call(global);
2425
const timestampAfterGc = Date.now();
2526

Diff for: src/util/is-connected.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Subscription } from "models/subscription";
22

33
export const isConnected = async (jiraHost: string): Promise<boolean> => {
4-
const subscriptions = await Subscription.getAllForHost(jiraHost) || [];
4+
const subscriptions = await Subscription.getAllForHost(jiraHost);
55

66
return subscriptions.length > 0;
77
};

Diff for: src/util/is-node-env.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EnvironmentEnum } from "interfaces/common";
22

3-
export const getNodeEnv: () => EnvironmentEnum = () => EnvironmentEnum[process.env.NODE_ENV || ""] as EnvironmentEnum || EnvironmentEnum.development;
3+
export const getNodeEnv: () => EnvironmentEnum = () => EnvironmentEnum[process.env.NODE_ENV || ""] as EnvironmentEnum | undefined || EnvironmentEnum.development;
44
export const isNodeEnv = (env: EnvironmentEnum) => getNodeEnv() === env;
55
export const isNodeProd = () => isNodeEnv(EnvironmentEnum.production);
66
export const isNodeDev = () => isNodeEnv(EnvironmentEnum.development);

Diff for: src/util/jira-utils.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe("Jira Utils", () => {
116116
["JIRA-123abcd JIRA-456 abcd", "JIRA-456"]
117117
])("matching with whole word", (full, ...issueKeys) => {
118118
it(`should match "${full}" to "${issueKeys.toString()}"`, () => {
119-
expect(jiraIssueKeyParser(full)).toEqual(issueKeys ? issueKeys : []);
119+
expect(jiraIssueKeyParser(full)).toEqual(issueKeys);
120120
});
121121
});
122122
});

Diff for: src/util/preemptive-rate-limit.ts

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const getRateRateLimitStatus = async (context: SQSMessageContext<BaseMessagePayl
6262

6363
const getRateResetTimeInSeconds = (rateLimitResponse: Octokit.RateLimitGetResponse): number => {
6464
// Get the furthest away rate reset to ensure we don't exhaust the other one too quickly
65+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
6566
const resetEpochDateTimeInSeconds = Math.max(rateLimitResponse?.resources?.core?.reset, rateLimitResponse?.resources?.graphql?.reset);
6667
const timeToResetInSeconds = resetEpochDateTimeInSeconds - (Date.now()/1000);
6768
//sometimes, possibly a bug in github?, the timeToResetInSeconds is almost 0. To avoid reschdule to task too soon, adding a minimum of 10 minutes.

0 commit comments

Comments
 (0)