Skip to content

Commit

Permalink
No default export eslint (entur#734)
Browse files Browse the repository at this point in the history
* no default export + changes eslint errors to be warnings
* lint fix
  • Loading branch information
BirgitteBS authored Oct 12, 2022
1 parent d7c934a commit 1bfbbd6
Show file tree
Hide file tree
Showing 23 changed files with 62 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"eol-last": "warn",
"import/no-unresolved": "off",
"import/no-useless-path-segments": "error",
//fault-export": "error",
"import/no-default-export": "error",
"import/order": [
"error",
{
Expand Down
2 changes: 1 addition & 1 deletion src/components/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { Filter } from '../../services/realtimeVehicles/types/filter'
import { getIconColor, useDebounce } from '../../utils'
import { useSettingsContext } from '../../settings'
import useRealtimeVehicleData from '../../logic/useRealtimeVehicleData'
import { useRealtimeVehicleData } from '../../logic/useRealtimeVehicleData'
import { RealtimeVehicle } from '../../services/realtimeVehicles/types/realtimeVehicle'
import { useStopPlacesWithLines } from '../../logic/useStopPlacesWithLines'
import { LineOverlay } from './RealtimeVehicleTag/LineOverlay/LineOverlay'
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Admin/EditTab/BikeSearch/BikePanelSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AbortSignal as AbortSignalNodeFetch } from 'node-fetch/externals'
import { Coordinates } from '@entur/sdk'
import { Dropdown } from '@entur/dropdown'
import { Station } from '@entur/sdk/lib/mobility/types'
import service from '../../../../service'
import { enturClient } from '../../../../service'
import { createAbortController, getTranslation } from '../../../../utils'
import './BikePanelSearch.scss'

Expand All @@ -28,7 +28,7 @@ const BikePanelSearch = ({ onSelected, position }: Props): JSX.Element => {
useEffect(() => {
const controller = createAbortController()
if (position) {
service.mobility
enturClient.mobility
.getStations(
{
lat: position.latitude,
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Admin/EditTab/EditTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
getFromLocalStorage,
} from '../../../settings/LocalStorage'
import { useStopPlacesWithLines } from '../../../logic/useStopPlacesWithLines'
import useRealtimeVehicleData from '../../../logic/useRealtimeVehicleData'
import { useRealtimeVehicleData } from '../../../logic/useRealtimeVehicleData'
import { StopPlacePanel } from './StopPlacePanel/StopPlacePanel'
import { BikePanelSearch } from './BikeSearch/BikePanelSearch'
import { StopPlaceSearch } from './StopPlaceSearch/StopPlaceSearch'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { Coordinates, Feature } from '@entur/sdk'
import { Dropdown } from '@entur/dropdown'
import service from '../../../../service'
import { enturClient } from '../../../../service'
import './StopPlaceSearch.scss'

interface Item {
Expand All @@ -24,7 +24,7 @@ function mapFeaturesToItems(features: Feature[]): Item[] {
async function getItems(query: string): Promise<Item[]> {
if (!query.trim().length) return []

const featuresData = await service.getFeatures(query, undefined, {
const featuresData = await enturClient.getFeatures(query, undefined, {
layers: ['venue'],
})
return mapFeaturesToItems(featuresData)
Expand Down
4 changes: 2 additions & 2 deletions src/containers/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { MapDashboard } from '../dashboards/Map/MapDashboard'
import { TimelineDashboard } from '../dashboards/Timeline/TimelineDashboard'
import { Header } from '../components/Header/Header'
import { BusStopDashboard } from '../dashboards/BusStop/BusStopDashboard'
import PrivateRoute from '../routers/PrivateRoute'
import { PrivateRoute } from '../routers/PrivateRoute'
import {
getFromLocalStorage,
saveToLocalStorage,
Expand Down Expand Up @@ -289,4 +289,4 @@ const App = (): JSX.Element => (
</BrowserRouter>
)

export default App
export { App }
6 changes: 3 additions & 3 deletions src/containers/LandingPage/SearchPanel/SearchPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button } from '@entur/button'
import { Coordinates, Feature, convertFeatureToLocation } from '@entur/sdk'
import { Dropdown } from '@entur/dropdown'
import { PositionIcon } from '@entur/icons'
import service from '../../../service'
import { enturClient } from '../../../service'
import { useLocationPermission } from '../../../hooks'
import './SearchPanel.scss'

Expand All @@ -21,7 +21,7 @@ async function getStopPlace(coordinates: {
latitude: number
longitude: number
}): Promise<string | undefined> {
const result = await service.getFeaturesReverse(coordinates, {
const result = await enturClient.getFeaturesReverse(coordinates, {
size: 1,
radius: 1000,
})
Expand Down Expand Up @@ -152,7 +152,7 @@ const SearchPanel = ({ handleCoordinatesSelected }: Props): JSX.Element => {
return defaultSuggestions
}

const featuresData = await service.getFeatures(query)
const featuresData = await enturClient.getFeatures(query)
const suggestedFeatures = mapFeaturesToItems(featuresData)
return [...defaultSuggestions, ...suggestedFeatures]
}
Expand Down
2 changes: 1 addition & 1 deletion src/dashboards/Chrono/BikeTile/BikeTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Tile } from '../components/Tile/Tile'
import { useSettingsContext } from '../../../settings'
import { IconColorType } from '../../../types'
import { getIconColorType, getTranslation } from '../../../utils'
import useWalkInfo, { WalkInfo } from '../../../logic/useWalkInfo'
import { useWalkInfo, WalkInfo } from '../../../logic/useWalkInfo'
import { TileRow } from '../components/TileRow/TileRow'
import './BikeTile.scss'

Expand Down
2 changes: 1 addition & 1 deletion src/dashboards/Compact/BikeTile/BikeTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { TileRow } from '../components/TileRow/TileRow'
import { useSettingsContext } from '../../../settings'
import { IconColorType } from '../../../types'
import { getIconColorType, getTranslation } from '../../../utils'
import useWalkInfo, { WalkInfo } from '../../../logic/useWalkInfo'
import { useWalkInfo, WalkInfo } from '../../../logic/useWalkInfo'

function getWalkInfoBike(
walkInfos: WalkInfo[],
Expand Down
14 changes: 7 additions & 7 deletions src/logic/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { default as useBikeRentalStations } from './useBikeRentalStations'
export { default as useNearestPlaces } from './useNearestPlaces'
export { default as useStopPlacesWithDepartures } from './useStopPlacesWithDepartures'
export { default as useMobility } from './useMobility'
export { default as useWalkInfo } from './useWalkInfo'
export { default as useWeather } from './useWeather'
export { default as useOperators } from './useOperators'
export { useBikeRentalStations } from './useBikeRentalStations'
export { useNearestPlaces } from './useNearestPlaces'
export { useStopPlacesWithDepartures } from './useStopPlacesWithDepartures'
export { useMobility } from './useMobility'
export { useWalkInfo } from './useWalkInfo'
export { useWeather } from './useWeather'
export { useOperators } from './useOperators'
10 changes: 6 additions & 4 deletions src/logic/useBikeRentalStations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { useEffect, useState } from 'react'
import { AbortSignal as AbortSignalNodeFetch } from 'node-fetch/externals'
import { Coordinates } from '@entur/sdk'
import { Station } from '@entur/sdk/lib/mobility/types'
import service from '../service'
import { enturClient } from '../service'
import { useSettingsContext } from '../settings'
import { createAbortController } from '../utils'

async function fetchBikeRentalStationsById(
allStationIds: string[],
signal?: AbortSignal,
): Promise<Station[]> {
return await service.mobility.getStationsById(
return await enturClient.mobility.getStationsById(
{
stationIds: allStationIds,
},
Expand All @@ -24,7 +24,7 @@ async function fetchBikeRentalStationsNearby(
distance: number,
signal?: AbortSignal,
): Promise<Station[]> {
return await service.mobility.getStations(
return await enturClient.mobility.getStations(
{
lat: coordinates.latitude,
lon: coordinates.longitude,
Expand All @@ -36,7 +36,7 @@ async function fetchBikeRentalStationsNearby(

const EMPTY_BIKE_RENTAL_STATIONS: Station[] = []

export default function useBikeRentalStations(
function useBikeRentalStations(
removeHiddenStations = true,
): Station[] | undefined {
const [settings] = useSettingsContext()
Expand Down Expand Up @@ -118,3 +118,5 @@ export default function useBikeRentalStations(

return bikeRentalStations
}

export { useBikeRentalStations }
12 changes: 6 additions & 6 deletions src/logic/useMobility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect, useMemo, useState } from 'react'
import { AbortSignal as AbortSignalNodeFetch } from 'node-fetch/externals'
import { FormFactor, Operator, Vehicle } from '@entur/sdk/lib/mobility/types'
import { Coordinates } from '@entur/sdk'
import service from '../service'
import { enturClient } from '../service'
import { useSettingsContext } from '../settings'
import { REFRESH_INTERVAL, ALL_ACTIVE_OPERATOR_IDS } from '../constants'
import { createAbortController } from '../utils'
Expand All @@ -20,7 +20,7 @@ async function fetchVehicles(
return []
}

return service.mobility.getVehicles(
return enturClient.mobility.getVehicles(
{
lat: Number(coordinates.latitude),
lon: Number(coordinates.longitude),
Expand All @@ -39,9 +39,7 @@ async function fetchVehicles(

const EMPTY_VEHICLES: Vehicle[] = []

export default function useMobility(
formFactor?: FormFactor,
): Vehicle[] | undefined {
function useMobility(formFactor?: FormFactor): Vehicle[] | undefined {
const [settings] = useSettingsContext()
const allOperators = useOperators()
const [vehicles, setVehicles] = useState<Vehicle[]>()
Expand All @@ -52,7 +50,7 @@ export default function useMobility(
const operators = useMemo(
() =>
allOperators.filter(
(operator) =>
(operator: { id: string }) =>
!hiddenMobilityOperators ||
!hiddenMobilityOperators?.includes(operator.id),
),
Expand Down Expand Up @@ -101,3 +99,5 @@ export default function useMobility(

return vehicles
}

export { useMobility }
7 changes: 3 additions & 4 deletions src/logic/useNearestPlaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ type GetNearestPlacesResponse = {
}>
}

export default function useNearestPlaces(
position: Coordinates | undefined,
distance = 2000,
) {
function useNearestPlaces(position: Coordinates | undefined, distance = 2000) {
const [nearestPlaces, setNearestPlaces] = useState<NearestPlace[]>([])

const { latitude, longitude } = position ?? {}
Expand Down Expand Up @@ -121,3 +118,5 @@ export default function useNearestPlaces(

return nearestPlaces
}

export { useNearestPlaces }
8 changes: 5 additions & 3 deletions src/logic/useOperators.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useEffect, useState } from 'react'
import { Operator } from '@entur/sdk/lib/mobility/types'
import service from '../service'
import { enturClient } from '../service'
import { ALL_ACTIVE_OPERATOR_IDS } from '../constants'

async function fetchOperators(): Promise<Operator[]> {
return service.mobility.getOperators()
return enturClient.mobility.getOperators()
}

export default function useOperators(): Operator[] {
function useOperators(): Operator[] {
const [operators, setOperators] = useState<Operator[]>([])

useEffect(() => {
Expand All @@ -30,3 +30,5 @@ export default function useOperators(): Operator[] {

return operators
}

export { useOperators }
6 changes: 4 additions & 2 deletions src/logic/useRealtimeVehicleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '../constants'
import { useSettingsContext } from '../settings'
import { useStopPlacesWithLines } from './useStopPlacesWithLines'
import useVehicleReducer, { ActionType } from './useRealtimeVehicleReducer'
import { useVehicleReducer, ActionType } from './useRealtimeVehicleReducer'

interface Return {
realtimeVehicles: RealtimeVehicle[] | undefined
Expand All @@ -28,7 +28,7 @@ interface QueryData {
/**
* Hook to query and subscribe to remote vehicle data
*/
export default function useRealtimeVehicleData(filter?: Filter): Return {
function useRealtimeVehicleData(filter?: Filter): Return {
const client = useApolloClient()
const [state, dispatch] = useVehicleReducer()
const { uniqueLines } = useStopPlacesWithLines()
Expand Down Expand Up @@ -155,3 +155,5 @@ export default function useRealtimeVehicleData(filter?: Filter): Return {

return { realtimeVehicles, allLinesWithRealtimeData }
}

export { useRealtimeVehicleData }
2 changes: 1 addition & 1 deletion src/logic/useRealtimeVehicleReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ const useVehicleReducer = (): [
Dispatch<Action>,
] => useReducer(reducerFactory(), initialState)

export default useVehicleReducer
export { useVehicleReducer }
8 changes: 4 additions & 4 deletions src/logic/useStopPlacesWithDepartures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isNotNullOrUndefined, nonEmpty, unique } from '../utils'
import { apolloClient } from '../service'
import { useSettingsContext } from '../settings'
import { REFRESH_INTERVAL } from '../constants'
import useNearestPlaces from './useNearestPlaces'
import { useNearestPlaces } from './useNearestPlaces'

const GET_STOP_PLACES_WITH_DEPARTURES_QUERY = gql`
query getStopPlacesWithDepartures($ids: [String]!) {
Expand Down Expand Up @@ -174,9 +174,7 @@ function transformDepartureToLineData(

const EMPTY_STOP_PLACES_WITH_DEPARTURES: StopPlaceWithDepartures[] = []

export default function useStopPlacesWithDepartures():
| StopPlaceWithDepartures[]
| undefined {
function useStopPlacesWithDepartures(): StopPlaceWithDepartures[] | undefined {
const [settings] = useSettingsContext()

const nearestPlaces = useNearestPlaces(
Expand Down Expand Up @@ -296,3 +294,5 @@ export default function useStopPlacesWithDepartures():

return stopPlacesWithDepartures
}

export { useStopPlacesWithDepartures }
2 changes: 1 addition & 1 deletion src/logic/useStopPlacesWithLines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Line, StopPlaceWithLines } from '../types'
import { createAbortController, unique } from '../utils'
import { useSettingsContext } from '../settings'
import { getStopPlacesWithLines } from './getStopPlacesWithLines'
import useStopPlacesWithDepartures from './useStopPlacesWithDepartures'
import { useStopPlacesWithDepartures } from './useStopPlacesWithDepartures'

interface Return {
uniqueLines: Line[] | undefined
Expand Down
4 changes: 3 additions & 1 deletion src/logic/useWalkInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async function getWalkInfo(

const EMPTY_WALK_INFO: WalkInfo[] = []

export default function useWalkInfo(destinations: Destination[]): WalkInfo[] {
function useWalkInfo(destinations: Destination[]): WalkInfo[] {
const [settings] = useSettingsContext()
const [travelTime, setTravelTime] = useState<WalkInfo[]>(EMPTY_WALK_INFO)

Expand Down Expand Up @@ -154,3 +154,5 @@ export default function useWalkInfo(destinations: Destination[]): WalkInfo[] {

return travelTime
}

export { useWalkInfo }
3 changes: 2 additions & 1 deletion src/logic/useWeather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function getWeather(
}
}

export default function useWeather(): Properties | undefined {
function useWeather(): Properties | undefined {
const [settings] = useSettingsContext()
const [weather, setWeather] = useState<Properties | undefined>()

Expand Down Expand Up @@ -122,3 +122,4 @@ interface WeatherDetailsFuture {
precipitation_amount_min: number
probability_of_precipitation: number
}
export { useWeather }
2 changes: 1 addition & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'react-app-polyfill/stable'
import { init } from '@sentry/react'
import splitbee from '@splitbee/web'
import './main.scss'
import App from './containers/App'
import { App } from './containers/App'

if (process.env.SENTRY_DSN) {
init({
Expand Down
2 changes: 1 addition & 1 deletion src/routers/PrivateRoute/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ interface Props {
exact: boolean
}

export default PrivateRoute
export { PrivateRoute }
6 changes: 4 additions & 2 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (!CLIENT_NAME && process.env.NODE_ENV !== 'production') {
)
}

export default createEnturClient({
const enturClient = createEnturClient({
clientName: CLIENT_NAME,
hosts: {
journeyPlanner: process.env.JOURNEYPLANNER_HOST_V2,
Expand All @@ -19,10 +19,12 @@ export default createEnturClient({
},
})

export const apolloClient = new ApolloClient({
const apolloClient = new ApolloClient({
uri: `${process.env.JOURNEYPLANNER_HOST_V3}/graphql`,
cache: new InMemoryCache(),
headers: {
'ET-Client-Name': CLIENT_NAME,
},
})

export { enturClient, apolloClient }

0 comments on commit 1bfbbd6

Please sign in to comment.