Skip to content

Commit 7ea9865

Browse files
committed
chore: disable prefer-optional-chain ESLint rule
The rule's --fix introduces logic bugs by converting falsy guards to optional chains, removing protection against empty strings and nullish values. Workarounds (eslint-disable comments, magic-string hacks) are worse than the original code. Disabling the rule and removing all related eslint-disable comments.
1 parent b060610 commit 7ea9865

6 files changed

Lines changed: 1 addition & 7 deletions

File tree

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ const config = defineConfig([
446446
],
447447
'@typescript-eslint/prefer-find': 'off',
448448
'@typescript-eslint/prefer-includes': 'off',
449+
'@typescript-eslint/prefer-optional-chain': 'off',
449450
'@typescript-eslint/prefer-nullish-coalescing': [
450451
'error',
451452
{

src/components/Modal/ReanimatedModal/Container/GestureHandler.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ function hasSwipeEnded(
1616
) {
1717
'worklet';
1818

19-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
2019
if (!swipeDirection || !swipeDirection?.length || !onSwipeComplete) {
2120
return;
2221
}
@@ -66,7 +65,6 @@ function GestureHandler({swipeDirection, onSwipeComplete, swipeThreshold = 100,
6665
[initialTranslationX, initialTranslationY, onSwipeComplete, swipeDirection, swipeThreshold],
6766
);
6867

69-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
7068
if (!swipeDirection || !swipeDirection?.length || !onSwipeComplete) {
7169
return children;
7270
}

src/libs/PolicyUtils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,8 +1299,6 @@ function hasIndependentTags(policy: OnyxEntry<Policy>, policyTagList: OnyxEntry<
12991299

13001300
/** Get the Xero organizations connected to the policy */
13011301
function getXeroTenants(policy: Policy | undefined): Tenant[] {
1302-
// Due to the way optional chain is being handled in this useMemo we are forced to use this approach to properly handle undefined values
1303-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
13041302
if (!policy || !policy.connections || !policy.connections.xero || !policy.connections.xero.data) {
13051303
return [];
13061304
}

src/pages/OnboardingWorkEmail/BaseOnboardingWorkEmail.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ function BaseOnboardingWorkEmail({shouldUseNativeStyles}: BaseOnboardingWorkEmai
112112
const emailParts = userEmail.split('@');
113113
const domain = emailParts.at(1) ?? '';
114114

115-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- optional chain removes the falsy guard for empty strings, causing a false positive when both emails are empty
116115
if (session?.email && userEmail.toLowerCase() === session.email.toLowerCase() && !isOffline) {
117116
addErrorMessage(errors, INPUT_IDS.ONBOARDING_WORK_EMAIL, translate('onboarding.workEmailValidationError.sameAsSignupEmail'));
118117
} else if ((!Str.isValidEmail(userEmail) || PUBLIC_DOMAINS_SET.has(domain.toLowerCase())) && !isOffline) {

src/pages/workspace/companyCards/WorkspaceCompanyCardAddWorkEmailPage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ function WorkspaceCompanyCardAddWorkEmailPage({route}: WorkspaceCompanyCardAddWo
9595
};
9696

9797
useEffect(() => {
98-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- optional chain changes logic: when both email and primaryContactMethod are falsy, it skips early return and navigates incorrectly
9998
if (!email || !primaryContactMethod || primaryContactMethod.toLowerCase() !== email.toLowerCase() || isWorkEmailValidated) {
10099
return;
101100
}

src/pages/workspace/expensifyCard/WorkspaceExpensifyCardAddWorkEmailPage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ function WorkspaceExpensifyCardAddWorkEmailPage({route}: WorkspaceExpensifyCardA
8686
};
8787

8888
useEffect(() => {
89-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- optional chain changes logic: when both email and primaryContactMethod are falsy, it skips early return and navigates incorrectly
9089
if (!email || !primaryContactMethod || primaryContactMethod.toLowerCase() !== email.toLowerCase() || isWorkEmailValidated) {
9190
return;
9291
}

0 commit comments

Comments
 (0)