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

[No QA] Use double negation instead of Boolean() #42492

Merged
merged 13 commits into from
Jun 6, 2024
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.49",
"eslint-config-expensify": "^2.0.50",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^24.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function extractAttachments(
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 @@ -69,7 +69,7 @@ function extractAttachments(
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 @@ -329,7 +329,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 @@ -104,7 +104,7 @@ function ConfirmedRoute({mapboxAccessToken, transaction, isSmallerIcon, shouldHa

const shouldDisplayMap = !requireRouteToDisplayMap || !!coordinates.length;

return !isOffline && Boolean(mapboxAccessToken?.token) && shouldDisplayMap ? (
return !isOffline && !!mapboxAccessToken?.token && shouldDisplayMap ? (
<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 @@ -51,7 +51,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 @@ -170,7 +170,7 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
}, [directionCoordinates, currentPosition, mapPadding, waypoints]);

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 @@ -208,7 +208,7 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
});
}, [directionCoordinates, currentPosition, mapRef, waypoints, mapPadding]);

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 @@ -922,14 +922,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 @@ -43,7 +43,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 @@ -121,7 +121,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 @@ -89,11 +89,13 @@ 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 = Boolean(
TransactionUtils.hasNoticeTypeViolation(transaction?.transactionID ?? '', transactionViolations) && ReportUtils.isPaidGroupPolicy(iouReport) && canUseViolations,
const hasNoticeTypeViolations = !!(
TransactionUtils.hasNoticeTypeViolation(transaction?.transactionID ?? '', transactionViolations) &&
ReportUtils.isPaidGroupPolicy(iouReport) &&
canUseViolations
);
const hasFieldErrors = TransactionUtils.hasMissingSmartscanFields(transaction);
const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ function MoneyRequestView({
{shouldShowReceiptHeader && (
<ReceiptAuditHeader
notes={receiptViolations}
shouldShowAuditMessage={Boolean(shouldShowNotesViolations && didRceiptScanSucceed)}
shouldShowAuditMessage={!!(shouldShowNotesViolations && didRceiptScanSucceed)}
/>
)}
{(hasReceipt || errors) && (
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 @@ -42,7 +42,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 handleMouseUp = (e: React.MouseEvent<Element, MouseEvent>) => {
e.stopPropagation();
setMouseUp();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Switch({isOn, onToggle, accessibilityLabel, disabled, showLockIcon}: Sw
pressDimmingValue={0.8}
>
<Animated.View style={[styles.switchThumb, styles.switchThumbTransformation(offsetX.current)]}>
{(Boolean(disabled) || Boolean(showLockIcon)) && (
{(!!disabled || !!showLockIcon) && (
<Icon
src={Expensicons.Lock}
fill={isOn ? theme.text : theme.icon}
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 @@ -407,7 +407,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 @@ -168,7 +168,7 @@ function convertToDisplayStringWithoutCurrency(amountInCents: number, currency:
*/
function isValidCurrencyCode(currencyCode: string): boolean {
const currency = currencyList?.[currencyCode];
return Boolean(currency);
return !!currency;
}

export {
Expand Down
Loading
Loading