Skip to content

Commit 19032f5

Browse files
no-unnecessary-condition lint rule violations fixed
1 parent 1e9ace3 commit 19032f5

File tree

12 files changed

+20
-95
lines changed

12 files changed

+20
-95
lines changed

eslint-suppressions.json

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
{
2-
"src/server/api/bannerRouter.ts": {
3-
"@typescript-eslint/no-unnecessary-condition": {
4-
"count": 1
5-
}
6-
},
72
"src/server/middleware/errorHandling.ts": {
83
"@typescript-eslint/no-unsafe-assignment": {
94
"count": 1
@@ -14,59 +9,9 @@
149
"count": 8
1510
}
1611
},
17-
"src/server/selection/ab.ts": {
18-
"@typescript-eslint/no-unnecessary-condition": {
19-
"count": 1
20-
}
21-
},
22-
"src/server/selection/epsilonGreedySelection.ts": {
23-
"@typescript-eslint/no-unnecessary-condition": {
24-
"count": 1
25-
}
26-
},
27-
"src/server/selection/helpers.ts": {
28-
"@typescript-eslint/no-unnecessary-condition": {
29-
"count": 1
30-
}
31-
},
32-
"src/server/selection/selectVariant.ts": {
33-
"@typescript-eslint/no-unnecessary-condition": {
34-
"count": 1
35-
}
36-
},
37-
"src/server/tests/banners/bannerSelection.ts": {
38-
"@typescript-eslint/no-unnecessary-condition": {
39-
"count": 3
40-
}
41-
},
42-
"src/server/tests/epics/epicSelection.ts": {
43-
"@typescript-eslint/no-unnecessary-condition": {
44-
"count": 1
45-
}
46-
},
47-
"src/server/tests/headers/headerSelection.ts": {
48-
"@typescript-eslint/no-unnecessary-condition": {
49-
"count": 2
50-
}
51-
},
5212
"src/server/utils/valueReloader.ts": {
5313
"@typescript-eslint/no-floating-promises": {
5414
"count": 1
5515
}
56-
},
57-
"src/shared/lib/geolocation.ts": {
58-
"@typescript-eslint/no-unnecessary-condition": {
59-
"count": 1
60-
}
61-
},
62-
"src/shared/lib/placeholders.ts": {
63-
"@typescript-eslint/no-unnecessary-condition": {
64-
"count": 2
65-
}
66-
},
67-
"src/shared/types/abTests/banner.ts": {
68-
"@typescript-eslint/no-unnecessary-condition": {
69-
"count": 1
70-
}
7116
}
7217
}

src/server/api/bannerRouter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const buildBannerRouter = (
104104
const design = getDesignForVariant(variant, bannerDesigns.get());
105105

106106
const contributionAmounts = choiceCardAmounts.get();
107-
const requiredCountry = targeting.countryCode ?? 'GB';
107+
const requiredCountry = targeting.countryCode || 'GB';
108108
const requiredRegion = countryCodeToCountryGroupId(requiredCountry);
109109
const targetingMvtId = targeting.mvtId || 1;
110110
const variantAmounts = selectAmountsTestVariant(

src/server/selection/ab.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ export const selectAmountsTestVariant = (
106106
const assignmentIndex = getRandomNumber(`${seed + mvtId}`) % variants.length;
107107
const variant = variants[assignmentIndex];
108108

109-
if (!variant) {
110-
return undefined;
111-
}
112-
113109
// Test is running and user has been successfully assigned to a control/variant
114110
return {
115111
testName: liveTestName ?? `${testName}_AB_TEST`,

src/server/selection/epsilonGreedySelection.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ export function selectVariantWithHighestMean<V extends Variant, T extends Test<V
2929
? sortedVariants[0]
3030
: sortedVariants[Math.floor(Math.random() * bestVariants)]; // more than 1
3131

32-
if (!variant) {
33-
return undefined;
34-
}
35-
3632
return test.variants.find((v) => v.name === variant.variantName);
3733
}
3834

src/server/selection/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { BanditVariantData } from './banditData';
66

77
export function selectRandomVariant<V extends Variant, T extends Test<V>>(test: T): V | undefined {
88
const randomVariantIndex = Math.floor(Math.random() * test.variants.length);
9-
const randomVariantData = test.variants[randomVariantIndex];
9+
const randomVariantData = test.variants.length && test.variants[randomVariantIndex];
1010

1111
if (!randomVariantData) {
1212
logError(`Failed to select random variant for bandit test: ${test.name}`);

src/server/selection/selectVariant.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,10 @@ export const selectVariant = <V extends Variant, T extends Test<V>>(
6767
} else {
6868
// No configured methodology, default to AB test
6969
const variant = selectVariantUsingMVT<V, T>(test, mvtId);
70-
if (variant) {
71-
return {
72-
test,
73-
variant,
74-
};
75-
}
70+
return {
71+
test,
72+
variant,
73+
};
7674
}
7775
return;
7876
};

src/server/tests/banners/bannerSelection.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ const purchaseMatches = (
179179
}
180180

181181
const { product, userType } = purchaseInfo;
182-
const productValid = product && testPurchaseInfo?.product.includes(product);
183-
const userValid = userType && testPurchaseInfo?.userType.includes(userType);
182+
const productValid = testPurchaseInfo?.product.includes(product);
183+
const userValid = testPurchaseInfo?.userType.includes(userType);
184184

185185
return productValid && userValid;
186186
};
@@ -245,15 +245,7 @@ export const selectBannerTest = (
245245
purchaseMatches(test, targeting.purchaseInfo, targeting.isSignedIn) &&
246246
canShowBannerAgain(targeting, test, bannerDeployTimes, now, deploySchedule) &&
247247
correctSignedInStatus(targeting.isSignedIn, test.signedInStatus) &&
248-
pageContextMatches(
249-
targeting,
250-
test.contextTargeting ?? {
251-
tagIds: [],
252-
sectionIds: [],
253-
excludedTagIds: [],
254-
excludedSectionIds: [],
255-
},
256-
) &&
248+
pageContextMatches(targeting, test.contextTargeting) &&
257249
consentStatusMatches(targeting.hasConsented, test.consentStatus) &&
258250
abandonedBasketMatches(test.bannerChannel, targeting.abandonedBasket) &&
259251
matchesFrontsOnlyRequirement(test, targeting)

src/server/tests/epics/epicSelection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export const deviceTypeMatchesFilter = (userDeviceType: UserDeviceType): Filter
170170

171171
type FilterResults = Record<string, boolean>;
172172

173-
export type Debug = Record<string, FilterResults>;
173+
export type Debug = Record<string, FilterResults | undefined>;
174174

175175
export interface Result {
176176
result?: {
@@ -216,9 +216,9 @@ export const findTestAndVariant = (
216216
const test = tests.find((test) =>
217217
filters.every((filter) => {
218218
const got = filter.test(test, targeting);
219-
220-
if (debug[test.name]) {
221-
debug[test.name][filter.id] = got;
219+
const debugResults = debug[test.name];
220+
if (debugResults) {
221+
debugResults[filter.id] = got;
222222
} else {
223223
debug[test.name] = { [filter.id]: got };
224224
}

src/server/tests/headers/headerSelection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ const purchaseMatches = (
325325
}
326326

327327
const { product, userType } = purchaseInfo;
328-
const productValid = product && testPurchaseInfo?.product.includes(product);
329-
const userValid = userType && testPurchaseInfo?.userType.includes(userType);
328+
const productValid = testPurchaseInfo?.product.includes(product);
329+
const userValid = testPurchaseInfo?.userType.includes(userType);
330330

331331
return productValid && userValid;
332332
};

src/shared/lib/geolocation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ export const isGWCheckoutUrl = (baseUrl: string): boolean =>
634634
export const addRegionIdToSupportUrl = (originalUrl: string, countryCode?: string): string => {
635635
if (countryCode) {
636636
const supportRegionId = countryCodeToSupportRegionId(countryCode);
637-
if (supportRegionId && !isGWCheckoutUrl(originalUrl)) {
637+
if (!isGWCheckoutUrl(originalUrl)) {
638638
return originalUrl.replace(
639639
/(support\.theguardian\.com)\/(contribute-in-epic|contribute|subscribe|checkout)/,
640640
(_, domain, path) => `${domain}/${supportRegionId.toLowerCase()}/${path}`,

0 commit comments

Comments
 (0)