Skip to content

Commit

Permalink
chore: fix some linter stuff (#2512)
Browse files Browse the repository at this point in the history
this is just to get a look at what current PRs are actually changing
  • Loading branch information
redreceipt committed May 25, 2022
1 parent 14ce6a0 commit 9ef7158
Show file tree
Hide file tree
Showing 34 changed files with 223 additions and 77 deletions.
4 changes: 3 additions & 1 deletion packages/apollos-ui-authentication/src/ProtectedRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const ProtectedRoute = () => {
useEffect(() => {
// if we don't have the logged in state, do nothing
// we're still showing the splash screen
if (isLoggedIn == null) return;
if (isLoggedIn == null) {
return;
}

SplashScreen.hide();
if (isLoggedIn) {
Expand Down
8 changes: 6 additions & 2 deletions packages/apollos-ui-connected/src/TabsConnected/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ const TabsConnected = ({ hasCampus }) => {
},
fetchPolicy: 'cache-and-network',
});
if (error) return null;
if (loading) return <ActivityIndicator />;
if (error) {
return null;
}
if (loading) {
return <ActivityIndicator />;
}
return <Tabs tabs={data?.tabs ?? []} />;
};

Expand Down
4 changes: 3 additions & 1 deletion packages/apollos-ui-kit/src/AddCommentInput/Confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ const Confirmation = ({
const headerRight = useMemo(
// eslint-disable-next-line react/display-name
() => () => {
if (isSubmitting) return <ActivityIndicator />;
if (isSubmitting) {
return <ActivityIndicator />;
}
return (
<SaveButton onPress={onPressSave}>
{share === 'PUBLIC' ? 'Share' : 'Save'}
Expand Down
8 changes: 6 additions & 2 deletions packages/apollos-ui-kit/src/AddCommentInput/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ const Editor = ({

const handleStopWriting = useCallback(() => {
setIsEditing(false);
if (!text.value?.length) bottomSheetModalRef.current?.collapse();
if (!text.value?.length) {
bottomSheetModalRef.current?.collapse();
}
}, [bottomSheetModalRef, text]);

const handleDismiss = useCallback(() => {
Expand Down Expand Up @@ -151,7 +153,9 @@ const Editor = ({
// the navigation header while the keyboard is visible is borked on the
// react-native-screens side of things. Not sure why 🤔
let shouldShowHeader = headerShown;
if (Platform.OS === 'android') shouldShowHeader = false;
if (Platform.OS === 'android') {
shouldShowHeader = false;
}

navigation.setOptions({
headerShown: shouldShowHeader,
Expand Down
4 changes: 3 additions & 1 deletion packages/apollos-ui-kit/src/Avatar/Placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const PlaceholderInitials = styled(({ themeSize, theme }) => ({
}))(Text);

const initialsToColor = (initials, s = 40, l = 60) => {
if (!initials) return null;
if (!initials) {
return null;
}

let hash = 0;
initials.split('').forEach((char) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/apollos-ui-kit/src/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ const Button = enhance(
...touchableProps
}) => {
const accessibilityTraits = ['button'];
if (disabled || loading) accessibilityTraits.push('disabled');
if (disabled || loading) {
accessibilityTraits.push('disabled');
}

const buttonContent = (
<ButtonStyles
Expand Down
3 changes: 2 additions & 1 deletion packages/apollos-ui-kit/src/Chip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ const Chip = enhance(
...buttonProps
}) => {
// TODO remove deprecated props
if (icon)
if (icon) {
console.warn(
'icon prop deprecated. Passing a custom Icon through children is recommended.'
);
}
return (
<StyledButton
TouchableComponent={TouchableOpacity}
Expand Down
32 changes: 24 additions & 8 deletions packages/apollos-ui-kit/src/ConnectedImage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,30 @@ export const ImageSourceType = PropTypes.oneOfType([
export const sizeCache = {};

export const getCacheKey = (source) => {
if (!source) return undefined;
if (source.url) return source.url;
if (source.uri) return source.uri;
if (typeof source === 'string') return source;
if (!source) {
return undefined;
}
if (source.url) {
return source.url;
}
if (source.uri) {
return source.uri;
}
if (typeof source === 'string') {
return source;
}
return undefined;
};

export const getCachedSources = (_sources = []) => {
let sources = _sources;
if (!Array.isArray(sources)) sources = [sources];
if (!Array.isArray(sources)) {
sources = [sources];
}
sources = sources.map((source) => {
if (typeof source === 'string') return { url: source };
if (typeof source === 'string') {
return { url: source };
}
return source;
});

Expand Down Expand Up @@ -93,7 +105,9 @@ const ConnectedImage = ({
}

const handleOnLoad = (e) => {
if (onLoad) onLoad(e);
if (onLoad) {
onLoad(e);
}
const {
nativeEvent: { source: loadedSource },
} = e;
Expand All @@ -118,7 +132,9 @@ const ConnectedImage = ({
};

const aspectRatioPropValidator = (props, propName, componentName) => {
if (props[propName] === undefined) return;
if (props[propName] === undefined) {
return;
}

let errorMessage = '';

Expand Down
24 changes: 18 additions & 6 deletions packages/apollos-ui-kit/src/ContentCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import CardFooter from './CardFooter';

const ContentCardWrapper = styled(({ tile }) => {
const style = {};
if (tile) style.width = Dimensions.get('window').width * 0.66;
if (tile) {
style.width = Dimensions.get('window').width * 0.66;
}
return style;
})(Card);

Expand Down Expand Up @@ -47,7 +49,9 @@ class ContentCard extends PureComponent {
};

renderCardHeader() {
if (this.props.header) return this.props.header;
if (this.props.header) {
return this.props.header;
}
if (this.props.coverImage || this.props.isLoading) {
let forceRatio = null;
if (this.props.isLoading) {
Expand All @@ -72,8 +76,12 @@ class ContentCard extends PureComponent {
}

renderCardContent() {
if (this.props.content) return this.props.content;
if (!this.props.title && !this.props.isLoading) return null;
if (this.props.content) {
return this.props.content;
}
if (!this.props.title && !this.props.isLoading) {
return null;
}
return (
<ContentText
tile={this.props.tile}
Expand All @@ -85,8 +93,12 @@ class ContentCard extends PureComponent {
}

renderCardFooter() {
if (this.props.footer) return this.props.footer;
if (!this.props.metrics && !this.props.isLoading) return null;
if (this.props.footer) {
return this.props.footer;
}
if (!this.props.metrics && !this.props.isLoading) {
return null;
}

const floating =
!this.props.isLoading && this.props.coverImage && !this.props.title;
Expand Down
23 changes: 17 additions & 6 deletions packages/apollos-ui-kit/src/ContentTitles/ContentTitles.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,32 @@ const ContentTitles = ({
onPressShare,
actionIcon,
}) => {
if (featured && micro)
if (featured && micro) {
console.warn(
'You are using both featured and micro on ContentTitles, which is not supported'
);
}

let Title = H3;
if (featured) Title = H2;
if (micro) Title = H4;
if (featured) {
Title = H2;
}
if (micro) {
Title = H4;
}

let Summary = BodyText;
if (micro) Summary = BodySmall;
if (micro) {
Summary = BodySmall;
}

let numberOfTitleLines = 3;
if (summary || micro) numberOfTitleLines = 2;
if (micro && summary && label) numberOfTitleLines = 1;
if (summary || micro) {
numberOfTitleLines = 2;
}
if (micro && summary && label) {
numberOfTitleLines = 1;
}

return (
<Container>
Expand Down
4 changes: 3 additions & 1 deletion packages/apollos-ui-kit/src/FollowList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class FollowList extends PureComponent {

const showButton = onPressFollowListButton && followListButtonTitle;

if (followers?.length === 0 && !isLoading && !showButton) return null;
if (followers?.length === 0 && !isLoading && !showButton) {
return null;
}

return (
<RenderAsCard>
Expand Down
2 changes: 1 addition & 1 deletion packages/apollos-ui-kit/src/Icon/Icon.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Object.keys(icons).forEach((iconName) => {
});
});

describe(`The Icon component`, () => {
describe('The Icon component', () => {
it('return null for a missing icon', () => {
const tree = renderer.create(
<Providers>
Expand Down
4 changes: 3 additions & 1 deletion packages/apollos-ui-kit/src/ModalView/ModalButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const ModalBackButton = (props) => {
key: route.state.routes[route.state.index - 1]?.key,
});
}
if (!onPress) return null;
if (!onPress) {
return null;
}
return <ModalButton name={'arrow-back'} onPress={onPress} {...props} />;
};

Expand Down
4 changes: 3 additions & 1 deletion packages/apollos-ui-kit/src/NavigationService/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ const goBack = performWhenReady((from) => {
let key;
if (from) {
const route = _navigator.state.nav.routes.find((r) => r.routeName === from);
if (route) ({ key } = route);
if (route) {
({ key } = route);
}
}
_navigator.dispatch(CommonActions.back({ key }));
});
Expand Down
8 changes: 6 additions & 2 deletions packages/apollos-ui-kit/src/Placeholder/Paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ export const Paragraph = ({
<View style={style}>
{times(lineNumber, (i) => {
let lineWidth = width;
if (i === 0 && firstLineWidth) lineWidth = firstLineWidth;
if (i === lineNumber - 1 && lastLineWidth) lineWidth = lastLineWidth;
if (i === 0 && firstLineWidth) {
lineWidth = firstLineWidth;
}
if (i === lineNumber - 1 && lastLineWidth) {
lineWidth = lastLineWidth;
}
return <ParagraphLine key={i} width={lineWidth} style={lineStyle} />;
})}
</View>
Expand Down
8 changes: 6 additions & 2 deletions packages/apollos-ui-kit/src/SocialBar/SocialBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ const SocialBar = ({ onPressLike, onPressShare, isLiked, children, style }) => {
// If only share button, flex the button to the right
// Otherwise, distribute space between the buttons
let justifyContent = 'space-between';
if (!onPressLike && onPressShare && !children) justifyContent = 'flex-end';
if (onPressLike && !onPressShare && !children) justifyContent = 'flex-start';
if (!onPressLike && onPressShare && !children) {
justifyContent = 'flex-end';
}
if (onPressLike && !onPressShare && !children) {
justifyContent = 'flex-start';
}
const containerStyle = useMemo(() => ({ justifyContent }), [justifyContent]);

return (
Expand Down
16 changes: 12 additions & 4 deletions packages/apollos-ui-kit/src/StretchyView/ReanimatedStretchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ const Stretchy = ({ children, stretchOn = 'top', scrollY, style }) => {
);

const translateY = useDerivedValue(() => {
if (!scrollY || !layoutHeight.value) return 0;
if (!scrollY || !layoutHeight.value) {
return 0;
}
if (stretchOn === 'top') {
if (scrollY.value >= 0) return 0;
if (scrollY.value >= 0) {
return 0;
}
return scrollY.value / 2;
}

Expand All @@ -32,9 +36,13 @@ const Stretchy = ({ children, stretchOn = 'top', scrollY, style }) => {
});

const scale = useDerivedValue(() => {
if (!scrollY || !layoutHeight.value) return 1;
if (!scrollY || !layoutHeight.value) {
return 1;
}
if (stretchOn === 'top') {
if (scrollY.value >= 0) return 1;
if (scrollY.value >= 0) {
return 1;
}
// y1 = 1 (scale)
// y2 = 2
// x1 = 0 (scrollY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import Stretchy from './ReanimatedStretchy';

const StretchyView = ({ children, scrollY: scrollYProp }) => {
let scrollY = useSharedValue(0);
if (scrollYProp) scrollY = scrollYProp;
if (scrollYProp) {
scrollY = scrollYProp;
}

const onScroll = useAnimatedScrollHandler((event) => {
scrollY.value = event.contentOffset.y;
Expand Down
12 changes: 9 additions & 3 deletions packages/apollos-ui-kit/src/StretchyView/Stretchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class Stretchy extends Component {
};

get stretchyYPosition() {
if (!this.props.scrollY || !this.props.height) return 0;
if (!this.props.scrollY || !this.props.height) {
return 0;
}

if (this.props.stretchOn === 'top') {
return this.props.scrollY.interpolate({
Expand Down Expand Up @@ -53,7 +55,9 @@ class Stretchy extends Component {
}

get stretchyScale() {
if (!this.props.scrollY) return 1;
if (!this.props.scrollY) {
return 1;
}

if (this.props.stretchOn === 'top') {
return this.props.scrollY.interpolate({
Expand Down Expand Up @@ -84,7 +88,9 @@ class Stretchy extends Component {
}

get stretchyOpacity() {
if (!this.props.scrollY || !this.props.height) return 0;
if (!this.props.scrollY || !this.props.height) {
return 0;
}

if (this.props.stretchOn === 'top') {
return this.props.scrollY.interpolate({
Expand Down

0 comments on commit 9ef7158

Please sign in to comment.