From 693d49acb94b12fcf8352e921683f5c1c801cc53 Mon Sep 17 00:00:00 2001 From: gelocraft Date: Sun, 30 Nov 2025 05:27:40 +0000 Subject: [PATCH 1/4] chore(eslint): remove inline disables --- src/components/SettlementButton/index.tsx | 1 - src/hooks/useCardFeeds.tsx | 1 - src/hooks/useDuplicateTransactionsAndViolations.ts | 2 -- src/libs/CardFeedUtils.ts | 2 -- src/libs/CategoryOptionListUtils.ts | 1 - 5 files changed, 7 deletions(-) diff --git a/src/components/SettlementButton/index.tsx b/src/components/SettlementButton/index.tsx index a912824d9a9c..24f053023d72 100644 --- a/src/components/SettlementButton/index.tsx +++ b/src/components/SettlementButton/index.tsx @@ -299,7 +299,6 @@ function SettlementButton({ } if ((hasMultiplePolicies || hasSinglePolicy) && canUseWallet && !isPersonalOnlyOption) { - // eslint-disable-next-line unicorn/no-array-for-each activeAdminPolicies.forEach((activePolicy) => { const policyName = activePolicy.name; buttonOptions.push({ diff --git a/src/hooks/useCardFeeds.tsx b/src/hooks/useCardFeeds.tsx index 46aa02c29e87..85802db80858 100644 --- a/src/hooks/useCardFeeds.tsx +++ b/src/hooks/useCardFeeds.tsx @@ -49,7 +49,6 @@ const useCardFeeds = (policyID: string | undefined): [CombinedCardFeeds | undefi return acc; } - // eslint-disable-next-line unicorn/no-array-for-each Object.entries(feed.settings.companyCards).forEach(([key, feedSettings]) => { const feedName = key as CompanyCardFeed; const feedOAuthAccountDetails = feed.settings.oAuthAccountDetails?.[feedName]; diff --git a/src/hooks/useDuplicateTransactionsAndViolations.ts b/src/hooks/useDuplicateTransactionsAndViolations.ts index db49787a1a69..8fa3ca82775c 100644 --- a/src/hooks/useDuplicateTransactionsAndViolations.ts +++ b/src/hooks/useDuplicateTransactionsAndViolations.ts @@ -32,7 +32,6 @@ function selectViolationsWithDuplicates(transactionIDs: string[], allTransaction transactionViolations .filter((violations) => violations.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION) .flatMap((violations) => violations?.data?.duplicates ?? []) - // eslint-disable-next-line unicorn/no-array-for-each .forEach((duplicateID) => { if (!duplicateID) { return; @@ -85,7 +84,6 @@ function selectTransactionsWithDuplicates( transactionViolations .filter((violations) => violations.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION) .flatMap((violations) => violations?.data?.duplicates ?? []) - // eslint-disable-next-line unicorn/no-array-for-each .forEach((duplicateID) => { if (!duplicateID) { return; diff --git a/src/libs/CardFeedUtils.ts b/src/libs/CardFeedUtils.ts index 4505e81c1834..6c9d28170a7e 100644 --- a/src/libs/CardFeedUtils.ts +++ b/src/libs/CardFeedUtils.ts @@ -424,7 +424,6 @@ function getCardFeedsForDisplay(allCardFeeds: OnyxCollection, allCard continue; } - // eslint-disable-next-line unicorn/no-array-for-each Object.keys(getOriginalCompanyFeeds(cardFeeds)).forEach((key) => { const feed = key as CompanyCardFeed; const id = `${fundID}_${feed}`; @@ -479,7 +478,6 @@ function getCardFeedsForDisplayPerPolicy(allCardFeeds: OnyxCollection continue; } - // eslint-disable-next-line unicorn/no-array-for-each Object.entries(getOriginalCompanyFeeds(cardFeeds)).forEach(([key, feedData]) => { const preferredPolicy = 'preferredPolicy' in feedData ? (feedData.preferredPolicy ?? '') : ''; const feed = key as CompanyCardFeed; diff --git a/src/libs/CategoryOptionListUtils.ts b/src/libs/CategoryOptionListUtils.ts index 012d81e22eb7..001930a7cba2 100644 --- a/src/libs/CategoryOptionListUtils.ts +++ b/src/libs/CategoryOptionListUtils.ts @@ -55,7 +55,6 @@ function getCategoryOptionTree(options: Record | Category[], i continue; } - // eslint-disable-next-line unicorn/no-array-for-each option.name.split(CONST.PARENT_CHILD_SEPARATOR).forEach((optionName, index, array) => { const indents = times(index, () => CONST.INDENTS).join(''); const isChild = array.length - 1 === index; From 451366367e770eed3f8f6ab8278ca0f5c809b6a2 Mon Sep 17 00:00:00 2001 From: gelocraft Date: Sun, 30 Nov 2025 06:09:33 +0000 Subject: [PATCH 2/4] fix(eslint): auto-fix unicorn/no-array-for-each rule violations --- src/components/SettlementButton/index.tsx | 1 + src/hooks/useCardFeeds.tsx | 6 ++--- .../useDuplicateTransactionsAndViolations.ts | 24 +++++++++---------- src/libs/CardFeedUtils.ts | 10 ++++---- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/components/SettlementButton/index.tsx b/src/components/SettlementButton/index.tsx index 24f053023d72..a912824d9a9c 100644 --- a/src/components/SettlementButton/index.tsx +++ b/src/components/SettlementButton/index.tsx @@ -299,6 +299,7 @@ function SettlementButton({ } if ((hasMultiplePolicies || hasSinglePolicy) && canUseWallet && !isPersonalOnlyOption) { + // eslint-disable-next-line unicorn/no-array-for-each activeAdminPolicies.forEach((activePolicy) => { const policyName = activePolicy.name; buttonOptions.push({ diff --git a/src/hooks/useCardFeeds.tsx b/src/hooks/useCardFeeds.tsx index 85802db80858..52e52bb79279 100644 --- a/src/hooks/useCardFeeds.tsx +++ b/src/hooks/useCardFeeds.tsx @@ -49,7 +49,7 @@ const useCardFeeds = (policyID: string | undefined): [CombinedCardFeeds | undefi return acc; } - Object.entries(feed.settings.companyCards).forEach(([key, feedSettings]) => { + for (const [key, feedSettings] of Object.entries(feed.settings.companyCards)) { const feedName = key as CompanyCardFeed; const feedOAuthAccountDetails = feed.settings.oAuthAccountDetails?.[feedName]; const feedCompanyCardNickname = feed.settings.companyCardNicknames?.[feedName]; @@ -57,7 +57,7 @@ const useCardFeeds = (policyID: string | undefined): [CombinedCardFeeds | undefi const shouldAddFeed = domainID && (feedSettings.preferredPolicy ? feedSettings.preferredPolicy === policyID : domainID === workspaceAccountID.toString()); if (!shouldAddFeed) { - return; + continue; } const combinedFeedKey = getCompanyCardFeedWithDomainID(feedName, domainID); @@ -69,7 +69,7 @@ const useCardFeeds = (policyID: string | undefined): [CombinedCardFeeds | undefi domainID: Number(domainID), feed: feedName, }; - }); + } return acc; }, result); diff --git a/src/hooks/useDuplicateTransactionsAndViolations.ts b/src/hooks/useDuplicateTransactionsAndViolations.ts index 8fa3ca82775c..8a51545b078a 100644 --- a/src/hooks/useDuplicateTransactionsAndViolations.ts +++ b/src/hooks/useDuplicateTransactionsAndViolations.ts @@ -32,6 +32,7 @@ function selectViolationsWithDuplicates(transactionIDs: string[], allTransaction transactionViolations .filter((violations) => violations.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION) .flatMap((violations) => violations?.data?.duplicates ?? []) + // eslint-disable-next-line unicorn/no-array-for-each .forEach((duplicateID) => { if (!duplicateID) { return; @@ -81,21 +82,20 @@ function selectTransactionsWithDuplicates( continue; } - transactionViolations + for (const duplicateID of transactionViolations .filter((violations) => violations.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION) - .flatMap((violations) => violations?.data?.duplicates ?? []) - .forEach((duplicateID) => { - if (!duplicateID) { - return; - } + .flatMap((violations) => violations?.data?.duplicates ?? [])) { + if (!duplicateID) { + continue; + } - const duplicateKey = `${ONYXKEYS.COLLECTION.TRANSACTION}${duplicateID}`; - const duplicateTransaction = allTransactions[duplicateKey]; + const duplicateKey = `${ONYXKEYS.COLLECTION.TRANSACTION}${duplicateID}`; + const duplicateTransaction = allTransactions[duplicateKey]; - if (duplicateTransaction) { - result[duplicateKey] = duplicateTransaction; - } - }); + if (duplicateTransaction) { + result[duplicateKey] = duplicateTransaction; + } + } } return result; } diff --git a/src/libs/CardFeedUtils.ts b/src/libs/CardFeedUtils.ts index 6c9d28170a7e..dbbd5855aaeb 100644 --- a/src/libs/CardFeedUtils.ts +++ b/src/libs/CardFeedUtils.ts @@ -424,12 +424,12 @@ function getCardFeedsForDisplay(allCardFeeds: OnyxCollection, allCard continue; } - Object.keys(getOriginalCompanyFeeds(cardFeeds)).forEach((key) => { + for (const key of Object.keys(getOriginalCompanyFeeds(cardFeeds))) { const feed = key as CompanyCardFeed; const id = `${fundID}_${feed}`; if (cardFeedsForDisplay[id]) { - return; + continue; } cardFeedsForDisplay[id] = { @@ -438,7 +438,7 @@ function getCardFeedsForDisplay(allCardFeeds: OnyxCollection, allCard fundID, name: getCustomOrFormattedFeedName(feed, cardFeeds?.settings?.companyCardNicknames?.[feed], false) ?? feed, }; - }); + } } for (const card of Object.values(allCards)) { @@ -478,7 +478,7 @@ function getCardFeedsForDisplayPerPolicy(allCardFeeds: OnyxCollection continue; } - Object.entries(getOriginalCompanyFeeds(cardFeeds)).forEach(([key, feedData]) => { + for (const [key, feedData] of Object.entries(getOriginalCompanyFeeds(cardFeeds))) { const preferredPolicy = 'preferredPolicy' in feedData ? (feedData.preferredPolicy ?? '') : ''; const feed = key as CompanyCardFeed; const id = `${fundID}_${feed}`; @@ -489,7 +489,7 @@ function getCardFeedsForDisplayPerPolicy(allCardFeeds: OnyxCollection fundID, name: getCustomOrFormattedFeedName(feed, cardFeeds?.settings?.companyCardNicknames?.[feed], false) ?? feed, }); - }); + } } return cardFeedsForDisplayPerPolicy; From e8b3b1823fa7e84c3f0cbe0592752b1d7bd73c78 Mon Sep 17 00:00:00 2001 From: gelocraft Date: Sun, 30 Nov 2025 06:21:01 +0000 Subject: [PATCH 3/4] fix(eslint): manually fix unicorn/no-array-for-each rule violation --- src/libs/CategoryOptionListUtils.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/CategoryOptionListUtils.ts b/src/libs/CategoryOptionListUtils.ts index 001930a7cba2..5c92b0cbd72f 100644 --- a/src/libs/CategoryOptionListUtils.ts +++ b/src/libs/CategoryOptionListUtils.ts @@ -55,7 +55,9 @@ function getCategoryOptionTree(options: Record | Category[], i continue; } - option.name.split(CONST.PARENT_CHILD_SEPARATOR).forEach((optionName, index, array) => { + const array = option.name.split(CONST.PARENT_CHILD_SEPARATOR); + + for (const [index, optionName] of array.entries()) { const indents = times(index, () => CONST.INDENTS).join(''); const isChild = array.length - 1 === index; const searchText = array.slice(0, index + 1).join(CONST.PARENT_CHILD_SEPARATOR); @@ -63,7 +65,7 @@ function getCategoryOptionTree(options: Record | Category[], i const isParentOptionDisabled = !selectedParentOption || !selectedParentOption.enabled || selectedParentOption.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; if (optionCollection.has(searchText)) { - return; + continue; } const decodedCategoryName = getDecodedCategoryName(optionName); @@ -76,7 +78,7 @@ function getCategoryOptionTree(options: Record | Category[], i isSelected: isChild ? !!option.isSelected : !!selectedParentOption, pendingAction: option.pendingAction, }); - }); + } } return Array.from(optionCollection.values()); From 40fa79dcb06341da7ecc1301ddfef3eda300c627 Mon Sep 17 00:00:00 2001 From: gelocraft Date: Thu, 4 Dec 2025 12:03:09 +0000 Subject: [PATCH 4/4] refactor: accept roryabraham code suggestion --- .../useDuplicateTransactionsAndViolations.ts | 20 +++++++++++-------- src/libs/CategoryOptionListUtils.ts | 7 ++++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/hooks/useDuplicateTransactionsAndViolations.ts b/src/hooks/useDuplicateTransactionsAndViolations.ts index 8a51545b078a..cc8fadaccd27 100644 --- a/src/hooks/useDuplicateTransactionsAndViolations.ts +++ b/src/hooks/useDuplicateTransactionsAndViolations.ts @@ -82,18 +82,22 @@ function selectTransactionsWithDuplicates( continue; } - for (const duplicateID of transactionViolations - .filter((violations) => violations.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION) - .flatMap((violations) => violations?.data?.duplicates ?? [])) { - if (!duplicateID) { + for (const violation of transactionViolations) { + if (violation.name !== CONST.VIOLATIONS.DUPLICATED_TRANSACTION) { continue; } - const duplicateKey = `${ONYXKEYS.COLLECTION.TRANSACTION}${duplicateID}`; - const duplicateTransaction = allTransactions[duplicateKey]; + for (const duplicateID of violation.data?.duplicates ?? []) { + if (!duplicateID) { + continue; + } - if (duplicateTransaction) { - result[duplicateKey] = duplicateTransaction; + const duplicateKey = `${ONYXKEYS.COLLECTION.TRANSACTION}${duplicateID}`; + const duplicateTransaction = allTransactions[duplicateKey]; + + if (duplicateTransaction) { + result[duplicateKey] = duplicateTransaction; + } } } } diff --git a/src/libs/CategoryOptionListUtils.ts b/src/libs/CategoryOptionListUtils.ts index 5c92b0cbd72f..ccf96d15dfd6 100644 --- a/src/libs/CategoryOptionListUtils.ts +++ b/src/libs/CategoryOptionListUtils.ts @@ -57,7 +57,12 @@ function getCategoryOptionTree(options: Record | Category[], i const array = option.name.split(CONST.PARENT_CHILD_SEPARATOR); - for (const [index, optionName] of array.entries()) { + for (let index = 0; index < array.length; index++) { + const optionName = array.at(index); + if (!optionName) { + continue; + } + const indents = times(index, () => CONST.INDENTS).join(''); const isChild = array.length - 1 === index; const searchText = array.slice(0, index + 1).join(CONST.PARENT_CHILD_SEPARATOR);