Skip to content

Commit

Permalink
Add boolean-conditional-rendering rule
Browse files Browse the repository at this point in the history
  • Loading branch information
rayane-djouah committed Oct 30, 2024
1 parent 3867756 commit ab40264
Show file tree
Hide file tree
Showing 119 changed files with 178 additions and 177 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ module.exports = {
files: ['*.ts', '*.tsx'],
rules: {
'rulesdir/prefer-at': 'error',
'rulesdir/boolean-conditional-rendering': 'error',
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/components/AccountSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function AccountSwitcher() {
>
{currentUserPersonalDetails?.displayName}
</Text>
{canSwitchAccounts && (
{!!canSwitchAccounts && (
<View style={styles.justifyContentCenter}>
<Icon
fill={theme.icon}
Expand Down Expand Up @@ -180,7 +180,7 @@ function AccountSwitcher() {
</View>
</View>
</PressableWithFeedback>
{canSwitchAccounts && (
{!!canSwitchAccounts && (
<PopoverMenu
isVisible={shouldShowDelegatorMenu}
onClose={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function CarouselItem({item, onPress, isFocused, isModalHovered}: CarouselItemPr
/>
</View>

{item.hasBeenFlagged && (
{!!item.hasBeenFlagged && (
<SafeAreaConsumer>
{({safeAreaPaddingBottomStyle}) => <View style={[styles.appBG, safeAreaPaddingBottomStyle]}>{renderButton([styles.m4, styles.alignSelfCenter])}</View>}
</SafeAreaConsumer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function DefaultAttachmentView({fileName = '', shouldShowLoadingSpinnerIcon = fa
</View>

<Text style={[styles.textStrong, styles.flexShrink1, styles.breakAll, styles.flexWrap, styles.mw100, isDeleted && styles.lineThrough]}>{fileName}</Text>
{!shouldShowLoadingSpinnerIcon && shouldShowDownloadIcon && (
{!shouldShowLoadingSpinnerIcon && !!shouldShowDownloadIcon && (
<Tooltip text={translate('common.download')}>
<View style={styles.ml2}>
<Icon
Expand Down
2 changes: 1 addition & 1 deletion src/components/AvatarWithDisplayName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function AvatarWithDisplayName({

const headerView = (
<View style={[styles.appContentHeaderTitle, styles.flex1]}>
{report && !!title && (
{!!report && !!title && (
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter, styles.justifyContentBetween]}>
<PressableWithoutFeedback
onPress={showActorDetails}
Expand Down
2 changes: 1 addition & 1 deletion src/components/AvatarWithImagePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ function AvatarWithImagePicker({
)}
</AttachmentModal>
</View>
{errorData.validationError && (
{!!errorData.validationError && (
<DotIndicatorMessage
style={[styles.mt6]}
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
2 changes: 1 addition & 1 deletion src/components/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function Badge({
aria-label={!pressable ? text : undefined}
accessible={false}
>
{icon && (
{!!icon && (
<View style={[styles.mr2, iconStyles]}>
<Icon
width={variables.iconSizeExtraSmall}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function Banner({
]}
>
<View style={[styles.flexRow, styles.flex1, styles.mw100, styles.alignItemsCenter]}>
{shouldShowIcon && icon && (
{shouldShowIcon && !!icon && (
<View style={[styles.mr3]}>
<Icon
src={icon}
Expand Down
6 changes: 3 additions & 3 deletions src/components/BlockingViews/BlockingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function BlockingView({
const subtitleText = useMemo(
() => (
<>
{subtitle && (
{!!subtitle && (
<AutoEmailLink
style={[styles.textAlignCenter, subtitleStyle]}
text={subtitle}
Expand Down Expand Up @@ -134,7 +134,7 @@ function BlockingView({

return (
<View style={[styles.flex1, styles.alignItemsCenter, styles.justifyContentCenter, styles.ph10, containerStyle]}>
{animation && (
{!!animation && (
<Lottie
source={animation}
loop
Expand All @@ -143,7 +143,7 @@ function BlockingView({
webStyle={animationWebStyle}
/>
)}
{icon && (
{!!icon && (
<Icon
src={icon}
fill={iconColor}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function Button(
return (
<View style={[isContentCentered ? styles.justifyContentCenter : styles.justifyContentBetween, styles.flexRow]}>
<View style={[styles.alignItemsCenter, styles.flexRow, styles.flexShrink1]}>
{icon && (
{!!icon && (
<View style={[large ? styles.mr2 : styles.mr1, !text && styles.mr0, iconStyles]}>
<Icon
src={icon}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ButtonWithDropdownMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function ButtonWithDropdownMenu<IValueType>({
enterKeyEventListenerPriority={enterKeyEventListenerPriority}
/>
)}
{(shouldAlwaysShowDropdownMenu || options.length > 1) && popoverAnchorPosition && (
{(shouldAlwaysShowDropdownMenu || options.length > 1) && !!popoverAnchorPosition && (
<PopoverMenu
isVisible={isMenuVisible}
onClose={() => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/CheckboxWithLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ function CheckboxWithLabel(
style={[styles.flexRow, styles.alignItemsCenter, styles.noSelect, styles.w100]}
wrapperStyle={[styles.ml3, styles.pr2, styles.w100, styles.flexWrap, styles.flexShrink1]}
>
{label && <Text style={[styles.ml1]}>{label}</Text>}
{LabelComponent && <LabelComponent />}
{!!label && <Text style={[styles.ml1]}>{label}</Text>}
{!!LabelComponent && <LabelComponent />}
</PressableWithFeedback>
</View>
<FormHelpMessage message={errorText} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/CollapsibleSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function CollapsibleSection({title, children, titleStyle, textStyle, wrapperStyl
src={src}
/>
</PressableWithFeedback>
{shouldShowSectionBorder && <View style={styles.collapsibleSectionBorder} />}
{!!shouldShowSectionBorder && <View style={styles.collapsibleSectionBorder} />}
<Collapsible isOpened={isExpanded}>
<View>{children}</View>
</Collapsible>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConfirmContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function ConfirmContent({
</View>
)}
<View style={isCentered ? [styles.alignItemsCenter, styles.mb6] : []}>
{iconSource && (
{!!iconSource && (
<View style={[shouldCenterIcon ? styles.justifyContentCenter : null, styles.flexRow, styles.mb3]}>
<Icon
src={iconSource}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConnectionLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function ConnectionLayoutContent({title, titleStyle, children, titleAlreadyTrans
const styles = useThemeStyles();
return (
<>
{title && <Text style={[styles.pb5, titleStyle]}>{titleAlreadyTranslated ?? translate(title)}</Text>}
{!!title && <Text style={[styles.pb5, titleStyle]}>{titleAlreadyTranslated ?? translate(title)}</Text>}
{children}
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/DecisionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function DecisionModal({title, prompt = '', firstOptionText, secondOptionText, o
</View>
<Text>{prompt}</Text>
</View>
{firstOptionText && (
{!!firstOptionText && (
<Button
success
style={[styles.mt4]}
Expand Down
2 changes: 1 addition & 1 deletion src/components/EReceiptThumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function EReceiptThumbnail({transaction, borderRadius, fileExtension, isReceiptT
fill={secondaryColor}
additionalStyles={[styles.fullScreen]}
/>
{isReceiptThumbnail && fileExtension && (
{isReceiptThumbnail && !!fileExtension && (
<Text
selectable={false}
style={[
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeatureList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function FeatureList({
large
/>
)}
{ctaErrorMessage && (
{!!ctaErrorMessage && (
<DotIndicatorMessage
style={styles.mb1}
messages={{error: ctaErrorMessage}}
Expand Down
4 changes: 2 additions & 2 deletions src/components/HeaderWithBackButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ function HeaderWithBackButton({
</PressableWithoutFeedback>
</Tooltip>
)}
{icon && (
{!!icon && (
<Icon
src={icon}
width={variables.iconHeader}
height={variables.iconHeader}
additionalStyles={[styles.mr2]}
/>
)}
{policyAvatar && (
{!!policyAvatar && (
<Avatar
containerStyles={[StyleUtils.getWidthAndHeightStyle(StyleUtils.getAvatarSize(CONST.AVATAR_SIZE.DEFAULT)), styles.mr3]}
source={policyAvatar?.source}
Expand Down
2 changes: 1 addition & 1 deletion src/components/InteractiveStepWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function InteractiveStepWrapper(
onBackButtonPress={handleBackButtonPress}
guidesCallTaskID={guidesCallTaskID}
/>
{stepNames && (
{!!stepNames && (
<View style={[styles.ph5, styles.mb5, styles.mt3, {height: CONST.BANK_ACCOUNT.STEPS_HEADER_HEIGHT}]}>
<InteractiveStepSubHeader
startStepIndex={startStepIndex}
Expand Down
4 changes: 2 additions & 2 deletions src/components/LHNOptionsList/OptionRowLHN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti
/>
</View>
)}
{hasDraftComment && optionItem.isAllowedToComment && (
{hasDraftComment && !!optionItem.isAllowedToComment && (
<View
style={styles.ml2}
accessibilityLabel={translate('sidebarScreen.draftedMessage')}
Expand All @@ -336,7 +336,7 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti
/>
</View>
)}
{!shouldShowGreenDotIndicator && !hasBrickError && optionItem.isPinned && (
{!shouldShowGreenDotIndicator && !hasBrickError && !!optionItem.isPinned && (
<View
style={styles.ml2}
accessibilityLabel={translate('sidebarScreen.chatPinned')}
Expand Down
2 changes: 1 addition & 1 deletion src/components/MagicCodeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ function MagicCodeInput(
</View>
))}
</View>
{errorText && (
{!!errorText && (
<FormHelpMessage
isError
message={errorText}
Expand Down
2 changes: 1 addition & 1 deletion src/components/MapView/Direction.website.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Direction({coordinates}: DirectionProps) {
}
return (
<View>
{coordinates && (
{!!coordinates && (
<Source
id="route"
type="geojson"
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 @@ -275,7 +275,7 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
);
})}

{directionCoordinates && <Direction coordinates={directionCoordinates} />}
{!!directionCoordinates && <Direction coordinates={directionCoordinates} />}
</Mapbox.MapView>
{interactive && (
<View style={[styles.pAbsolute, styles.p5, styles.t0, styles.r0, {zIndex: 1}]}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MapView/MapViewImpl.website.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ const MapViewImpl = forwardRef<MapViewHandle, ComponentProps>(
</Marker>
);
})}
{directionCoordinates && <Direction coordinates={directionCoordinates} />}
{!!directionCoordinates && <Direction coordinates={directionCoordinates} />}
</Map>
{interactive && (
<View style={[styles.pAbsolute, styles.p5, styles.t0, styles.r0, {zIndex: 1}]}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MentionSuggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function MentionSuggestions({

return (
<View style={[styles.autoCompleteSuggestionContainer, styles.ph2]}>
{item.icons && !!item.icons.length && (
{!!item.icons && !!item.icons.length && (
<View style={styles.mentionSuggestionsAvatarContainer}>
<Avatar
source={item.icons.at(0)?.source}
Expand Down
14 changes: 7 additions & 7 deletions src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ function MenuItem(
]}
/>
)}
{icon && !Array.isArray(icon) && (
{!!icon && !Array.isArray(icon) && (
<View
style={[
styles.popoverMenuIcon,
Expand Down Expand Up @@ -679,7 +679,7 @@ function MenuItem(
color={theme.textSupporting}
/>
))}
{icon && iconType === CONST.ICON_TYPE_WORKSPACE && (
{!!icon && iconType === CONST.ICON_TYPE_WORKSPACE && (
<Avatar
imageStyles={[styles.alignSelfCenter]}
size={CONST.AVATAR_SIZE.DEFAULT}
Expand All @@ -702,7 +702,7 @@ function MenuItem(
)}
</View>
)}
{secondaryIcon && (
{!!secondaryIcon && (
<View style={[styles.popoverMenuIcon, iconStyles, isSecondaryIconHoverable && StyleUtils.getBackgroundAndBorderStyle(theme.border)]}>
<Icon
contentFit={contentFit}
Expand Down Expand Up @@ -748,7 +748,7 @@ function MenuItem(
{renderTitleContent()}
</Text>
)}
{shouldShowTitleIcon && titleIcon && (
{!!shouldShowTitleIcon && !!titleIcon && (
<View style={[styles.ml2]}>
<Icon
src={titleIcon}
Expand Down Expand Up @@ -790,19 +790,19 @@ function MenuItem(
</View>
</View>
<View style={[styles.flexRow, styles.menuItemTextContainer, !hasPressableRightComponent && styles.pointerEventsNone]}>
{badgeText && (
{!!badgeText && (
<Badge
text={badgeText}
badgeStyles={badgeStyle}
/>
)}
{/* Since subtitle can be of type number, we should allow 0 to be shown */}
{(subtitle === 0 || subtitle) && (
{(subtitle === 0 || !!subtitle) && (
<View style={[styles.justifyContentCenter, styles.mr1]}>
<Text style={[styles.textLabelSupporting, ...(combinedStyle as TextStyle[])]}>{subtitle}</Text>
</View>
)}
{floatRightAvatars?.length > 0 && firstIcon && (
{floatRightAvatars?.length > 0 && !!firstIcon && (
<View style={[styles.alignItemsCenter, styles.justifyContentCenter, brickRoadIndicator ? styles.mr2 : styles.mrn2]}>
{shouldShowSubscriptRightAvatar ? (
<SubscriptAvatar
Expand Down
Loading

0 comments on commit ab40264

Please sign in to comment.