Skip to content

Commit 4942d1b

Browse files
Fix ESLint prefer-nullish-coalescing warnings
1 parent 0838872 commit 4942d1b

File tree

10 files changed

+19
-44
lines changed

10 files changed

+19
-44
lines changed

.changeset/serious-ducks-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@guardian/support-dotcom-components': patch
3+
---
4+
5+
prefer-nullish-coalescing lint rule violations fix

eslint-suppressions.json

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
"@typescript-eslint/restrict-template-expressions": {
1818
"count": 1
1919
},
20-
"@typescript-eslint/prefer-nullish-coalescing": {
21-
"count": 2
22-
},
2320
"@typescript-eslint/no-unsafe-assignment": {
2421
"count": 3
2522
},
@@ -74,16 +71,6 @@
7471
"count": 1
7572
}
7673
},
77-
"src/server/lib/targeting.ts": {
78-
"@typescript-eslint/prefer-nullish-coalescing": {
79-
"count": 1
80-
}
81-
},
82-
"src/server/lib/tracking.ts": {
83-
"@typescript-eslint/prefer-nullish-coalescing": {
84-
"count": 1
85-
}
86-
},
8774
"src/server/middleware/errorHandling.ts": {
8875
"@typescript-eslint/no-unsafe-assignment": {
8976
"count": 1
@@ -102,9 +89,6 @@
10289
"src/server/selection/ab.ts": {
10390
"@typescript-eslint/no-unnecessary-condition": {
10491
"count": 1
105-
},
106-
"@typescript-eslint/prefer-nullish-coalescing": {
107-
"count": 1
10892
}
10993
},
11094
"src/server/selection/epsilonGreedySelection.ts": {
@@ -144,24 +128,13 @@
144128
}
145129
},
146130
"src/server/tests/epics/epicSelection.ts": {
147-
"@typescript-eslint/prefer-nullish-coalescing": {
148-
"count": 4
149-
},
150131
"@typescript-eslint/no-unnecessary-condition": {
151132
"count": 1
152133
}
153134
},
154-
"src/server/tests/gutters/gutterSelection.ts": {
155-
"@typescript-eslint/prefer-nullish-coalescing": {
156-
"count": 2
157-
}
158-
},
159135
"src/server/tests/headers/headerSelection.ts": {
160136
"@typescript-eslint/no-unnecessary-condition": {
161137
"count": 2
162-
},
163-
"@typescript-eslint/prefer-nullish-coalescing": {
164-
"count": 2
165138
}
166139
},
167140
"src/server/utils/logging.ts": {
@@ -197,9 +170,6 @@
197170
}
198171
},
199172
"src/shared/lib/geolocation.ts": {
200-
"@typescript-eslint/prefer-nullish-coalescing": {
201-
"count": 1
202-
},
203173
"@typescript-eslint/no-unnecessary-condition": {
204174
"count": 1
205175
}

src/server/api/epicRouter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const buildEpicRouter = (
9696
return {};
9797
}
9898

99-
const targetingMvtId = targeting.mvtId || 1;
99+
const targetingMvtId = targeting.mvtId ?? 1;
100100

101101
const tests =
102102
type === 'ARTICLE'
@@ -166,7 +166,7 @@ export const buildEpicRouter = (
166166
abTestName: test.name,
167167
abTestVariant: variant.name,
168168
campaignCode: buildEpicCampaignCode(test, variant),
169-
campaignId: `epic_${test.campaignId || test.name}`,
169+
campaignId: `epic_${test.campaignId ?? test.name}`,
170170
componentType: 'ACQUISITIONS_EPIC',
171171
products: ['CONTRIBUTION', 'MEMBERSHIP_SUPPORTER'],
172172
labels: test.isSuperMode ? ['SUPER_MODE'] : undefined,

src/server/lib/targeting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const shouldThrottle = (
5757
};
5858

5959
export const shouldNotRenderEpic = (meta: EpicTargeting): boolean => {
60-
const section = meta.sectionId || meta.sectionName;
60+
const section = meta.sectionId ?? meta.sectionName;
6161
const isLowValueSection = !!section && lowValueSections.includes(section);
6262
const isLowValueTag = lowValueTags.some((id) => meta.tags.some((pageTag) => pageTag.id === id));
6363

src/server/lib/tracking.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
const campaignPrefix = 'gdnwb_copts_memco';
1111

1212
export const buildEpicCampaignCode = (test: EpicTest, variant: EpicVariant): string =>
13-
`${campaignPrefix}_${test.campaignId || test.name}_${variant.name}`;
13+
`${campaignPrefix}_${test.campaignId ?? test.name}_${variant.name}`;
1414

1515
export const buildBannerCampaignCode = (test: BannerTest, variant: BannerVariant): string =>
1616
`${test.name}_${variant.name}`;

src/server/selection/ab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const selectAmountsTestVariant = (
112112

113113
// Test is running and user has been successfully assigned to a control/variant
114114
return {
115-
testName: liveTestName || `${testName}_AB_TEST`,
115+
testName: liveTestName ?? `${testName}_AB_TEST`,
116116
...variant,
117117
};
118118
};

src/server/tests/epics/epicSelection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const withinMaxViews = (log: EpicViewLog, now: Date = new Date()): Filter
109109

110110
const testId = test.useLocalViewLog ? test.name : undefined;
111111

112-
return !shouldThrottle(log, test.maxViews || defaultMaxViews, testId, now);
112+
return !shouldThrottle(log, test.maxViews ?? defaultMaxViews, testId, now);
113113
},
114114
});
115115

@@ -203,9 +203,9 @@ export const findTestAndVariant = (
203203
hasCountryCode,
204204
isCountryTargetedForEpic,
205205
// For the super mode pass, we treat all tests as "always ask" so disable this filter
206-
...(isSuperModePass ? [] : [withinMaxViews(targeting.epicViewLog || [])]),
206+
...(isSuperModePass ? [] : [withinMaxViews(targeting.epicViewLog ?? [])]),
207207
respectArticleCountOptOut,
208-
withinArticleViewedSettings(targeting.weeklyArticleHistory || []),
208+
withinArticleViewedSettings(targeting.weeklyArticleHistory ?? []),
209209
deviceTypeMatchesFilter(userDeviceType),
210210
correctSignedInStatusFilter,
211211
momentumMatches,
@@ -278,7 +278,7 @@ function selectEpicVariant(
278278
banditData: BanditData[],
279279
targeting: EpicTargeting,
280280
): Result {
281-
const result = selectVariant<EpicVariant, EpicTest>(test, targeting.mvtId || 1, banditData);
281+
const result = selectVariant<EpicVariant, EpicTest>(test, targeting.mvtId ?? 1, banditData);
282282
return {
283283
result,
284284
};

src/server/tests/gutters/gutterSelection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const selectBestTest = (
6565
return {
6666
test: selectedTest,
6767
variant: selectedVariant,
68-
moduleName: selectedVariant.moduleName || moduleName,
68+
moduleName: selectedVariant.moduleName ?? moduleName,
6969
};
7070
};
7171

@@ -84,7 +84,7 @@ const getForcedVariant = (
8484
return {
8585
test,
8686
variant,
87-
moduleName: variant.moduleName || moduleName,
87+
moduleName: variant.moduleName ?? moduleName,
8888
};
8989
}
9090
return null;

src/server/tests/headers/headerSelection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ export const selectBestTest = (
379379
return {
380380
test: selectedTest,
381381
variant: selectedVariant,
382-
moduleName: selectedVariant.moduleName || moduleName,
382+
moduleName: selectedVariant.moduleName ?? moduleName,
383383
};
384384
};
385385

@@ -398,7 +398,7 @@ const getForcedVariant = (
398398
return {
399399
test,
400400
variant,
401-
moduleName: variant.moduleName || moduleName,
401+
moduleName: variant.moduleName ?? moduleName,
402402
};
403403
}
404404
return null;

src/shared/lib/geolocation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ export const countryCodeToCountryGroupId = (countryCode?: string): CountryGroupI
576576
const foundCountryGroupId = availableCountryGroupIds.find((countryGroupId) =>
577577
countryGroups[countryGroupId].countries.includes(countryCode ?? ''),
578578
);
579-
return foundCountryGroupId || 'International';
579+
return foundCountryGroupId ?? 'International';
580580
};
581581

582582
export const inTargetedCountry = (

0 commit comments

Comments
 (0)