From c9913a830381f3e23b2b31d0b3c0b203b9707c89 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Fri, 15 Dec 2023 18:41:57 +0000 Subject: [PATCH] Lint JavaScript --- lib/utils.js | 20 +++++++++----------- test/utils.js | 4 ++-- test/wizard.js | 4 ++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 4013ea1..3f41ffc 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -24,17 +24,17 @@ const getFork = (forks, req) => { if (fork.value || fork.values) { const includedValues = toPath(fork.value ? fork.value : fork.values) - if (includedValues.some(v => sessionData.indexOf(v) >= 0)) { + if (includedValues.some((v) => sessionData.indexOf(v) >= 0)) { return key } } if (fork.excludedValue || fork.excludedValues) { - const excludedValues = toPath(fork.excludedValue - ? fork.excludedValue - : fork.excludedValues) + const excludedValues = toPath( + fork.excludedValue ? fork.excludedValue : fork.excludedValues + ) - if (!excludedValues.some(v => sessionData.indexOf(v) >= 0)) { + if (!excludedValues.some((v) => sessionData.indexOf(v) >= 0)) { return key } } @@ -58,16 +58,14 @@ const getPathWithSearchParams = (originalUrl, path) => { // Add any path params to params on original URL const originalParams = getSearchParams(originalUrl) const pathParams = getSearchParams(path) - for (let [key, value] of originalParams.entries()) { - pathParams.append(key, value); + for (const [key, value] of originalParams.entries()) { + pathParams.append(key, value) } // Remove query string from path path = path.split('?')[0] - return pathParams.size - ? `${path}?${pathParams.toString()}` - : path + return pathParams.size ? `${path}?${pathParams.toString()}` : path } /** @@ -77,7 +75,7 @@ const getPathWithSearchParams = (originalUrl, path) => { */ const getSearchParams = (originalUrl) => { const queryString = originalUrl.split('?')[1] - const searchParams = new URLSearchParams(queryString); + const searchParams = new URLSearchParams(queryString) return searchParams } diff --git a/test/utils.js b/test/utils.js index cbaf99e..82eee9c 100644 --- a/test/utils.js +++ b/test/utils.js @@ -24,7 +24,7 @@ describe('Utility functions', () => { await t.test('and redirects with shorthand', () => { const forks = { - '/country': req.session.data.country == 'England' + '/country': req.session.data.country === 'England' } assert.equal(utils.getFork(forks, req), '/country') @@ -32,7 +32,7 @@ describe('Utility functions', () => { await t.test('and redirects if function returns `true`', () => { const forks = { - '/country': () => req.session.data.country == 'England' + '/country': () => req.session.data.country === 'England' } assert.equal(utils.getFork(forks, req), '/country') diff --git a/test/wizard.js b/test/wizard.js index 65f7c13..79d2cb3 100644 --- a/test/wizard.js +++ b/test/wizard.js @@ -61,7 +61,7 @@ describe('GOV.UK Prototype Wizard', () => { 'forked-to': '/email', 'forked-from': '/do-you-have-a-national-insurance-number' } - }, + } } assert.deepEqual(wizard(journey, req), { @@ -78,7 +78,7 @@ describe('GOV.UK Prototype Wizard', () => { data: { 'forked-from': '/do-you-have-a-national-insurance-number', 'forked-to': '/email' - }, + } }, originalUrl: '/do-you-have-a-national-insurance-number', path: '/do-you-have-a-national-insurance-number'