From 8b9d6802299f2c96147163ecc4adbad48f110cda Mon Sep 17 00:00:00 2001 From: Andrea Ligios <11974750+andrea-ligios@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:42:34 +0200 Subject: [PATCH 1/2] Straighten the method with guard clauses --- lib/commons/config.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/commons/config.js b/lib/commons/config.js index a09b468f..38129b38 100644 --- a/lib/commons/config.js +++ b/lib/commons/config.js @@ -18,18 +18,13 @@ const getRequiredOption = (options, optionName) => { }; const getApiKey = ({ apiKey, token }) => { - let calculatedApiKey = apiKey; - if (!calculatedApiKey) { - calculatedApiKey = token; - if (!calculatedApiKey) { - throw new ReportPortalRequiredOptionError('apiKey'); - } else { - console.warn(`Option 'token' is deprecated. Use 'apiKey' instead.`); - } - } - - return calculatedApiKey; -}; + if (apiKey) return apiKey; + + if (!token) throw new ReportPortalRequiredOptionError('apiKey'); + + console.warn(`Option 'token' is deprecated. Use 'apiKey' instead.`); + return token; +} const getClientConfig = (options) => { let calculatedOptions = options; From 051976ab6a1165dcddbad109d6a3913796d50f95 Mon Sep 17 00:00:00 2001 From: Andrea Ligios <11974750+andrea-ligios@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:50:02 +0200 Subject: [PATCH 2/2] Fix syntax and whitespaces --- lib/commons/config.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/commons/config.js b/lib/commons/config.js index 38129b38..7d721fcd 100644 --- a/lib/commons/config.js +++ b/lib/commons/config.js @@ -19,12 +19,10 @@ const getRequiredOption = (options, optionName) => { const getApiKey = ({ apiKey, token }) => { if (apiKey) return apiKey; - if (!token) throw new ReportPortalRequiredOptionError('apiKey'); - console.warn(`Option 'token' is deprecated. Use 'apiKey' instead.`); return token; -} +}; const getClientConfig = (options) => { let calculatedOptions = options;