Skip to content

Commit

Permalink
NONE: Re-enable eslint rules (#2556)
Browse files Browse the repository at this point in the history
  • Loading branch information
atraversatlassian authored Nov 20, 2023
1 parent 0ec4bb3 commit 82fd9fe
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 36 deletions.
9 changes: 5 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/await-thenable": "off",
"@typescript-eslint/no-misused-promises": "off"
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-explicit-any": "off"
}
},
{
Expand All @@ -131,7 +132,8 @@
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-call": "off"
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-explicit-any": "off"
}
},
{
Expand All @@ -142,8 +144,7 @@
"@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",
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/no-unnecessary-condition": "off"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/config/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const requestSerializer = (req) => req && ({
remotePort: req.socket?.remotePort
});

const graphQlErrorsSerializer = (errors: Array<any>) => (
const graphQlErrorsSerializer = (errors: Array<Error>) => (
{
errors: errors.map(error => errorSerializer(error))
}
Expand Down
13 changes: 12 additions & 1 deletion src/github/client/github-client.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AxiosResponse } from "axios";
import { GraphQLError } from "./github-client-errors";
import { Octokit } from "@octokit/rest";
import { JiraAuthor } from "~/src/interfaces/jira";

export enum SortDirection {
ASC = "asc",
Expand Down Expand Up @@ -151,6 +152,14 @@ export type CodeScanningAlertResponseItem = {
most_recent_instance: CodeScanningAlertResponseItemMostRecentInstance;
};

export interface Commit {
author: JiraAuthor;
authoredDate: string;
message: string;
oid: string;
url: string;
}

export interface Branch {
associatedPullRequests: {
nodes: {
Expand All @@ -169,7 +178,9 @@ export interface Branch {
oid: string;
message: string;
url: string;
history: any;
history: {
nodes: Commit[];
}
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/middleware/frontend-log-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ declare global {
}
}

export const LogMiddleware = async (req: Request<ParamsDictionary, any, { jiraHost?: string }>, res: Response, next: NextFunction): Promise<void> => {
export const LogMiddleware = async (req: Request<ParamsDictionary, unknown, { jiraHost?: string }>, res: Response, next: NextFunction): Promise<void> => {
req.log = getLogger("frontend-log-middleware", {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
fields: req.log?.fields,
Expand Down Expand Up @@ -77,15 +77,15 @@ export const LogMiddleware = async (req: Request<ParamsDictionary, any, { jiraHo
next();
};

const getUnvalidatedJiraHost = (req: Request<ParamsDictionary, any, { jiraHost?: string }>): string | undefined =>
const getUnvalidatedJiraHost = (req: Request<ParamsDictionary, unknown, { jiraHost?: string }>): string | undefined =>
req.session?.jiraHost || extractUnsafeJiraHost(req);

/**
* Checks if the URL matches any of the URL patterns defined in `moduleUrls`
*/
const checkPathValidity = (url: string) => moduleUrls.some(moduleUrl => matchRouteWithPattern(moduleUrl, url));

const extractUnsafeJiraHost = (req: Request<ParamsDictionary, any, { jiraHost?: string }>): string | undefined => {
const extractUnsafeJiraHost = (req: Request<ParamsDictionary, unknown, { jiraHost?: string }>): string | undefined => {
if (checkPathValidity(req.path) && req.method == "GET") {
// Only save xdm_e query when on the GET post install url (iframe url)
return req.query.xdm_e as string;
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/github-server-app-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jest.mock("models/installation");
jest.mock("models/github-server-app");

const GIT_HUB_SERVER_APP_ID = 123;
const GIT_HUB_SERVER_APP_APP_ID = 789;
const GIT_HUB_SERVER_APP_APP_ID = "789";
const UUID = "97da6b0e-ec61-11ec-8ea0-0242ac120002";
const JIRA_INSTALLATION_ID = 1;

Expand Down
4 changes: 2 additions & 2 deletions src/middleware/github-server-app-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { envVars } from "config/env";
import { GITHUB_CLOUD_BASEURL } from "~/src/github/client/github-client-constants";
import { BaseLocals } from "../rest/routes";

export const GithubServerAppMiddleware = async (req: Request, res: Response<any, BaseLocals>, next: NextFunction): Promise<void> => {
export const GithubServerAppMiddleware = async (req: Request, res: Response<unknown, BaseLocals>, next: NextFunction): Promise<void> => {
const jiraHost = res.locals.jiraHost;
const { uuid } = req.params;

Expand Down Expand Up @@ -40,7 +40,7 @@ export const GithubServerAppMiddleware = async (req: Request, res: Response<any,
res.locals.gitHubAppId = gitHubServerApp.id;
res.locals.gitHubAppConfig = {
gitHubAppId: gitHubServerApp.id,
appId: gitHubServerApp.appId,
appId: String(gitHubServerApp.appId),
uuid: gitHubServerApp.uuid,
hostname: gitHubServerApp.gitHubBaseUrl,
clientId: gitHubServerApp.gitHubClientId
Expand Down
6 changes: 3 additions & 3 deletions src/middleware/jira-symmetric-jwt-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { envVars } from "~/src/config/env";
import { errorStringFromUnknown } from "../util/error-string-from-unknown";
import { BaseLocals } from "../rest/routes";

export const jiraSymmetricJwtMiddleware = async (req: Request<ParamsDictionary, any, { jwt?: string }, { jwt?: string }, BaseLocals>, res: Response, next: NextFunction) => {
export const jiraSymmetricJwtMiddleware = async (req: Request<ParamsDictionary, unknown, { jwt?: string }, { jwt?: string }, BaseLocals>, res: Response, next: NextFunction) => {
const authHeader = req.headers["authorization"] as string;
const authHeaderPrefix = "JWT ";
const cookies = req.cookies as { jwt?: string };
Expand All @@ -36,7 +36,7 @@ export const jiraSymmetricJwtMiddleware = async (req: Request<ParamsDictionary,
req.log.warn("No Installation found");
return res.status(401).send("Unauthorised");
}
let verifiedClaims: Record<any, any>;
let verifiedClaims: Record<string, string | number>;
try {
verifiedClaims = await verifySymmetricJwt(req, token, installation);
} catch (err: unknown) {
Expand Down Expand Up @@ -107,7 +107,7 @@ const verifySymmetricJwt = async (req: Request, token: string, installation: Ins
const secret = await installation.decrypt("encryptedSharedSecret", req.log);

try {
const claims = decodeSymmetric(token, secret, algorithm, false) as { exp?: number, qsh?: string };
const claims = decodeSymmetric(token, secret, algorithm, false) as Record<string, string | number>;
const tokenType = await getTokenType(req.originalUrl, req.method);

verifyJwtClaims(claims, tokenType, req);
Expand Down
2 changes: 1 addition & 1 deletion src/rest/middleware/jira-admin/jira-admin-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { errorWrapper } from "../../helper";
import { BaseLocals } from "../../routes";

const ADMIN_PERMISSION = "ADMINISTER";
export const JiraAdminEnforceMiddleware = errorWrapper("jiraAdminEnforceMiddleware", async (req: Request, res: Response<any, BaseLocals>, next: NextFunction): Promise<void> => {
export const JiraAdminEnforceMiddleware = errorWrapper("jiraAdminEnforceMiddleware", async (req: Request, res: Response<unknown, BaseLocals>, next: NextFunction): Promise<void> => {

const { accountId, installation, jiraHost } = res.locals;

Expand Down
2 changes: 1 addition & 1 deletion src/rest/middleware/jwt/jwt-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { BaseLocals } from "../../routes";
const INVALID_SECRET = "some-invalid-secret";
const SKIP_PATHS = ["/spa/deferred"];

export const JwtHandler = errorWrapper("JwtHandler", async (req: Request, res: Response<any, BaseLocals>, next: NextFunction) => {
export const JwtHandler = errorWrapper("JwtHandler", async (req: Request, res: Response<unknown, BaseLocals>, next: NextFunction) => {

const token = req.headers["authorization"];

Expand Down
2 changes: 1 addition & 1 deletion src/rest/routes/github-orgs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GitHubOrgsRouter.get("/", errorWrapper("GitHubOrgsFetchOrgs", async (req: Reques

GitHubOrgsRouter.post("/", errorWrapper("GitHubOrgsConnectJira", async (req: Request, res: Response<OrganizationsResponse, BaseLocals>) => {
const { installation, githubToken, gitHubAppId } = res.locals;
const body = req.body as { installationId: any };
const body = req.body as { installationId: unknown };
const gitHubInstallationId = Number(body.installationId);

if (!gitHubInstallationId) {
Expand Down
9 changes: 8 additions & 1 deletion src/rest/routes/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Installation } from "~/src/models/installation";

export interface BaseLocals extends Record<string, any> {
export interface BaseLocals extends Record<string, object | string | number | undefined> {
gitHubAppConfig: {
gitHubAppId: number | undefined;
appId: string;
uuid: string | undefined;
hostname: string;
clientId: string;
};
installation: Installation;
jiraHost: string;
githubToken: string;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/github/github-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ describe("GitHub router", () => {
jiraHost,
gitHubAppId: gitHubAppId,
gitHubAppConfig: expect.objectContaining({
appId: GITHUB_SERVER_APP_ID,
appId: String(GITHUB_SERVER_APP_ID),
uuid: GITHUB_SERVER_APP_UUID
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("JiraConnectEnterpriseAppRouter", () => {
.expect(200);
expect(capturedGHEAppConfig).toEqual(expect.objectContaining({
uuid: GHE_APP_UUID,
appId: 1
appId: "1"
}));
});
it("should throw error for invalid uuid", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/sqs/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export class SqsQueue<MessagePayload extends BaseMessagePayload> {
try {
context.log.warn({ err }, "Failed message");
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const errorHandlingResult = await this.errorHandler(err as any, context);
const errorHandlingResult = await this.errorHandler(err as Error, context);

this.log.info({ errorHandlingResult }, "Error handling result");
if (errorHandlingResult.isFailure) {
Expand Down
55 changes: 46 additions & 9 deletions src/sync/transforms/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,44 @@ import { isEmpty, union } from "lodash";
import { generateCreatePullRequestUrl } from "../../transforms/util/pull-request-link-generator";
import { transformRepositoryDevInfoBulk } from "~/src/transforms/transform-repository";
import { Repository } from "models/subscription";
import { Branch } from "~/src/github/client/github-client.types";
import { Branch, Commit } from "~/src/github/client/github-client.types";
import { JiraAuthor } from "~/src/interfaces/jira";

interface JiraBranch {
createPullRequestUrl: string,
id: string,
issueKeys: string[],
lastCommit: {
author: JiraAuthor,
authorTimestamp: string,
displayId: string,
fileCount: number,
hash: string,
id: string,
issueKeys: string[],
message: string,
url?: string,
updateSequenceId: number
},
name: string,
url: string,
updateSequenceId: number
}

interface JiraCommit {
author: JiraAuthor,
authorTimestamp: string,
displayId: string,
fileCount: number,
hash: string,
id: string,
issueKeys: string[],
message: string,
timestamp: string,
url: string,
updateSequenceId: number
}


// TODO: better typing in file
/**
Expand All @@ -16,7 +53,7 @@ import { Branch } from "~/src/github/client/github-client.types";
* - Title of the last associated Pull Request
* - Message from the last commit in that branch
*/
const mapBranch = (branch: Branch, repository: Repository, alwaysSend: boolean) => {
const mapBranch = (branch: Branch, repository: Repository, alwaysSend: boolean): JiraBranch | undefined => {
const branchKeys = jiraIssueKeyParser(branch.name);
const pullRequestKeys = jiraIssueKeyParser(
branch.associatedPullRequests.nodes.length ? branch.associatedPullRequests.nodes[0].title : ""
Expand Down Expand Up @@ -57,7 +94,7 @@ const mapBranch = (branch: Branch, repository: Repository, alwaysSend: boolean)
* of commits we got from the GraphQL response and maps the data
* to the structure needed for the DevInfo API
*/
const mapCommit = (commit, alwaysSend: boolean) => {
const mapCommit = (commit: Commit, alwaysSend: boolean): JiraCommit | undefined => {
const issueKeys = jiraIssueKeyParser(commit.message);

if (isEmpty(issueKeys) && !alwaysSend) {
Expand Down Expand Up @@ -85,17 +122,17 @@ const mapCommit = (commit, alwaysSend: boolean) => {
* @param payload
* @param gitHubBaseUrl - can be undefined for Cloud
*/
export const transformBranches = (payload: { branches: any, repository: Repository }, gitHubBaseUrl: string | undefined, alwaysSendBranches: boolean, alwaysSendCommits: boolean) => {
export const transformBranches = (payload: { branches: Branch[], repository: Repository }, gitHubBaseUrl: string | undefined, alwaysSendBranches: boolean, alwaysSendCommits: boolean) => {
// TODO: use reduce instead of map/filter
const branches = payload.branches
.map((branch) => mapBranch(branch, payload.repository, alwaysSendBranches))
.filter((branch) => !!branch);
.map((branch: Branch) => mapBranch(branch, payload.repository, alwaysSendBranches))
.filter((branch: JiraBranch | undefined) => !!branch);

// TODO: use reduce instead of map/filter
const commits = payload.branches.flatMap((branch) =>
const commits = payload.branches.flatMap((branch: Branch) =>
branch.target.history.nodes
.map((commit) => mapCommit(commit, alwaysSendCommits))
.filter((branch) => !!branch)
.map((commit: Commit) => mapCommit(commit, alwaysSendCommits))
.filter((commit: JiraCommit | undefined) => !!commit)
);

if ((!commits || !commits.length) && (!branches || !branches.length)) {
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/transform-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export const transformPullRequest = (repository: Repository, _jiraHost: string,

const mapReviews = (reviews: pullRequestNode["reviews"]["nodes"] = [], reviewRequests: pullRequestNode["reviewRequests"]["nodes"] = []): JiraReview[] => {
const allReviews = [...reviewRequests || [], ...reviews || []] as pullRequestNode["reviews"]["nodes"];
const usernames: Record<string, any> = {};
const usernames: Record<string, JiraReviewer> = {};

// The reduce function goes through all the reviews and creates an array of unique users
// (so users' avatars won't be duplicated on the dev panel in Jira)
Expand Down
2 changes: 1 addition & 1 deletion src/util/curl/curl-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("curl-utils", () => {
authorization: "secrets"
});
expect(result.meta).toContain("> POST / HTTP");
expect(result.body).toEqual(expect.stringContaining("HTTP Status 403"));
expect(result.body).toEqual(expect.stringContaining("403"));
expect(result.meta).toContain("< HTTP/2 403");
});
it("should not contains private information in the headers", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/util/filtering-http-logs-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Writable } from "stream";
*/
export const filteringHttpLogsStream = (filteringLoggerName: string, out: Writable = process.stdout): Writable =>
new Writable({
write: (chunk: any, encoding: BufferEncoding, next) => {
write: (chunk: unknown, encoding: BufferEncoding, next) => {
//TODO Remove this code when there will be convenient way to do it in Probot.
//See https://github.com/probot/probot/issues/1577
if (String(chunk)?.match(`${filteringLoggerName}.*(GET|POST|DELETE|PUT|PATCH) /`)) {
Expand Down
4 changes: 2 additions & 2 deletions src/util/handlebars/handlebar-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const registerHandlebarsHelpers = () => {

hbs.registerHelper(
"ifAllReposSynced",
(numberOfSyncedRepos: number, totalNumberOfRepos: number): any =>
(numberOfSyncedRepos: number, totalNumberOfRepos: number): string =>
numberOfSyncedRepos === totalNumberOfRepos
? totalNumberOfRepos
? String(totalNumberOfRepos)
: `${numberOfSyncedRepos} / ${totalNumberOfRepos}`
);

Expand Down

0 comments on commit 82fd9fe

Please sign in to comment.