Skip to content

Commit

Permalink
Straighten the method with guard clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-ligios authored Sep 12, 2023
1 parent bd6a15a commit 8b9d680
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions lib/commons/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 21 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (14)

Delete `··`

Check failure on line 21 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (16)

Delete `··`

Check failure on line 21 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (18)

Delete `··`

Check failure on line 21 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (20)

Delete `··`

Check failure on line 22 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (14)

Delete `··`

Check failure on line 22 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (16)

Delete `··`

Check failure on line 22 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (18)

Delete `··`

Check failure on line 22 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (20)

Delete `··`
if (!token) throw new ReportPortalRequiredOptionError('apiKey');

Check failure on line 24 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (14)

Delete `··`

Check failure on line 24 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (16)

Delete `··`

Check failure on line 24 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (18)

Delete `··`

Check failure on line 24 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (20)

Delete `··`
console.warn(`Option 'token' is deprecated. Use 'apiKey' instead.`);

Check warning on line 25 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (14)

Unexpected console statement

Check warning on line 25 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected console statement

Check warning on line 25 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected console statement

Check warning on line 25 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected console statement
return token;
}

Check failure on line 27 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (14)

Insert `;`

Check failure on line 27 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (16)

Insert `;`

Check failure on line 27 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (18)

Insert `;`

Check failure on line 27 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (20)

Insert `;`

const getClientConfig = (options) => {
let calculatedOptions = options;
Expand Down

0 comments on commit 8b9d680

Please sign in to comment.