Skip to content

Commit

Permalink
style: add jsx expressions linter
Browse files Browse the repository at this point in the history
  • Loading branch information
satish-ravi committed May 23, 2024
1 parent 37e365e commit 228bb71
Show file tree
Hide file tree
Showing 41 changed files with 141 additions and 99 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
extends: ['@valora/eslint-config-typescript'],
plugins: ['@jambit/typed-redux-saga'],
plugins: ['@jambit/typed-redux-saga', 'jsx-expressions'],
parserOptions: {
project: './tsconfig.eslint.json',
},
Expand All @@ -17,6 +17,7 @@ module.exports = {
excludedFiles: ['./**/*.test.ts', './**/*.test.tsx'],
rules: {
'@jambit/typed-redux-saga/use-typed-effects': 'error',
'jsx-expressions/strict-logical-expressions': 'error',
},
},
],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"eslint": "^8.19.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jest": "^26.1.1",
"eslint-plugin-jsx-expressions": "^1.3.2",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-native": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/RevokePhoneNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const RevokePhoneNumber = ({ forwardedRef }: Props) => {
title={t('revokePhoneNumber.bottomSheetTitle')}
testId="RevokePhoneNumberBottomSheet"
>
{e164PhoneNumber && (
{!!e164PhoneNumber && (
<PhoneNumberWithFlag
e164PhoneNumber={e164PhoneNumber}
defaultCountryCode={defaultCountryCode ?? undefined}
Expand Down
2 changes: 1 addition & 1 deletion src/account/AccountErrorScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function AccountErrorScreen({
<TextButton onPress={onPress} testID={`${testID}Button`}>
{buttonLabel}
</TextButton>
{secondaryButtonLabel && onPressSecondary && (
{!!secondaryButtonLabel && onPressSecondary && (
<TextButton
style={styles.secondaryButton}
onPress={onPressSecondary}
Expand Down
2 changes: 1 addition & 1 deletion src/account/Education.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const Education = (props: Props) => {
>
{step.isTopTitle && <Text style={styles.headingTop}>{step.title}</Text>}
<View style={styles.swipedContentInner}>
{step.image && (
{!!step.image && (
<Image source={step.image} style={styles.bodyImage} resizeMode="contain" />
)}
{!step.isTopTitle && <Text style={styles.heading}>{step.title}</Text>}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export function Avatar(props: Props) {
>
{name}
</Text>
{e164NumberToShow && (
{!!e164NumberToShow && (
<PhoneNumberWithFlag
e164PhoneNumber={e164NumberToShow}
defaultCountryCode={defaultCountryCode}
/>
)}
{!e164NumberToShow && address && recipient.name && (
{!e164NumberToShow && !!address && !!recipient.name && (
<Text style={[fontStyles.small, styles.contactName]} numberOfLines={1} ellipsizeMode="tail">
{formatShortenedAddress(address)}
</Text>
Expand Down
6 changes: 3 additions & 3 deletions src/components/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const BottomSheet = ({
onOpen={onOpen}
snapPoints={snapPoints}
>
{hasStickyHeader && (
{!!hasStickyHeader && (
<View style={[styles.stickyHeaderContainer, styles.headerContentSpacing]}>
{stickyTitle && <Text style={titleStyle}>{title}</Text>}
{stickyHeaderComponent}
Expand All @@ -61,10 +61,10 @@ const BottomSheet = ({
containerStyle={hasStickyHeader ? { paddingTop: 0 } : undefined}
testId={testId}
>
{!stickyTitle && title && (
{!stickyTitle && !!title && (
<Text style={[titleStyle, styles.headerContentSpacing]}>{title}</Text>
)}
{description && <Text style={styles.description}>{description}</Text>}
{!!description && <Text style={styles.description}>{description}</Text>}
{children}
</BottomSheetScrollView>
</BottomSheetBase>
Expand Down
12 changes: 6 additions & 6 deletions src/components/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ export default function Dialog({
onModalHide={onDialogHide}
>
<ScrollView contentContainerStyle={styles.root}>
{image && <Image style={styles.imageContainer} source={image} resizeMode="contain" />}
{title && <Text style={styles.title}>{title}</Text>}
{!!image && <Image style={styles.imageContainer} source={image} resizeMode="contain" />}
{!!title && <Text style={styles.title}>{title}</Text>}
<Text style={styles.body}>{children}</Text>
</ScrollView>
<View style={styles.actions}>
{secondaryActionText && (
{!!secondaryActionText && (
<TextButton
style={styles.secondary}
disabled={secondaryActionDisabled}
onPress={secondaryActionPress}
testID={testID && `${testID}/SecondaryAction`}
testID={testID ? `${testID}/SecondaryAction` : undefined}
>
{secondaryActionText}
</TextButton>
Expand All @@ -73,11 +73,11 @@ export default function Dialog({
<ActivityIndicator style={styles.primary} size="small" color={colors.primary} />
) : (
<>
{actionText && (
{!!actionText && (
<TextButton
style={isActionHighlighted ? styles.primary : styles.secondary}
onPress={actionPress}
testID={testID && `${testID}/PrimaryAction`}
testID={testID ? `${testID}/PrimaryAction` : undefined}
>
{actionText}
</TextButton>
Expand Down
2 changes: 1 addition & 1 deletion src/components/IconWithNetworkBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function IconWithNetworkBadge({ networkId, children }: Props) {
return (
<View>
{children}
{networkImageUrl && (
{!!networkImageUrl && (
<FastImage
source={{
uri: networkImageUrl,
Expand Down
4 changes: 2 additions & 2 deletions src/components/InLineNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ export function InLineNotification({
</View>
)}
<View style={styles.contentContainer}>
{title && <Text style={styles.titleText}>{title}</Text>}
{!!title && <Text style={styles.titleText}>{title}</Text>}
<Text style={[styles.bodyText]}>{description}</Text>
</View>
</View>

{(ctaLabel || ctaLabel2) && (
{(!!ctaLabel || !!ctaLabel2) && (
<View style={[styles.row, styles.ctaRow]}>
{renderCtaLabel(ctaLabel, onPressCta, variantColor.primary)}
{renderCtaLabel(ctaLabel2, onPressCta2, variantColor.primary)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/PercentageIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function PercentageIndicator({
<View style={styles.container} testID={testID}>
<View style={styles.indicator}>{indicator}</View>
<Text style={[percentageTextStyle, { color }]}>{percentageString}</Text>
{suffixText && <Text style={[suffixTextStyle, { color }]}>{suffixText}</Text>}
{!!suffixText && <Text style={[suffixTextStyle, { color }]}>{suffixText}</Text>}
</View>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReviewHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ReviewHeader extends React.PureComponent<Props> {
return (
<View style={styles.container}>
<Text style={[fontStyles.h1, styles.heading]}>{title}</Text>
{subtitle && subtitle.length > 0 && <Text style={fontStyles.regular}>{subtitle}</Text>}
{!!subtitle && subtitle.length > 0 && <Text style={fontStyles.regular}>{subtitle}</Text>}
</View>
)
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/SettingsItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ export function SettingsItemTextValue({
<View style={styles.container}>
<Title value={title} />
<View style={styles.right}>
{value && (
{!!value && (
<Text
testID={testID ? `${testID}/value` : `${title}/value`}
style={isValueActionable ? styles.valueActionable : styles.value}
>
{value}
</Text>
)}
{(value || showChevron) && (
{(!!value || showChevron) && (
<ForwardChevron color={isValueActionable ? colors.primary : undefined} />
)}
</View>
Expand Down Expand Up @@ -83,7 +83,7 @@ export function SettingsItemSwitch({
<Title value={title} />
<Switch testID={testID} value={value} onValueChange={onValueChange} />
</View>
{details && (
{!!details && (
<View>
<Text style={styles.details}>{details}</Text>
</View>
Expand All @@ -107,7 +107,7 @@ export function SettingsExpandedItem({
<View style={styles.container}>
<Title value={title} />
</View>
{details && (
{!!details && (
<View>
<Text style={styles.details}>{details}</Text>
</View>
Expand Down
2 changes: 1 addition & 1 deletion src/components/SimpleMessagingCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function SimpleMessagingCard({
<View style={styles.innerContainer}>
<View style={styles.content}>
<View>
{header && <Text style={styles.header}>{header}</Text>}
{!!header && <Text style={styles.header}>{header}</Text>}
<Text style={styles.text} testID={`${testID}/Text`}>
{text}
</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/components/SmartTopAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function SmartTopAlert({ alert }: Props) {
{!!title && <Text style={[fontStyles.small500, styles.text]}> {title} </Text>}
{message}
</Text>
{buttonMessage && (
{!!buttonMessage && (
<SmallButton
onPress={onPress}
text={buttonMessage}
Expand Down
2 changes: 1 addition & 1 deletion src/components/TokenIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default function TokenIcon({ token, viewStyle, testID, size = IconSize.ME
</View>
)}

{token.networkIconUrl && (
{!!token.networkIconUrl && (
<FastImage
source={{ uri: token.networkIconUrl }}
style={[
Expand Down
6 changes: 3 additions & 3 deletions src/components/header/CustomHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ function CustomHeader({ left, right, title, style }: Props) {
typeof title === 'string' ? <Text style={headerStyles.headerTitle}>{title}</Text> : title
return (
<View style={style ? [styles.container, style] : styles.container}>
{title && <View style={styles.titleContainer}>{titleComponent}</View>}
{left && <View style={styles.buttonContainer}>{left}</View>}
{right && <View style={styles.buttonContainer}>{right}</View>}
{!!title && <View style={styles.titleContainer}>{titleComponent}</View>}
{!!left && <View style={styles.buttonContainer}>{left}</View>}
{!!right && <View style={styles.buttonContainer}>{right}</View>}
</View>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/dappsExplorer/NoResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function NoResults({ selectedFilter, removeFilter, testID, searchTerm }: Props)
</View>
</View>
)}
{selectedFilter?.id && (
{!!selectedFilter?.id && (
<View style={styles.filterContainer}>
<Text style={styles.filterAppliedText}>
<Trans
Expand Down
2 changes: 1 addition & 1 deletion src/dappsExplorer/TabDiscover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function TabDiscover({ navigation }: Props) {
return (
<SafeAreaView testID="DAppsExplorerScreen" style={styles.safeAreaContainer} edges={[]}>
<>
{!loading && error && (
{!loading && !!error && (
<View style={styles.centerContainer}>
<Text style={fontStyles.regular}>{t('dappsScreen.errorMessage')}</Text>
</View>
Expand Down
2 changes: 1 addition & 1 deletion src/fiatExchanges/BidaliScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function BidaliScreen({ route, navigation }: Props) {

return (
<SafeAreaView style={styles.container} edges={['bottom']}>
{initialJavaScript && (
{!!initialJavaScript && (
<WebView
ref={webViewRef}
source={{ uri: networkConfig.bidaliUrl }}
Expand Down
2 changes: 1 addition & 1 deletion src/fiatExchanges/SelectProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function ExchangesSection({
<Text style={styles.categoryText}>{text}</Text>
</View>

{rightText && (
{!!rightText && (
<View style={styles.right}>
<Text style={styles.linkToOtherScreen}>{rightText}</Text>
</View>
Expand Down
2 changes: 1 addition & 1 deletion src/fiatExchanges/Spend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function Spend(props: Props) {
<Text style={styles.optionTitle}>{merchant.name}</Text>
<LinkArrow />
</View>
{merchant.subtitleKey && (
{!!merchant.subtitleKey && (
<Text style={styles.optionSubtitle}>{t(merchant.subtitleKey)}</Text>
)}
</ListItem>
Expand Down
4 changes: 2 additions & 2 deletions src/fiatconnect/FiatDetailsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function FormField({
return (
<View style={styles.inputView} key={`inputField-${field.name}`}>
<View style={styles.row}>
{field.label && <Text style={styles.inputLabel}>{field.label}</Text>}
{!!field.label && <Text style={styles.inputLabel}>{field.label}</Text>}
{field.infoDialog && (
<TouchableOpacity
testID={`infoIcon-${field.name}`}
Expand Down Expand Up @@ -355,7 +355,7 @@ function FormField({
}}
/>
)}
{errorMessage && showError && (
{!!errorMessage && showError && (
<Text testID={`errorMessage-${field.name}`} style={styles.error}>
{errorMessage}
</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/home/HomeAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class HomeAction extends React.Component<HomeActionProps> {
<View style={styles.textContainer}>
<Text style={[fonts.small600, styles.title]}>{title}</Text>
<Text style={[fonts.small, styles.subtitle]}>{subtitle}</Text>
{cta && ctaOnPress && <SmallButton solid={true} text={cta} onPress={ctaOnPress} />}
{!!cta && ctaOnPress && <SmallButton solid={true} text={cta} onPress={ctaOnPress} />}
</View>
</View>
)
Expand Down
2 changes: 1 addition & 1 deletion src/home/celebration/ConfettiCelebration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const ConfettiCelebration = ({
onLayout={handleLayout}
>
<View style={styles.notification}>
{title && <Text style={styles.titleText}>{title}</Text>}
{!!title && <Text style={styles.titleText}>{title}</Text>}
<Text style={styles.descriptionText}>{description}</Text>
</View>
</Animated.View>
Expand Down
12 changes: 3 additions & 9 deletions src/icons/BackChevron.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@ import Svg, { Path } from 'react-native-svg'
import Colors from 'src/styles/colors'

export interface Props {
height?: number
color?: ColorValue | Animated.Node<ColorValue | undefined>
height: number
color: ColorValue | Animated.Node<ColorValue | undefined>
}
const AnimatedPath = Animated.createAnimatedComponent(Path)

function BackChevron({ color, height }: Props) {
return (
<Svg
height={height}
width={height && height / 2}
viewBox="0 0 8 16"
fill="none"
testID="BackChevron"
>
<Svg height={height} width={height / 2} viewBox="0 0 8 16" fill="none" testID="BackChevron">
<AnimatedPath
fillRule="evenodd"
clipRule="evenodd"
Expand Down
6 changes: 3 additions & 3 deletions src/icons/ForwardChevron.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import colors from 'src/styles/colors'
import Svg, { Path } from 'svgs'

interface Props {
height?: number
color?: string
height: number
color: string
}

function ForwardChevron({ color, height }: Props) {
return (
<Svg
height={height}
width={height && height / 2}
width={height / 2}
viewBox="0 0 8 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
Expand Down
4 changes: 2 additions & 2 deletions src/navigator/Headers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export function HeaderTitleWithSubtitle({
}) {
return (
<View style={styles.header} testID={testID}>
{title && (
{!!title && (
<Text
testID="HeaderTitle"
style={styles.headerTitle}
Expand All @@ -266,7 +266,7 @@ export function HeaderTitleWithSubtitle({
{title}
</Text>
)}
{subTitle && (
{!!subTitle && (
<Text
testID="HeaderSubTitle"
style={styles.headerSubTitle}
Expand Down
2 changes: 1 addition & 1 deletion src/navigator/ProfileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function ProfileMenu({ route }: Props) {
{displayName}
</Text>
)}
{phoneNumberVerified && e164PhoneNumber && (
{phoneNumberVerified && !!e164PhoneNumber && (
<PhoneNumberWithFlag
e164PhoneNumber={e164PhoneNumber}
defaultCountryCode={defaultCountryCode ? defaultCountryCode : undefined}
Expand Down
Loading

0 comments on commit 228bb71

Please sign in to comment.