Skip to content

Commit

Permalink
NONE: Re-enable lint rules (#2587)
Browse files Browse the repository at this point in the history
* NONE: Re-enable lint rules

* Address feedback
  • Loading branch information
atraversatlassian authored Dec 1, 2023
1 parent 78c3ca4 commit a1e5909
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
16 changes: 7 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@
"@typescript-eslint/require-await": "off",
"@typescript-eslint/await-thenable": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unnecessary-condition": "off"
}
},
{
Expand All @@ -124,7 +125,10 @@
"src/jira/**",
"src/models/**",
"src/sync/**",
"src/transforms/**"
"src/transforms/**",
"src/util/**",
"src/sqs/**",
"src/middleware/**"
],
"rules": {
// To be removed later
Expand All @@ -133,13 +137,7 @@
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-explicit-any": "off"
}
},
{
"files": ["src/**/*.ts", "test/**/*.ts"],
"rules": {
// TODO: Re-enable gradually
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unnecessary-condition": "off"
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Transforms<T, K extends keyof T = keyof T> = {
};

const transforms: Transforms<EnvVars> = {
MICROS_ENV: (value?: string) => EnvironmentEnum[value || ""] as EnvironmentEnum || EnvironmentEnum.development,
MICROS_ENV: (value?: string) => EnvironmentEnum[value || ""] as EnvironmentEnum | undefined || EnvironmentEnum.development,
MICROS_GROUP: (value?: string) => value || "",
NODE_ENV: () => nodeEnv,
S3_DUMPS_BUCKET_NAME: (value?: string) => value ?? "",
Expand All @@ -40,7 +40,7 @@ const transforms: Transforms<EnvVars> = {
if (!parsed) {
return [];
}
if (parsed && !Array.isArray(parsed)) {
if (!Array.isArray(parsed)) {
return [parsed];
}
return parsed;
Expand Down
4 changes: 3 additions & 1 deletion src/config/statsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const elapsedTimeMetrics = (
) => {
const elapsedTimeInMs = hrtimer();
const method = req.method;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
(req.log || logger).debug({
method: req.method,
path: req.path,
Expand All @@ -103,8 +104,9 @@ export const elapsedTimeMetrics = (
res.once("finish", () => {
const elapsedTime = elapsedTimeInMs();
const statusCode = `${res.statusCode}`;
const path = (req.baseUrl || "") + ((req.route as { path?: string; })?.path || "/*");
const path = (req.baseUrl || "") + ((req.route as { path?: string; } | undefined)?.path || "/*");
const tags = { path, method, statusCode };
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
(req.log || logger).debug(`${method} request executed in ${elapsedTime} with status ${statusCode} path ${path}`);

//Count response time metric
Expand Down
2 changes: 1 addition & 1 deletion src/rest/middleware/error/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const RestErrorHandler = (err: Error, req: Request, res: Response<ApiErro

const logErrorOrWarning = (err: Error, req: Request) => {

const httpStatus = parseInt(err["status"] as string ?? "") || parseInt(err["httpStatus"] as string ?? "") || 500;
const httpStatus = parseInt(err["status"] as string | undefined ?? "") || parseInt(err["httpStatus"] as string| undefined ?? "") || 500;
const extraInfo = {
httpStatus,
method: req.method,
Expand Down
4 changes: 3 additions & 1 deletion src/services/micros/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import EventEmitter from "events";
import { getLogger } from "config/logger";

const logger = getLogger("micros.lifecycle");
let client: Consumer;
let client: Consumer | undefined;

// Create a single event emitter for all listeners
const eventEmitter = new EventEmitter();
Expand Down Expand Up @@ -36,6 +36,8 @@ export const listenToMicrosLifecycle = (active: Callback, inactive: Callback): v
}
try {
const lifecycleData: LifecycleData = JSON.parse(data.Body) as LifecycleData;
// validate that the data has the required fields
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (lifecycleData.Type === undefined || lifecycleData.Subject === undefined || lifecycleData.Message === undefined) {
logger.error({ data }, "Lifecycle event missing required data, skipping.");
return;
Expand Down
9 changes: 2 additions & 7 deletions src/services/user-config-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const getRepoConfigFromGitHub = async (gitHubInstallationClient: GitHubInstallat
/**
* Iterates through environment patterns and returns true if any environment contains too many patterns to test against.
*/
const hasTooManyPatternsPerEnvironment = (config: Config): boolean => {
const hasTooManyPatternsPerEnvironment = (config: Config | undefined): boolean => {
const environmentMapping = config?.deployments?.environmentMapping;
if (!environmentMapping) {
return false;
Expand All @@ -113,7 +113,7 @@ const convertYamlToUserConfig = (input: string | undefined, logger: Logger): Con
return {};
}

const config: Config = YAML.parse(input) as Config;
const config = YAML.parse(input) as Config | undefined;
logger.info("User config file yaml content parsed successfully");

const configDeployments = config?.deployments;
Expand All @@ -131,11 +131,6 @@ const convertYamlToUserConfig = (input: string | undefined, logger: Logger): Con
}
}


if (!deployments) {
throw new Error(`Invalid .jira/config.yml structure`);
}

// Trim the input data to only include the required attributes
const output = { deployments } ;

Expand Down
1 change: 1 addition & 0 deletions test/setup/matchers/to-be-called-with-delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare namespace jest {

expect.extend({
toBeCalledWithDelaySec: async (received: jest.Mock<unknown>, expectedDelaySec: number) => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const actual = received.mock?.calls[0][0].DelaySeconds as number;
const pass = actual == expectedDelaySec;
const message = () => `Expected parameter to have DelaySeconds = ${expectedDelaySec} ${pass ? "" : `but was ${actual}`}`;
Expand Down

0 comments on commit a1e5909

Please sign in to comment.