Skip to content

Commit

Permalink
Merge pull request #42650 from kacper-mikolajczak/chore/eslint-config…
Browse files Browse the repository at this point in the history
…-expensify-2.0.49

Chore: Update eslint-config-expensify to 2.0.49
  • Loading branch information
mountiny authored Jun 2, 2024
2 parents 2b0b103 + 20b6fec commit f701c3e
Show file tree
Hide file tree
Showing 22 changed files with 198 additions and 232 deletions.
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 @@ -259,7 +259,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 @@ -521,10 +521,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 @@ -548,7 +551,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 @@ -6615,28 +6615,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 @@ -6688,14 +6684,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
13 changes: 6 additions & 7 deletions src/libs/actions/OnyxUpdateManager/utils/DeferredOnyxUpdates.ts
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

0 comments on commit f701c3e

Please sign in to comment.