diff --git a/.eslintrc.json b/.eslintrc.json index d0be326703..d4b7cd158e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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" } }, { @@ -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 @@ -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" } } diff --git a/src/config/env.ts b/src/config/env.ts index 4157be9c1c..422f726c18 100644 --- a/src/config/env.ts +++ b/src/config/env.ts @@ -23,7 +23,7 @@ type Transforms = { }; const transforms: Transforms = { - 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 ?? "", @@ -40,7 +40,7 @@ const transforms: Transforms = { if (!parsed) { return []; } - if (parsed && !Array.isArray(parsed)) { + if (!Array.isArray(parsed)) { return [parsed]; } return parsed; diff --git a/src/config/statsd.ts b/src/config/statsd.ts index bfc68731df..aef8fe827a 100644 --- a/src/config/statsd.ts +++ b/src/config/statsd.ts @@ -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, @@ -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 diff --git a/src/rest/middleware/error/index.ts b/src/rest/middleware/error/index.ts index 90dec953dd..d27dd24a4f 100644 --- a/src/rest/middleware/error/index.ts +++ b/src/rest/middleware/error/index.ts @@ -38,7 +38,7 @@ export const RestErrorHandler = (err: Error, req: Request, res: Response { - 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, diff --git a/src/services/micros/lifecycle.ts b/src/services/micros/lifecycle.ts index 9fa41ea746..8d25699e0d 100644 --- a/src/services/micros/lifecycle.ts +++ b/src/services/micros/lifecycle.ts @@ -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(); @@ -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; diff --git a/src/services/user-config-service.ts b/src/services/user-config-service.ts index 8cb5fa3abe..76d164cad6 100644 --- a/src/services/user-config-service.ts +++ b/src/services/user-config-service.ts @@ -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; @@ -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; @@ -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 } ; diff --git a/test/setup/matchers/to-be-called-with-delay.ts b/test/setup/matchers/to-be-called-with-delay.ts index b9060ba0cb..4478afab72 100644 --- a/test/setup/matchers/to-be-called-with-delay.ts +++ b/test/setup/matchers/to-be-called-with-delay.ts @@ -8,6 +8,7 @@ declare namespace jest { expect.extend({ toBeCalledWithDelaySec: async (received: jest.Mock, 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}`}`;