Skip to content

Commit d1b6f6d

Browse files
authored
Merge pull request Expensify#76358 from gelocraft/fix-no-array-for-each-1764558980
fix(eslint): fix unicorn/no-array-for-each rule violations
2 parents 8eaf7a2 + 99225a4 commit d1b6f6d

File tree

5 files changed

+41
-39
lines changed

5 files changed

+41
-39
lines changed

src/pages/ReimbursementAccount/NonUSD/utils/getInputKeysForBankInfoStep.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import type {CorpayFields} from '@src/types/onyx';
33

44
function getInputKeysForBankInfoStep(corpayFields: CorpayFields | undefined): Record<string, keyof ReimbursementAccountForm> {
55
const keys: Record<string, keyof ReimbursementAccountForm> = {};
6-
// eslint-disable-next-line unicorn/no-array-for-each
7-
corpayFields?.formFields?.forEach((field) => {
8-
keys[field.id] = field.id as keyof ReimbursementAccountForm;
9-
});
6+
if (corpayFields?.formFields) {
7+
for (const field of corpayFields.formFields) {
8+
keys[field.id] = field.id as keyof ReimbursementAccountForm;
9+
}
10+
}
1011
return keys;
1112
}
1213

src/pages/ReimbursementAccount/NonUSD/utils/getSignerDetailsAndSignerFilesForSignerInfo.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {OnyxEntry} from 'react-native-onyx';
22
import CONST from '@src/CONST';
33
import type {ReimbursementAccountForm} from '@src/types/form';
4-
import type {BeneficialOwnerDataKey, SignerInfoStepProps} from '@src/types/form/ReimbursementAccountForm';
4+
import type {BeneficialOwnerDataKey} from '@src/types/form/ReimbursementAccountForm';
55
import type {FileObject} from '@src/types/utils/Attachment';
66
import SafeString from '@src/utils/SafeString';
77

@@ -26,26 +26,25 @@ function getSignerDetailsAndSignerFilesForSignerInfo(reimbursementAccountDraft:
2626
const signerDetails: Record<string, string | boolean | FileObject[]> = {};
2727
const signerFiles: Record<string, string | FileObject | boolean> = {};
2828

29-
// eslint-disable-next-line unicorn/no-array-for-each
30-
signerDetailsFields.forEach((fieldName: keyof SignerInfoStepProps) => {
29+
for (const fieldName of signerDetailsFields) {
3130
if (fieldName === EMAIL) {
3231
signerDetails[fieldName] = signerEmail;
33-
return;
32+
continue;
3433
}
3534

3635
if (!reimbursementAccountDraft?.[fieldName]) {
37-
return;
36+
continue;
3837
}
3938

4039
if (fieldName === STREET || fieldName === CITY || fieldName === STATE || fieldName === ZIP_CODE) {
4140
signerDetails[ADDRESS] = signerDetails[ADDRESS]
4241
? `${SafeString(signerDetails[ADDRESS])}, ${SafeString(reimbursementAccountDraft?.[fieldName])}`
4342
: reimbursementAccountDraft?.[fieldName];
44-
return;
43+
continue;
4544
}
4645

4746
signerDetails[fieldName] = reimbursementAccountDraft?.[fieldName];
48-
});
47+
}
4948

5049
if (isUserBeneficialOwner) {
5150
signerDetails[FULL_NAME] = '';

src/pages/ScheduleCall/ScheduleCallPage.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,33 @@ function ScheduleCallPage() {
9494

9595
const allTimeSlots = guides.reduce((allSlots, guideAccountID) => {
9696
const guideSchedule = calendlySchedule?.data?.[guideAccountID];
97-
// eslint-disable-next-line unicorn/no-array-for-each
98-
guideSchedule?.timeSlots.forEach((timeSlot) => {
99-
allSlots.push({
100-
guideAccountID: Number(guideAccountID),
101-
guideEmail: guideSchedule.guideEmail,
102-
startTime: timeSlot.startTime,
103-
scheduleURL: timeSlot.schedulingURL,
104-
});
105-
});
97+
if (guideSchedule) {
98+
for (const timeSlot of guideSchedule.timeSlots) {
99+
allSlots.push({
100+
guideAccountID: Number(guideAccountID),
101+
guideEmail: guideSchedule.guideEmail,
102+
startTime: timeSlot.startTime,
103+
scheduleURL: timeSlot.schedulingURL,
104+
});
105+
}
106+
}
106107
return allSlots;
107108
}, [] as TimeSlot[]);
108109

109110
// Group time slots by date to render per day slots on calendar
110111
const timeSlotMap: Record<string, TimeSlot[]> = {};
111-
// eslint-disable-next-line unicorn/no-array-for-each
112-
allTimeSlots.forEach((timeSlot) => {
112+
for (const timeSlot of allTimeSlots) {
113113
const timeSlotDate = DateUtils.formatInTimeZoneWithFallback(new Date(timeSlot?.startTime), userTimezone, CONST.DATE.FNS_FORMAT_STRING);
114114
if (!timeSlotMap[timeSlotDate]) {
115115
timeSlotMap[timeSlotDate] = [];
116116
}
117117
timeSlotMap[timeSlotDate].push(timeSlot);
118-
});
118+
}
119119

120120
// Sort time slots within each date array to have in chronological order
121-
// eslint-disable-next-line unicorn/no-array-for-each
122-
Object.values(timeSlotMap).forEach((slots) => {
121+
for (const slots of Object.values(timeSlotMap)) {
123122
slots.sort((a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime());
124-
});
123+
}
125124

126125
return timeSlotMap;
127126
}, [calendlySchedule?.data, userTimezone]);

src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersCategoryPage.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ function SearchFiltersCategoryPage() {
5555
const uniqueCategoryNames = new Set<string>();
5656

5757
if (!selectedPoliciesCategories || selectedPoliciesCategories.length === 0) {
58-
// eslint-disable-next-line unicorn/no-array-for-each
59-
Object.values(allPolicyCategories ?? {}).map((policyCategories) => Object.values(policyCategories ?? {}).forEach((category) => uniqueCategoryNames.add(category.name)));
58+
const categories = Object.values(allPolicyCategories ?? {}).flatMap((policyCategories) => Object.values(policyCategories ?? {}));
59+
for (const category of categories) {
60+
uniqueCategoryNames.add(category.name);
61+
}
6062
} else {
61-
// eslint-disable-next-line unicorn/no-array-for-each
62-
selectedPoliciesCategories.forEach((category) => uniqueCategoryNames.add(category.name));
63+
for (const category of selectedPoliciesCategories) {
64+
uniqueCategoryNames.add(category.name);
65+
}
6366
}
6467
items.push(
6568
...Array.from(uniqueCategoryNames)

src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTaxRatePage.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ function SearchFiltersTaxRatePage() {
2222
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
2323
const allTaxRates = getAllTaxRates(policies);
2424
const selectedTaxesItems: SearchMultipleSelectionPickerItem[] = [];
25-
// eslint-disable-next-line unicorn/no-array-for-each
26-
Object.entries(allTaxRates).forEach(([taxRateName, taxRateKeys]) => {
27-
// eslint-disable-next-line unicorn/no-array-for-each
28-
searchAdvancedFiltersForm?.taxRate?.forEach((taxRateKey) => {
29-
if (!taxRateKeys.includes(taxRateKey) || selectedTaxesItems.some((item) => item.name === taxRateName)) {
30-
return;
25+
for (const [taxRateName, taxRateKeys] of Object.entries(allTaxRates)) {
26+
if (searchAdvancedFiltersForm?.taxRate) {
27+
for (const taxRateKey of searchAdvancedFiltersForm.taxRate) {
28+
if (!taxRateKeys.includes(taxRateKey) || selectedTaxesItems.some((item) => item.name === taxRateName)) {
29+
continue;
30+
}
31+
selectedTaxesItems.push({name: taxRateName, value: taxRateKeys});
3132
}
32-
selectedTaxesItems.push({name: taxRateName, value: taxRateKeys});
33-
});
34-
});
33+
}
34+
}
3535
const policyIDs = useMemo(() => searchAdvancedFiltersForm?.policyID ?? [], [searchAdvancedFiltersForm?.policyID]);
3636

3737
const selectedPoliciesMap = useMemo(() => {

0 commit comments

Comments
 (0)