Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Update eslint-config-expensify to 2.0.49 #42650

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f707179
update package
kacper-mikolajczak May 27, 2024
71b2413
fix react-native-permissions
kacper-mikolajczak May 27, 2024
86e68f0
fix TransactionUtils
kacper-mikolajczak May 27, 2024
16f9639
fix DeferredOnyxUpdates
kacper-mikolajczak May 27, 2024
c83262d
fix OnyxUpdateManager
kacper-mikolajczak May 27, 2024
36ebdda
fix Report
kacper-mikolajczak May 28, 2024
41ef7c4
RenameCardIsVirtual
kacper-mikolajczak May 28, 2024
36b4b57
RenameReceiptFilename
kacper-mikolajczak May 28, 2024
8eb1b9a
fix getSubstepValues
kacper-mikolajczak May 28, 2024
25983d7
fix BeneficialOwnersStep
kacper-mikolajczak May 28, 2024
dbb6be5
fix WorkspaceMembersPage
kacper-mikolajczak May 28, 2024
d85c1db
fix TestHelper
kacper-mikolajczak May 28, 2024
5f14db7
fix Expensicons
kacper-mikolajczak May 28, 2024
ebea12b
fix IOU
kacper-mikolajczak May 28, 2024
20867f9
fix fix IOU
kacper-mikolajczak May 28, 2024
8a23877
fix OptionsListUtils
kacper-mikolajczak May 28, 2024
c917538
fix ErrorUtils
kacper-mikolajczak May 28, 2024
256ad54
fix useStepFormSubmit
kacper-mikolajczak May 28, 2024
afab89b
WIP fix getSubstepValues
kacper-mikolajczak May 28, 2024
4e2ff5e
WIP fix Policy
kacper-mikolajczak May 28, 2024
e46d13c
fix types getSubstepValues
kacper-mikolajczak May 29, 2024
7e4cc57
fix types PolicyCategory
kacper-mikolajczak May 29, 2024
2f11174
fix types Policy
kacper-mikolajczak May 29, 2024
7e53265
Merge branch 'main' into chore/eslint-config-expensify-2.0.49
kacper-mikolajczak May 29, 2024
06e0881
add missing import Policy
kacper-mikolajczak May 29, 2024
1d478a9
fix types Category
kacper-mikolajczak May 29, 2024
2e3240e
fix fix types Category
kacper-mikolajczak May 29, 2024
20b6fec
force CI
kacper-mikolajczak May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions __mocks__/react-native-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,30 @@ const requestNotifications: jest.Mock<Notification> = jest.fn((options: Record<s
status: RESULTS.GRANTED,
settings: Object.keys(options)
.filter((option: string) => notificationOptions.includes(option))
.reduce((acc: NotificationSettings, option: string) => ({...acc, [option]: true}), {
lockScreen: true,
notificationCenter: true,
}),
.reduce(
(acc: NotificationSettings, option: string) => {
acc[option] = true;
return acc;
},
{
lockScreen: true,
notificationCenter: true,
},
),
}));

const checkMultiple: jest.Mock<ResultsCollection> = jest.fn((permissions: string[]) =>
permissions.reduce(
(acc: ResultsCollection, permission: string) => ({
...acc,
[permission]: RESULTS.GRANTED,
}),
{},
),
permissions.reduce((acc: ResultsCollection, permission: string) => {
acc[permission] = RESULTS.GRANTED;
return acc;
}, {}),
);

const requestMultiple: jest.Mock<ResultsCollection> = jest.fn((permissions: string[]) =>
permissions.reduce(
(acc: ResultsCollection, permission: string) => ({
...acc,
[permission]: RESULTS.GRANTED,
}),
{},
),
permissions.reduce((acc: ResultsCollection, permission: string) => {
acc[permission] = RESULTS.GRANTED;
return acc;
}, {}),
);

export {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
"electron-builder": "24.13.2",
"eslint": "^7.6.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-expensify": "^2.0.47",
"eslint-config-expensify": "^2.0.49",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^24.1.0",
Expand Down
5 changes: 3 additions & 2 deletions src/components/Icon/__mocks__/Expensicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import type {SvgProps} from 'react-native-svg';

const Expensicons = jest.requireActual<Record<string, React.FC<SvgProps>>>('../Expensicons');

module.exports = Object.keys(Expensicons).reduce((prev, curr) => {
module.exports = Object.keys(Expensicons).reduce((acc: Record<string, () => void>, curr) => {
// We set the name of the anonymous mock function here so we can dynamically build the list of mocks and access the
// "name" property to use in accessibility hints for element querying
const fn = () => '';
Object.defineProperty(fn, 'name', {value: curr});
return {...prev, [curr]: fn};
acc[curr] = fn;
return acc;
}, {});
14 changes: 6 additions & 8 deletions src/hooks/useStepFormSubmit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {useCallback} from 'react';
import type {FormOnyxKeys, FormOnyxValues} from '@components/Form/types';
import * as FormActions from '@userActions/FormActions';
import type {OnyxFormKey, OnyxFormValuesMapping} from '@src/ONYXKEYS';
import type {OnyxFormKey, OnyxFormValuesMapping, OnyxValues} from '@src/ONYXKEYS';
import type {BaseForm} from '@src/types/form/Form';
import type {SubStepProps} from './useSubStep/types';

type UseStepFormSubmitParams<T extends keyof OnyxFormValuesMapping> = Pick<SubStepProps, 'onNext'> & {
Expand All @@ -22,13 +23,10 @@ export default function useStepFormSubmit<T extends keyof OnyxFormValuesMapping>
return useCallback(
(values: FormOnyxValues<T>) => {
if (shouldSaveDraft) {
const stepValues = fieldIds.reduce(
(acc, key) => ({
...acc,
[key]: values[key],
}),
{},
);
const stepValues = fieldIds.reduce((acc, key) => {
acc[key] = values[key];
return acc;
}, {} as Record<(typeof fieldIds)[number], OnyxValues[T][Exclude<keyof OnyxValues[T], keyof BaseForm>]>);

FormActions.setDraftValues(formId, stepValues);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ErrorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function getLatestErrorFieldForAnyField<TOnyxData extends OnyxDataWithErrorField

const fieldNames = Object.keys(errorFields);
const latestErrorFields = fieldNames.map((fieldName) => getLatestErrorField(onyxData, fieldName));
return latestErrorFields.reduce((acc, error) => ({...acc, ...error}), {});
return latestErrorFields.reduce((acc, error) => Object.assign(acc, error), {});
}

/**
Expand Down
19 changes: 14 additions & 5 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,13 @@ function getSearchText(
function getAllReportErrors(report: OnyxEntry<Report>, reportActions: OnyxEntry<ReportActions>): OnyxCommon.Errors {
const reportErrors = report?.errors ?? {};
const reportErrorFields = report?.errorFields ?? {};
const reportActionErrors: OnyxCommon.ErrorFields = Object.values(reportActions ?? {}).reduce(
(prevReportActionErrors, action) => (!action || isEmptyObject(action.errors) ? prevReportActionErrors : {...prevReportActionErrors, ...action.errors}),
{},
);
const reportActionErrors: OnyxCommon.ErrorFields = Object.values(reportActions ?? {}).reduce((prevReportActionErrors, action) => {
if (!action || isEmptyObject(action.errors)) {
return prevReportActionErrors;
}

return Object.assign(prevReportActionErrors, action.errors);
}, {});
const parentReportAction: OnyxEntry<ReportAction> =
!report?.parentReportID || !report?.parentReportActionID ? null : allReportActions?.[report.parentReportID ?? '']?.[report.parentReportActionID ?? ''] ?? null;

Expand All @@ -543,7 +546,13 @@ function getAllReportErrors(report: OnyxEntry<Report>, reportActions: OnyxEntry<
...reportActionErrors,
};
// Combine all error messages keyed by microtime into one object
const allReportErrors = Object.values(errorSources)?.reduce((prevReportErrors, errors) => (isEmptyObject(errors) ? prevReportErrors : {...prevReportErrors, ...errors}), {});
const allReportErrors = Object.values(errorSources)?.reduce((prevReportErrors, errors) => {
if (isEmptyObject(errors)) {
return prevReportErrors;
}

return Object.assign(prevReportErrors, errors);
}, {});

return allReportErrors;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,12 @@ function getValidWaypoints(waypoints: WaypointCollection | undefined, reArrangeI
return acc;
}

const validatedWaypoints: WaypointCollection = {...acc, [`waypoint${reArrangeIndexes ? waypointIndex + 1 : index}`]: currentWaypoint};
acc[`waypoint${reArrangeIndexes ? waypointIndex + 1 : index}`] = currentWaypoint;

lastWaypointIndex = index;
waypointIndex += 1;

return validatedWaypoints;
return acc;
}, {});
}

Expand Down
28 changes: 11 additions & 17 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6571,28 +6571,24 @@ function setSplitShares(transaction: OnyxEntry<OnyxTypes.Transaction>, amount: n
// If this is called from an existing group chat, it'll be included. So we manually add them to account for both cases.
const accountIDs = [...new Set<number>([userAccountID, ...newAccountIDs, ...oldAccountIDs])];

const splitShares: SplitShares = accountIDs.reduce((result: SplitShares, accountID): SplitShares => {
const splitShares: SplitShares = accountIDs.reduce((acc: SplitShares, accountID): SplitShares => {
// We want to replace the contents of splitShares to contain only `newAccountIDs` entries
// In the case of going back to the participants page and removing a participant
// a simple merge will have the previous participant still present in the splitshares object
// So we manually set their entry to null
if (!newAccountIDs.includes(accountID) && accountID !== userAccountID) {
return {
...result,
[accountID]: null,
};
acc[accountID] = null;
return acc;
}

const isPayer = accountID === userAccountID;
const participantsLength = newAccountIDs.includes(userAccountID) ? newAccountIDs.length - 1 : newAccountIDs.length;
const splitAmount = IOUUtils.calculateAmount(participantsLength, amount, currency, isPayer);
return {
...result,
[accountID]: {
amount: splitAmount,
isModified: false,
},
acc[accountID] = {
amount: splitAmount,
isModified: false,
};
return acc;
}, {});

Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`, {splitShares});
Expand Down Expand Up @@ -6644,14 +6640,12 @@ function adjustRemainingSplitShares(transaction: NonNullable<OnyxTypes.Transacti
return;
}

const splitShares: SplitShares = unmodifiedSharesAccountIDs.reduce((result: SplitShares, accountID: number, index: number): SplitShares => {
const splitShares: SplitShares = unmodifiedSharesAccountIDs.reduce((acc: SplitShares, accountID: number, index: number): SplitShares => {
const splitAmount = IOUUtils.calculateAmount(unmodifiedSharesAccountIDs.length - 1, remainingTotal, transaction.currency, index === 0);
return {
...result,
[accountID]: {
amount: splitAmount,
},
acc[accountID] = {
amount: splitAmount,
};
return acc;
}, {});

Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`, {splitShares});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ function getUpdates(options?: GetDeferredOnyxUpdatesOptiosn) {
return deferredUpdates;
}

return Object.entries(deferredUpdates).reduce<DeferredUpdatesDictionary>(
(accUpdates, [lastUpdateID, update]) => ({
...accUpdates,
...(Number(lastUpdateID) > (options.minUpdateID ?? 0) ? {[Number(lastUpdateID)]: update} : {}),
}),
{},
);
return Object.entries(deferredUpdates).reduce<DeferredUpdatesDictionary>((acc, [lastUpdateID, update]) => {
if (Number(lastUpdateID) > (options.minUpdateID ?? 0)) {
acc[Number(lastUpdateID)] = update;
}
return acc;
}, {});
}

/**
Expand Down
14 changes: 6 additions & 8 deletions src/libs/actions/OnyxUpdateManager/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ function detectGapsAndSplit(updates: DeferredUpdatesDictionary, clientLastUpdate

let updatesAfterGaps: DeferredUpdatesDictionary = {};
if (gapExists) {
updatesAfterGaps = Object.entries(updates).reduce<DeferredUpdatesDictionary>(
(accUpdates, [lastUpdateID, update]) => ({
...accUpdates,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...(Number(lastUpdateID) >= firstUpdateAfterGapWithFallback ? {[Number(lastUpdateID)]: update} : {}),
}),
{},
);
updatesAfterGaps = Object.entries(updates).reduce<DeferredUpdatesDictionary>((acc, [lastUpdateID, update]) => {
if (Number(lastUpdateID) >= firstUpdateAfterGapWithFallback) {
acc[Number(lastUpdateID)] = update;
}
return acc;
}, {});
}

return {applicableUpdates, updatesAfterGaps, latestMissingUpdateID};
Expand Down
55 changes: 23 additions & 32 deletions src/libs/actions/Policy/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,40 +64,31 @@ Onyx.connect({
});

function buildOptimisticPolicyCategories(policyID: string, categories: readonly string[]) {
const optimisticCategoryMap = categories.reduce(
(acc, category) => ({
...acc,
[category]: {
name: category,
enabled: true,
errors: null,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
}),
{},
);
const optimisticCategoryMap = categories.reduce<Record<string, Partial<PolicyCategory>>>((acc, category) => {
acc[category] = {
name: category,
enabled: true,
errors: null,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
};
return acc;
}, {});

const successCategoryMap = categories.reduce(
(acc, category) => ({
...acc,
[category]: {
errors: null,
pendingAction: null,
},
}),
{},
);
const successCategoryMap = categories.reduce<Record<string, Partial<PolicyCategory>>>((acc, category) => {
acc[category] = {
errors: null,
pendingAction: null,
};
return acc;
}, {});

const failureCategoryMap = categories.reduce(
(acc, category) => ({
...acc,
[category]: {
errors: ErrorUtils.getMicroSecondOnyxError('workspace.categories.createFailureMessage'),
pendingAction: null,
},
}),
{},
);
const failureCategoryMap = categories.reduce<Record<string, Partial<PolicyCategory>>>((acc, category) => {
acc[category] = {
errors: ErrorUtils.getMicroSecondOnyxError('workspace.categories.createFailureMessage'),
pendingAction: null,
};
return acc;
}, {});

const onyxData: OnyxData = {
optimisticData: [
Expand Down
Loading
Loading