From 1ca1a214e803fc4f4468ae6c205bd92a30ac0659 Mon Sep 17 00:00:00 2001
From: RahulGautamSingh <rahultesnik@gmail.com>
Date: Tue, 30 Aug 2022 21:00:57 +0530
Subject: [PATCH] refactor: use optional chaining (#17510)

---
 lib/config/migrations/custom/schedule-migration.ts             | 2 +-
 lib/modules/datasource/galaxy-collection/index.ts              | 2 +-
 lib/modules/datasource/helm/index.ts                           | 2 +-
 lib/modules/versioning/maven/compare.ts                        | 2 +-
 .../repository/update/branch/execute-post-upgrade-commands.ts  | 3 +--
 5 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/lib/config/migrations/custom/schedule-migration.ts b/lib/config/migrations/custom/schedule-migration.ts
index 6ac6dc4cc4..3d5bd434ec 100644
--- a/lib/config/migrations/custom/schedule-migration.ts
+++ b/lib/config/migrations/custom/schedule-migration.ts
@@ -29,7 +29,7 @@ export class ScheduleMigration extends AbstractMigration {
             schedules[i].replace(regEx(/( \d?\d)((a|p)m)/g), '$1:00$2') // TODO #12071
           ).schedules[0];
           // Only migrate if the after time is greater than before, e.g. "after 10pm and before 5am"
-          if (!parsedSchedule || !parsedSchedule.t_a || !parsedSchedule.t_b) {
+          if (!parsedSchedule?.t_a || !parsedSchedule.t_b) {
             continue;
           }
 
diff --git a/lib/modules/datasource/galaxy-collection/index.ts b/lib/modules/datasource/galaxy-collection/index.ts
index 9e1fd5df9a..1839445f1e 100644
--- a/lib/modules/datasource/galaxy-collection/index.ts
+++ b/lib/modules/datasource/galaxy-collection/index.ts
@@ -43,7 +43,7 @@ export class GalaxyCollectionDatasource extends Datasource {
       this.handleGenericErrors(err);
     }
 
-    if (!baseUrlResponse || !baseUrlResponse.body) {
+    if (!baseUrlResponse?.body) {
       logger.warn(
         { dependency: packageName },
         `Received invalid data from ${baseUrl}`
diff --git a/lib/modules/datasource/helm/index.ts b/lib/modules/datasource/helm/index.ts
index 621092c228..5419c1d5aa 100644
--- a/lib/modules/datasource/helm/index.ts
+++ b/lib/modules/datasource/helm/index.ts
@@ -37,7 +37,7 @@ export class HelmDatasource extends Datasource {
       res = await this.http.get('index.yaml', {
         baseUrl: ensureTrailingSlash(helmRepository),
       });
-      if (!res || !res.body) {
+      if (!res?.body) {
         logger.warn(
           { helmRepository },
           `Received invalid response from helm repository`
diff --git a/lib/modules/versioning/maven/compare.ts b/lib/modules/versioning/maven/compare.ts
index b5d54ed21f..c97629d614 100644
--- a/lib/modules/versioning/maven/compare.ts
+++ b/lib/modules/versioning/maven/compare.ts
@@ -368,7 +368,7 @@ function parseRange(rangeStr: string): Range[] | null {
   if (interval.leftType) {
     return null;
   } // something like '[1,2],[3'
-  if (!ranges || !ranges.length) {
+  if (!ranges?.length) {
     return null;
   }
 
diff --git a/lib/workers/repository/update/branch/execute-post-upgrade-commands.ts b/lib/workers/repository/update/branch/execute-post-upgrade-commands.ts
index 4163f4412e..8983d0d36f 100644
--- a/lib/workers/repository/update/branch/execute-post-upgrade-commands.ts
+++ b/lib/workers/repository/update/branch/execute-post-upgrade-commands.ts
@@ -187,8 +187,7 @@ export default async function executePostUpgradeCommands(
 
   const updateUpgradeCommands: BranchUpgradeConfig[] = config.upgrades.filter(
     ({ postUpgradeTasks }) =>
-      !postUpgradeTasks ||
-      !postUpgradeTasks.executionMode ||
+      !postUpgradeTasks?.executionMode ||
       postUpgradeTasks.executionMode === 'update'
   );
 
-- 
GitLab