Skip to content

Commit

Permalink
Use double negation instead of Boolean()
Browse files Browse the repository at this point in the history
  • Loading branch information
ShridharGoel committed May 22, 2024
1 parent e8ae3c5 commit 8510c65
Show file tree
Hide file tree
Showing 100 changed files with 161 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function extractAttachmentsFromReport(parentReportAction?: OnyxEntry<ReportActio
const splittedUrl = attribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE].split('/');
attachments.unshift({
source: tryResolveUrlFromApiRoot(attribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE]),
isAuthTokenRequired: Boolean(attribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE]),
isAuthTokenRequired: !!attribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE],
file: {name: splittedUrl[splittedUrl.length - 1]},
duration: Number(attribs[CONST.ATTACHMENT_DURATION_ATTRIBUTE]),
isReceipt: false,
Expand Down Expand Up @@ -62,7 +62,7 @@ function extractAttachmentsFromReport(parentReportAction?: OnyxEntry<ReportActio
attachments.unshift({
reportActionID: attribs['data-id'],
source,
isAuthTokenRequired: Boolean(expensifySource),
isAuthTokenRequired: !!expensifySource,
file: {name: fileName},
isReceipt: false,
hasBeenFlagged: attribs['data-flagged'] === 'true',
Expand Down
4 changes: 2 additions & 2 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function Button(
large && styles.buttonLargeText,
success && styles.buttonSuccessText,
danger && styles.buttonDangerText,
Boolean(icon) && styles.textAlignLeft,
!!icon && styles.textAlignLeft,
textStyles,
]}
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
Expand Down Expand Up @@ -333,7 +333,7 @@ function Button(
]}
style={[
styles.button,
StyleUtils.getButtonStyleWithIcon(styles, small, medium, large, Boolean(icon), Boolean(text?.length > 0), shouldShowRightIcon),
StyleUtils.getButtonStyleWithIcon(styles, small, medium, large, !!icon, !!(text?.length > 0), shouldShowRightIcon),
success ? styles.buttonSuccess : undefined,
danger ? styles.buttonDanger : undefined,
isDisabled ? styles.buttonOpacityDisabled : undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConfirmedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function ConfirmedRoute({mapboxAccessToken, transaction, interactive}: Confirmed
return MapboxToken.stop;
}, []);

return !isOffline && Boolean(mapboxAccessToken?.token) ? (
return !isOffline && !!mapboxAccessToken?.token ? (
<DistanceMapView
interactive={interactive}
accessToken={mapboxAccessToken?.token ?? ''}
Expand Down
2 changes: 1 addition & 1 deletion src/components/DatePicker/CalendarPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function CalendarPicker({
style={themeStyles.calendarDayRoot}
accessibilityLabel={day?.toString() ?? ''}
tabIndex={day ? 0 : -1}
accessible={Boolean(day)}
accessible={!!day}
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
>
{({hovered, pressed}) => (
Expand Down
2 changes: 1 addition & 1 deletion src/components/DisplayNames/DisplayNamesWithTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function DisplayNamesWithToolTip({shouldUseFullTitle, fullTitle, displayNamesWit
</Fragment>
))}
{renderAdditionalText?.()}
{Boolean(isEllipsisActive) && (
{!!isEllipsisActive && (
<View style={styles.displayNameTooltipEllipsis}>
<Tooltip text={fullTitle}>
{/* There is some Gap for real ellipsis so we are adding 4 `.` to cover */}
Expand Down
2 changes: 1 addition & 1 deletion src/components/FocusableMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function FocusableMenuItem(props: MenuItemProps) {
const ref = useRef<View>(null);

// Sync focus on an item
useSyncFocus(ref, Boolean(props.focused));
useSyncFocus(ref, !!props.focused);

return (
<MenuItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function AnchorRenderer({tnode, style, key}: AnchorRendererProps) {
const htmlAttribs = tnode.attributes;
const {environmentURL} = useEnvironment();
// An auth token is needed to download Expensify chat attachments
const isAttachment = Boolean(htmlAttribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE]);
const isAttachment = !!htmlAttribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE];
const tNodeChild = tnode?.domNode?.children?.[0];
const displayName = tNodeChild && 'data' in tNodeChild && typeof tNodeChild.data === 'string' ? tNodeChild.data : '';
const parentStyle = tnode.parent?.styles?.nativeTextRet ?? {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function EditedRenderer({tnode, TDefaultRenderer, style, ...defaultRendererProps
const theme = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
const isPendingDelete = Boolean(tnode.attributes.deleted !== undefined);
const isPendingDelete = !!(tnode.attributes.deleted !== undefined);
return (
<Text>
<Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function ImageRenderer({tnode}: ImageRendererProps) {
// control and thus require no authToken to verify access.
//
const attachmentSourceAttribute = htmlAttribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE];
const isAttachmentOrReceipt = Boolean(attachmentSourceAttribute);
const isAttachmentOrReceipt = !!attachmentSourceAttribute;

// Files created/uploaded/hosted by App should resolve from API ROOT. Other URLs aren't modified
const previewSource = tryResolveUrlFromApiRoot(htmlAttribs.src);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Header({title = '', subtitle = '', textStyles = [], containerStyles = [
<>
{/* If there's no subtitle then display a fragment to avoid an empty space which moves the main title */}
{typeof subtitle === 'string'
? Boolean(subtitle) && (
? !!subtitle && (
<Text
style={[styles.mutedTextLabel, styles.pre]}
numberOfLines={1}
Expand All @@ -47,7 +47,7 @@ function Header({title = '', subtitle = '', textStyles = [], containerStyles = [
<View style={[styles.flex1, styles.flexRow, containerStyles]}>
<View style={styles.mw100}>
{typeof title === 'string'
? Boolean(title) && (
? !!title && (
<Text
numberOfLines={2}
style={[styles.headerText, styles.textLarge, textStyles]}
Expand Down
2 changes: 1 addition & 1 deletion src/components/MapView/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
};

const centerCoordinate = currentPosition ? [currentPosition.longitude, currentPosition.latitude] : initialState?.location;
return !isOffline && Boolean(accessToken) && Boolean(currentPosition) ? (
return !isOffline && !!accessToken && !!currentPosition ? (
<View style={[style, !interactive ? styles.pointerEventsNone : {}]}>
<Mapbox.MapView
style={{flex: 1}}
Expand Down
2 changes: 1 addition & 1 deletion src/components/MapView/MapView.website.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
[mapRef],
);

return !isOffline && Boolean(accessToken) && Boolean(currentPosition) ? (
return !isOffline && !!accessToken && !!currentPosition ? (
<View
style={style}
// eslint-disable-next-line react/jsx-props-no-spreading
Expand Down
2 changes: 1 addition & 1 deletion src/components/MentionSuggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function MentionSuggestions({prefix, mentions, highlightedMentionIndex = 0, onSe
>
{styledHandle?.map(
({text, isColored}, i) =>
Boolean(text) && (
!!text && (
<Text
// eslint-disable-next-line react/no-array-index-key
key={`${text}${i}`}
Expand Down
4 changes: 2 additions & 2 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -916,14 +916,14 @@ function MoneyRequestConfirmationList({
item: (
<MenuItemWithTopDescription
key={translate('common.rate')}
shouldShowRightIcon={Boolean(rate) && !isReadOnly && isPolicyExpenseChat}
shouldShowRightIcon={!!rate && !isReadOnly && isPolicyExpenseChat}
title={DistanceRequestUtils.getRateForDisplay(unit, rate, currency, translate, toLocaleDigit, isOffline)}
description={translate('common.rate')}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE_RATE.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()))}
disabled={didConfirm}
interactive={Boolean(rate) && !isReadOnly && isPolicyExpenseChat}
interactive={!!rate && !isReadOnly && isPolicyExpenseChat}
/>
),
shouldShow: isDistanceRequest && canUseP2PDistanceRequests,
Expand Down
2 changes: 1 addition & 1 deletion src/components/OptionListContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp
}

Object.values(reports ?? {})
.filter((report) => Boolean(Object.keys(report?.participants ?? {}).includes(accountID)) || (ReportUtils.isSelfDM(report) && report?.ownerAccountID === Number(accountID)))
.filter((report) => !!Object.keys(report?.participants ?? {}).includes(accountID) || (ReportUtils.isSelfDM(report) && report?.ownerAccountID === Number(accountID)))
.forEach((report) => {
if (!report) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/components/ParentNavigationSubtitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ function ParentNavigationSubtitle({parentNavigationSubtitleData, parentReportAct
style={[styles.optionAlternateText]}
numberOfLines={1}
>
{Boolean(reportName) && (
{!!reportName && (
<>
<Text style={[styles.optionAlternateText, styles.textLabelSupporting]}>{`${translate('threads.from')} `}</Text>
<Text style={[styles.optionAlternateText, styles.textLabelSupporting, styles.link]}>{reportName}</Text>
</>
)}
{Boolean(workspaceName) && <Text style={[styles.optionAlternateText, styles.textLabelSupporting]}>{` ${translate('threads.in')} ${workspaceName}`}</Text>}
{!!workspaceName && <Text style={[styles.optionAlternateText, styles.textLabelSupporting]}>{` ${translate('threads.in')} ${workspaceName}`}</Text>}
</Text>
</PressableWithoutFeedback>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Pressable/PressableWithFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function PressableWithFeedback(

return (
<OpacityView
shouldDim={Boolean(!rest.disabled && (isPressed || isHovered))}
shouldDim={!!(!rest.disabled && (isPressed || isHovered))}
dimmingValue={isPressed ? pressDimmingValue : hoverDimmingValue}
style={wrapperStyle}
needsOffscreenAlphaCompositing={needsOffscreenAlphaCompositing}
Expand Down
2 changes: 1 addition & 1 deletion src/components/RadioButtonWithLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function RadioButtonWithLabel({LabelComponent, style, label = '', hasError = fal
hoverDimmingValue={0.8}
pressDimmingValue={0.5}
>
{Boolean(label) && <Text style={[styles.ml1]}>{label}</Text>}
{!!label && <Text style={[styles.ml1]}>{label}</Text>}
{!!LabelComponent && <LabelComponent />}
</PressableWithFeedback>
</View>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/MoneyReportView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function MoneyReportView({report, policy}: MoneyReportViewProps) {
const formattedTotalAmount = CurrencyUtils.convertToDisplayString(totalDisplaySpend, report.currency);
const formattedOutOfPocketAmount = CurrencyUtils.convertToDisplayString(reimbursableSpend, report.currency);
const formattedCompanySpendAmount = CurrencyUtils.convertToDisplayString(nonReimbursableSpend, report.currency);
const isPartiallyPaid = Boolean(report?.pendingFields?.partial);
const isPartiallyPaid = !!report?.pendingFields?.partial;

const subAmountTextStyles: StyleProp<TextStyle> = [
styles.taskTitleMenuItem,
Expand Down Expand Up @@ -124,7 +124,7 @@ function MoneyReportView({report, policy}: MoneyReportViewProps) {
</Text>
</View>
</View>
{Boolean(shouldShowBreakdown) && (
{!!shouldShowBreakdown && (
<>
<View style={[styles.flexRow, styles.pointerEventsNone, styles.containerWithSpaceBetween, styles.ph5, styles.pv1]}>
<View style={[styles.flex1, styles.justifyContentCenter]}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function MoneyRequestPreviewContent({
const hasReceipt = TransactionUtils.hasReceipt(transaction);
const isScanning = hasReceipt && TransactionUtils.isReceiptBeingScanned(transaction);
const isOnHold = TransactionUtils.isOnHold(transaction);
const isSettlementOrApprovalPartial = Boolean(iouReport?.pendingFields?.partial);
const isSettlementOrApprovalPartial = !!iouReport?.pendingFields?.partial;
const isPartialHold = isSettlementOrApprovalPartial && isOnHold;
const hasViolations = TransactionUtils.hasViolation(transaction?.transactionID ?? '', transactionViolations);
const hasNoticeTypeViolations = TransactionUtils.hasNoticeTypeViolation(transaction?.transactionID ?? '', transactionViolations);
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function MoneyRequestView({
const isEmptyMerchant = transactionMerchant === '' || transactionMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT;
const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction);
const formattedTransactionAmount = transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : '';
const hasPendingWaypoints = Boolean(transaction?.pendingFields?.waypoints);
const hasPendingWaypoints = !!transaction?.pendingFields?.waypoints;
const showMapAsImage = isDistanceRequest && hasPendingWaypoints;
const formattedOriginalAmount = transactionOriginalAmount && transactionOriginalCurrency && CurrencyUtils.convertToDisplayString(transactionOriginalAmount, transactionOriginalCurrency);
const isCardTransaction = TransactionUtils.isCardTransaction(transaction);
Expand Down Expand Up @@ -329,7 +329,7 @@ function MoneyRequestView({
{!isInvoice && (
<ReceiptAuditHeader
notes={noticeTypeViolations}
shouldShowAuditMessage={Boolean(shouldShowNotesViolations && didRceiptScanSucceed)}
shouldShowAuditMessage={!!(shouldShowNotesViolations && didRceiptScanSucceed)}
/>
)}
{shouldShowMapOrReceipt && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/ReportActionItemImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function ReportActionItemImage({
const attachmentModalSource = tryResolveUrlFromApiRoot(image ?? '');
const thumbnailSource = tryResolveUrlFromApiRoot(thumbnail ?? '');
const isEReceipt = transaction && TransactionUtils.hasEReceipt(transaction);
const isDistanceRequest = Boolean(transaction && TransactionUtils.isDistanceRequest(transaction));
const isDistanceRequest = !!(transaction && TransactionUtils.isDistanceRequest(transaction));

let propsObj: ReceiptImageProps;

Expand Down
2 changes: 1 addition & 1 deletion src/components/SelectionList/BaseListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function BaseListItem<TItem extends ListItem>({
const pressableRef = useRef<View>(null);

// Sync focus on an item
useSyncFocus(pressableRef, Boolean(isFocused), shouldSyncFocus);
useSyncFocus(pressableRef, !!isFocused, shouldSyncFocus);

const rightHandSideComponentRender = () => {
if (canSelectMultiple || !rightHandSideComponent) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/BaseTextInput/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function BaseTextInput(
setPasswordHidden((prevPasswordHidden) => !prevPasswordHidden);
}, []);

const hasLabel = Boolean(label?.length);
const hasLabel = !!label?.length;
const isReadOnly = inputProps.readOnly ?? inputProps.disabled;
// Disabling this line for safeness as nullish coalescing works only if the value is undefined or null, and errorText can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down
6 changes: 3 additions & 3 deletions src/components/TextInput/BaseTextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function BaseTextInput(
setPasswordHidden((prevPasswordHidden: boolean | undefined) => !prevPasswordHidden);
}, []);

const hasLabel = Boolean(label?.length);
const hasLabel = !!label?.length;
const isReadOnly = inputProps.readOnly ?? inputProps.disabled;
// Disabling this line for safeness as nullish coalescing works only if the value is undefined or null, and errorText can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down Expand Up @@ -328,7 +328,7 @@ function BaseTextInput(
/>
</View>
)}
{Boolean(prefixCharacter) && (
{!!prefixCharacter && (
<View style={[styles.textInputPrefixWrapper, prefixContainerStyle]}>
<Text
tabIndex={-1}
Expand Down Expand Up @@ -405,7 +405,7 @@ function BaseTextInput(
style={[styles.mt4, styles.ml1]}
/>
)}
{Boolean(inputProps.secureTextEntry) && (
{!!inputProps.secureTextEntry && (
<Checkbox
style={[styles.flex1, styles.textInputIconContainer]}
onPress={togglePasswordVisibility}
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function TextInput(props: BaseTextInputProps, ref: ForwardedRef<BaseTextInputRef
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const isLabeledMultiline = Boolean(props.label?.length) && props.multiline;
const isLabeledMultiline = !!props.label?.length && props.multiline;
const labelAnimationStyle = {
// eslint-disable-next-line @typescript-eslint/naming-convention
'--active-label-translate-y': `${styleConst.ACTIVE_LABEL_TRANSLATE_Y}px`,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/CurrencyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function convertToDisplayStringWithoutCurrency(amountInCents: number, currency:
*/
function isValidCurrencyCode(currencyCode: string): boolean {
const currency = currencyList?.[currencyCode];
return Boolean(currency);
return !!currency;
}

export {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/EmojiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,13 @@ const enrichEmojiReactionWithTimestamps = (emoji: ReportActionReaction, emojiNam
*/
function hasAccountIDEmojiReacted(accountID: number, usersReactions: UsersReactions, skinTone?: number) {
if (skinTone === undefined) {
return Boolean(usersReactions[accountID]);
return !!usersReactions[accountID];
}
const userReaction = usersReactions[accountID];
if (!userReaction?.skinTones || !Object.values(userReaction?.skinTones ?? {}).length) {
return false;
}
return Boolean(userReaction.skinTones[skinTone]);
return !!userReaction.skinTones[skinTone];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Environment/betaChecker/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let isLastSavedBeta = false;
Onyx.connect({
key: ONYXKEYS.IS_BETA,
callback: (value) => {
isLastSavedBeta = Boolean(value);
isLastSavedBeta = !!value;
},
});

Expand Down
Loading

0 comments on commit 8510c65

Please sign in to comment.