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

chore: update eslint + prettier rules #254

Merged
merged 18 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
style: fix all forbidden non-null assertion
  • Loading branch information
ftonato committed Oct 8, 2019
commit 69a39bd2a6734d527b9903dec906318552c8e1fd
26 changes: 20 additions & 6 deletions App/Screens/Details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,37 @@ export function Details(props: DetailsProps) {
// I have no idea why, but if we don't clone the object, and continue to
// use `location.current` everywhere, we get a `setting key of frozen
// object` error. It's related to the MapView below.
// eslint-disable-next-line
const currentLocation = { ..._currentLocation! };

const haversineDistanceUnit = i18n.t(
'haversine_distance_unit'
) as DistanceUnit;

if (currentLocation === undefined || !Object.keys(currentLocation).length) {
ftonato marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(
'Details/Details.tsx only convert `distanceToStation` when `currentLocation` is defined.'
);
} else if (!api) {
throw new Error(
'Details/Details.tsx only convert `distanceToStation` when `api` is defined.'
);
}

const distance = distanceToStation(
currentLocation!,
api!,
currentLocation,
api,
haversineDistanceUnit
);

const station = {
description: api!.shootISmoke.station || '',
title: api!.shootISmoke.station,
description: (api && api.shootISmoke && api.shootISmoke.station) || '',
title: (api && api.shootISmoke && api.shootISmoke.station) || '',
...getCorrectLatLng(currentLocation, {
latitude: api!.city.geo[0],
longitude: api!.city.geo[1]
latitude:
(api && api.city && api.city.geo.length && api.city.geo[0]) || 0,
longitude:
(api && api.city && api.city.geo.length > 1 && api.city.geo[1]) || 0
ftonato marked this conversation as resolved.
Show resolved Hide resolved
})
};

Expand Down
18 changes: 14 additions & 4 deletions App/Screens/Details/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,19 @@ export function Header(props: HeaderProps) {
const { api } = useContext(ApiContext);
const { currentLocation } = useContext(CurrentLocationContext);

if (currentLocation === undefined || !Object.keys(currentLocation).length) {
throw new Error(
'Details/Header/Header.tsx only render when `currentLocation` is defined.'
);
} else if (!api) {
throw new Error(
'Details/Header/Header.tsx only render when `api` is defined.'
);
}

const lastUpdated =
api!.time && api!.time.v ? new Date(api!.time.v * 1000) : null;
const { dominentpol, iaqi } = api!;
api.time && api.time.v ? new Date(api.time.v * 1000) : null;
const { dominentpol, iaqi } = api;

return (
<View style={styles.container}>
Expand All @@ -109,8 +119,8 @@ export function Header(props: HeaderProps) {

<View style={styles.content}>
<CurrentLocation
api={api!}
currentLocation={currentLocation!}
api={api}
currentLocation={currentLocation}
style={styles.currentLocation}
/>
{lastUpdated &&
Expand Down
14 changes: 12 additions & 2 deletions App/Screens/Home/AdditionalInfo/AdditionalInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,21 @@ const styles = StyleSheet.create({
});

export function AdditionalInfo(props: AdditionalInfoProps) {
const { api } = useContext(ApiContext)!;
const { api } = useContext(ApiContext);
const { currentLocation } = useContext(CurrentLocationContext);
const { frequency, navigation, style, ...rest } = props;

const isTooFar = isStationTooFar(currentLocation!, api!);
if (currentLocation === undefined || !Object.keys(currentLocation).length) {
throw new Error(
'Home/AdditionalInfo/AdditionalInfo.tsx only gets calculate the `distanceToStation` when `currentLocation` is defined.'
);
} else if (!api) {
throw new Error(
'Home/AdditionalInfo/AdditionalInfo.tsx only gets calculate the `distanceToStation` when `api` is defined.'
);
}

const isTooFar = isStationTooFar(currentLocation, api);

function renderBeta() {
return (
Expand Down
16 changes: 13 additions & 3 deletions App/Screens/Home/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,22 @@ const styles = StyleSheet.create({
});

export function Footer(props: FooterProps) {
const { api } = useContext(ApiContext)!;
const { api } = useContext(ApiContext);
const { currentLocation } = useContext(CurrentLocationContext);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { navigation, style, ...rest } = props;

const isTooFar = isStationTooFar(currentLocation!, api!);
if (currentLocation === undefined || !Object.keys(currentLocation).length) {
throw new Error(
'Home/Footer/Footer.tsx only gets calculate the `distanceToStation` when `currentLocation` is defined.'
);
} else if (!api) {
throw new Error(
'Home/Footer/Footer.tsx only gets calculate the `distanceToStation` when `api` is defined.'
);
}

const isTooFar = isStationTooFar(currentLocation, api);

function goToAbout() {
track('HOME_SCREEN_ABOUT_CLICK');
Expand Down Expand Up @@ -70,7 +80,7 @@ export function Footer(props: FooterProps) {
Share.share({
title: i18n.t('home_share_title'),
message: i18n.t('home_share_message', {
cigarettes: api!.shootISmoke.cigarettes.toFixed(2)
cigarettes: (api && api.shootISmoke.cigarettes.toFixed(2)) || 0
ftonato marked this conversation as resolved.
Show resolved Hide resolved
})
});
}
Expand Down
24 changes: 18 additions & 6 deletions App/Screens/Home/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,39 @@ const styles = StyleSheet.create({
});

export function Header(props: HeaderProps) {
const { api } = useContext(ApiContext)!;
const { api } = useContext(ApiContext);
const { currentLocation, isGps } = useContext(CurrentLocationContext);
const { onChangeLocationClick } = props;

const distanceUnit = i18n.t('distance_unit');
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
const haversineDistanceUnit = i18n.t(
'haversine_distance_unit'
) as DistanceUnit;

if (currentLocation === undefined || !Object.keys(currentLocation).length) {
throw new Error(
'Home/Header/Header.tsx only convert `distanceToStation` when `currentLocation` is defined.'
);
} else if (!api) {
throw new Error(
'Home/Header/Header.tsx only convert `distanceToStation` when `api` is defined.'
);
}

const distance = distanceToStation(
currentLocation!,
api!,
currentLocation,
api,
haversineDistanceUnit
);
const isTooFar = isStationTooFar(currentLocation!, api!);

const isTooFar = isStationTooFar(currentLocation, api);

return (
<View style={styles.container}>
<View style={styles.currentLocation}>
<CurrentLocation
api={api!}
currentLocation={currentLocation!}
api={api}
currentLocation={currentLocation}
numberOfLines={2}
/>
<View style={styles.distance}>
Expand Down
2 changes: 1 addition & 1 deletion App/Screens/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function Home(props: HomeProps) {

trackScreen('HOME');

const cigarettesPerDay = api!.shootISmoke.cigarettes;
const cigarettesPerDay = (api && api.shootISmoke.cigarettes) || 0;

return (
<View style={styles.container}>
Expand Down
16 changes: 11 additions & 5 deletions App/Screens/Home/SelectFrequency/SelectFrequency.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export function SelectFrequency(props: ScrollViewProps) {
return;
}

scroll.current!.scrollTo({ x: 0 });
if (scroll && scroll.current) {
scroll.current.scrollTo({ x: 0 });
}
handleChangeFrequency('daily');
}}
style={styles.boxButton}
Expand All @@ -82,9 +84,11 @@ export function SelectFrequency(props: ScrollViewProps) {
return;
}

scroll.current!.scrollTo({
x: dailyWidth + theme.spacing.mini
});
if (scroll && scroll.current) {
scroll.current.scrollTo({
x: dailyWidth + theme.spacing.mini
});
}
handleChangeFrequency('weekly');
}}
style={styles.boxButton}
Expand All @@ -100,7 +104,9 @@ export function SelectFrequency(props: ScrollViewProps) {
return;
}

scroll.current!.scrollToEnd();
if (scroll && scroll.current) {
scroll.current.scrollToEnd();
}
handleChangeFrequency('monthly');
}}
style={styles.boxButton}
Expand Down
4 changes: 2 additions & 2 deletions App/Screens/Search/fetchAlgolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

import axios from 'axios';
import Constants from 'expo-constants';
import { pipe } from 'fp-ts/lib/pipeable';
import * as C from 'fp-ts/lib/Console';
import * as E from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import * as T from 'fp-ts/lib/Task';
import * as TE from 'fp-ts/lib/TaskEither';
import * as t from 'io-ts';
import { failure } from 'io-ts/lib/PathReporter';

import { LatLng } from '../../stores/fetchGpsPosition';
import { retry, sideEffect, toError } from '../../util/fp';

Expand All @@ -44,6 +43,7 @@ const AlgoliaHitT = t.exact(
lng: t.number
}),
country: t.string,
// eslint-disable-next-line
locale_names: t.array(t.string),
objectID: t.string
}),
Expand Down
18 changes: 14 additions & 4 deletions App/Screens/ShareScreen/ShareImage/ShareImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,21 @@ const styles = StyleSheet.create({
});

export function ShareImage() {
const { api } = useContext(ApiContext)!;
const { api } = useContext(ApiContext);
const { currentLocation } = useContext(CurrentLocationContext);
const { frequency } = useContext(FrequencyContext);

const cigarettesPerDay = api!.shootISmoke.cigarettes;
if (currentLocation === undefined || !Object.keys(currentLocation).length) {
throw new Error(
'ShareScreen/ShareImage/ShareImage.tsx only render when `currentLocation` is defined.'
);
} else if (!api) {
throw new Error(
'ShareScreen/ShareImage/ShareImage.tsx only render when `api` is defined.'
);
}

const cigarettesPerDay = (api && api.shootISmoke.cigarettes) || 0;

return (
<View style={styles.container}>
Expand All @@ -62,8 +72,8 @@ export function ShareImage() {
/>
<View>
<CurrentLocation
api={api!}
currentLocation={currentLocation!}
api={api}
currentLocation={currentLocation}
numberOfLines={2}
/>
</View>
Expand Down
6 changes: 3 additions & 3 deletions App/stores/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import { pipe } from 'fp-ts/lib/pipeable';
import * as T from 'fp-ts/lib/Task';
import * as TE from 'fp-ts/lib/TaskEither';
import React, { createContext, useContext, useEffect, useState } from 'react';

import { logFpError } from '../util/fp';
import { noop } from '../util/noop';
import { ErrorContext } from './error';
import { Api, fetchApi } from './fetchApi';
import { CurrentLocationContext } from './location';
import { logFpError } from '../util/fp';
import { noop } from '../util/noop';

interface Context {
api?: Api;
Expand Down Expand Up @@ -70,6 +69,7 @@ export function ApiContextProvider({ children }: ApiContextProviderProps) {
<ApiContext.Provider
value={{
api,
// eslint-disable-next-line
reloadApp: () => setCurrentLocation({ ...currentLocation! }) // Small trick to re-run effect
}}
>
Expand Down