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

Improve linter #166

Merged
merged 12 commits into from
Oct 31, 2023
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"plugins": ["react", "@typescript-eslint"],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": "off",
"react/react-in-jsx-scope": "off",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please find a solution so we'll get errors / warning whenever we have unused variable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to "error"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"prettier/prettier": [
"error",
{
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ jobs:
run: yarn
- name: Run lint
run: yarn lint
- name: find circular dependencies
run: yarn madge --extensions js,ts --circular .

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"i18next": "^23.5.1",
"leaflet": "^1.8.0",
"lodash.debounce": "^4.0.8",
"madge": "^6.1.0",
"moment": "^2.29.4",
"moment-timezone": "^0.5.43",
"open-bus-stride-client": "0.1.2",
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect } from 'react'
import { useCallback, useEffect } from 'react'
import 'antd/dist/antd.min.css'
import './App.scss'
import TimelinePage from 'src/pages/TimelinePage'
Expand Down
4 changes: 1 addition & 3 deletions src/api/groupByService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ example response
}
]
*/
export type GroupByResponse = {
type GroupByResponse = {
gtfs_route_date: string
gtfs_route_hour: string
operator_ref: number
Expand Down Expand Up @@ -130,5 +130,3 @@ export function useGroupBy({

return [data, loading, error] as const
}

export default groupbyAsync
14 changes: 0 additions & 14 deletions src/api/searchLocationService.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/pages/About.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import styled from 'styled-components'
import React from 'react'
import { TEXT_KEYS } from 'src/resources/texts'
import SlackIcon from '../resources/slack-icon.svg'
import { useTranslation } from 'react-i18next'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/GapsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect, useState } from 'react'
import { useContext, useEffect, useState } from 'react'
import { PageContainer } from './components/PageContainer'
import { Row } from './components/Row'
import { Label } from './components/Label'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/GapsPatternsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect, useState } from 'react'
import { useContext, useEffect, useState } from 'react'
import './GapsPatternsPage.scss'
import { Moment } from 'moment'
import { Skeleton, Spin } from 'antd'
Expand Down
63 changes: 0 additions & 63 deletions src/pages/MapPage.tsx

This file was deleted.

13 changes: 2 additions & 11 deletions src/pages/RealtimeMapPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useState } from 'react'
import { useEffect, useMemo, useState } from 'react'
import { MapContainer, Marker, Polyline, Popup, TileLayer, useMap } from 'react-leaflet'
import MarkerClusterGroup from 'react-leaflet-cluster'
import { TEXTS } from 'src/resources/texts'
Expand Down Expand Up @@ -37,15 +37,6 @@ interface Path {
vehicleRef: number
}

export function numberToColorHsl(i: number, max: number) {
const ratio = i / max
// 0 - black. 1 - red
const hue = 0
const saturation = ratio * 100
const lightness = ratio * 50
return `hsl(${hue}, ${saturation}%, ${lightness}%)`
}

const fiveMinutesAgo = moment().subtract(5, 'minutes')
const fourMinutesAgo = moment().subtract(4, 'minutes')

Expand Down Expand Up @@ -189,7 +180,7 @@ export default function RealtimeMapPage() {
)
}

export function Markers({ positions }: { positions: Point[] }) {
function Markers({ positions }: { positions: Point[] }) {
const map = useMap()
const [agencyList, setAgencyList] = useState<Agency[]>([])

Expand Down
2 changes: 1 addition & 1 deletion src/pages/SingleLineMapPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from 'moment'
import React, { useContext, useEffect, useMemo, useState } from 'react'
import { useContext, useEffect, useMemo, useState } from 'react'
import { MapContainer, Marker, Polyline, Popup, TileLayer } from 'react-leaflet'
import { getRoutesAsync } from 'src/api/gtfsService'
import useVehicleLocations from 'src/api/useVehicleLocations'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/TimelinePage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react'
import { useCallback, useContext, useEffect, useMemo, useState } from 'react'
import LineNumberSelector from 'src/pages/components/LineSelector'
import OperatorSelector from 'src/pages/components/OperatorSelector'
import { Row } from 'src/pages/components/Row'
Expand Down
1 change: 0 additions & 1 deletion src/pages/components/ClearButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { CloseOutlined as ClearIcon } from '@ant-design/icons'
import './ClearButton.scss'

Expand Down
4 changes: 2 additions & 2 deletions src/pages/components/DateSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import { useState } from 'react'
import { DatePicker } from '@mui/x-date-pickers/DatePicker'
import { TEXTS } from 'src/resources/texts'
import { DataAndTimeSelectorProps } from './utils/dateAndTime'
Expand All @@ -10,7 +10,7 @@ const Error = styled.div`
`

export function DateSelector({ time, onChange, customLabel }: DataAndTimeSelectorProps) {
const [error, setError] = React.useState<DateValidationError | null>(null)
const [error, setError] = useState<DateValidationError | null>(null)
return (
<>
<DatePicker
Expand Down
34 changes: 1 addition & 33 deletions src/pages/components/DateTimePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
import moment, { Moment } from 'moment'
import { Moment } from 'moment'
import React, { useCallback } from 'react'
import { DatePicker } from 'antd'
import { TEXTS } from 'src/resources/texts'

type DateTimePicker = {
timestamp: Moment | undefined
setDateTime: (timestamp: Moment) => void
showTime?: boolean
}

const JAN_FIRST_2022 = 1641038400000

function isDateDisabled(date: Moment) {
const END_OF_TODAY = moment().endOf('day')
return date.isAfter(END_OF_TODAY) || date.isBefore(moment(JAN_FIRST_2022))
}

export function useDate(initialValue: Moment) {
const [date, setDate] = React.useState<Moment>(initialValue)
Expand All @@ -25,20 +10,3 @@ export function useDate(initialValue: Moment) {
}, [])
return [date, onChange] as const
}

const DateTimePicker = ({ timestamp, setDateTime, showTime }: DateTimePicker) => (
<DatePicker
value={timestamp}
onChange={(nextTimestamp) => nextTimestamp && setDateTime(nextTimestamp)}
format={showTime ? TEXTS.datetime_format : TEXTS.date_format}
showTime={
showTime && {
defaultValue: moment('00:00:00', 'HH:mm:ss'),
format: 'HH:mm',
}
}
disabledDate={(date) => isDateDisabled(date)}
/>
)

export default DateTimePicker
2 changes: 0 additions & 2 deletions src/pages/components/DisplayGapsPercentage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from 'react'

import { TEXTS } from '../../resources/texts'
import './DisplayGapsPercentage.scss'
import { Row } from './Row'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { TEXTS } from 'src/resources/texts'
import { Autocomplete, TextField } from '@mui/material'

Expand Down
1 change: 0 additions & 1 deletion src/pages/components/Label.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import styled from 'styled-components'

const StyledDiv = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion src/pages/components/LineSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useLayoutEffect, useState } from 'react'
import { useCallback, useLayoutEffect, useState } from 'react'
import { TEXTS } from 'src/resources/texts'
import debounce from 'lodash.debounce'
import { TextField } from '@mui/material'
Expand Down
60 changes: 0 additions & 60 deletions src/pages/components/MapLayers/BusLayer.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/components/MapLayers/BusToolTip.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'
import { useEffect, useState } from 'react'
import { Point } from 'src/pages/RealtimeMapPage'
import { Button } from '@mui/material'
import moment from 'moment-timezone'
Expand Down
1 change: 0 additions & 1 deletion src/pages/components/MinuteSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { TEXTS } from 'src/resources/texts'
import { TextField } from '@mui/material'
import ClearButton from './ClearButton'
Expand Down
7 changes: 3 additions & 4 deletions src/pages/components/OperatorSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import { useEffect, useState } from 'react'
import { TEXTS } from 'src/resources/texts'
import { Operator, RELEVANT_OPERATORS } from 'src/model/operator'
import { Autocomplete, TextField } from '@mui/material'
Expand All @@ -14,9 +14,8 @@ const OperatorSelector = ({
setOperatorId,
onlyMajorOperators = false,
}: OperatorSelectorProps) => {
const [operators, setOperators] = React.useState<Operator[]>([])

React.useEffect(() => {
const [operators, setOperators] = useState<Operator[]>([])
useEffect(() => {
const majorOperatorsIds = ['3', '5', '15', '18', '25']
RELEVANT_OPERATORS.then((resultObj) =>
setOperators(
Expand Down
1 change: 0 additions & 1 deletion src/pages/components/RouteSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { formatted, TEXTS } from 'src/resources/texts'
import React from 'react'
import { BusRoute } from 'src/model/busRoute'
import { Autocomplete, TextField } from '@mui/material'

Expand Down
Loading
Loading