Skip to content

Commit

Permalink
Clean up a bunch of code and eslint warnings (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinmatte committed Jul 15, 2023
1 parent ae2c82b commit 54ccb64
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 132 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ module.exports = {
'import/no-unused-modules': ['off', { unusedExports: false }],
},
},
// Temporarily don't enforce some rules on types and constants
{
files: ['common/styles/*.ts', 'common/constants/**/*.ts', 'common/types/**/*.ts'],
rules: {
'@typescript-eslint/no-non-null-assertion': 'error',
'import/no-unused-modules': ['off', { unusedExports: false }],
},
},
],
ignorePatterns: ['node_modules/**/*', 'build/**/*', 'out/**/*'],
};
14 changes: 11 additions & 3 deletions common/api/slowzones.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
SlowZoneResponse,
SpeedRestriction,
} from '../../common/types/dataPoints';
import type { FetchSpeedRestrictionsOptions } from '../types/api';
import type { FetchSpeedRestrictionsOptions, FetchSpeedRestrictionsResponse } from '../types/api';
import { APP_DATA_BASE_PATH } from '../utils/constants';
import { getGtfsRailLineId } from '../utils/lines';

Expand All @@ -28,9 +28,17 @@ export const fetchSpeedRestrictions = async (
);
const today = new Date();
const response = await fetch(speedRestrictionsUrl.toString());
const { available, date: resolvedDate, zones } = await response.json();
const {
available,
date: resolvedDate,
zones,
}: FetchSpeedRestrictionsResponse = await response.json();
if (available) {
return zones.map((zone) => ({ ...zone, currentAsOf: resolvedDate, validAsOf: today }));
return zones.map((zone) => ({
...zone,
currentAsOf: new Date(resolvedDate),
validAsOf: today,
}));
}
return [];
};
53 changes: 0 additions & 53 deletions common/components/inputs/styles/tailwind.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion common/components/notices/ErrorNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import classNames from 'classnames';
import React from 'react';
import { useDelimitatedRoute } from '../../utils/router';
import { mbtaTextConfig } from '../inputs/styles/tailwind';
import { mbtaTextConfig } from '../../styles/general';

interface ErrorNoticeProps {
isWidget?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion common/components/notices/NoDataNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import classNames from 'classnames';
import React from 'react';
import { useDelimitatedRoute } from '../../utils/router';
import { mbtaTextConfig } from '../inputs/styles/tailwind';
import { mbtaTextConfig } from '../../styles/general';

interface NoDataNoticeProps {
isWidget?: boolean;
Expand Down
1 change: 1 addition & 0 deletions common/constants/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export const TWO_HOURS = 2 * ONE_HOUR;
export const THREE_HOURS = 3 * ONE_HOUR;
export const FOUR_HOURS = 4 * ONE_HOUR;
export const TWELVE_HOURS = 12 * ONE_HOUR;
export const ONE_DAY = 24 * ONE_HOUR;
9 changes: 9 additions & 0 deletions common/styles/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ export const lineColorLightBorder = {
DEFAULT: `border-stone-900`,
};

export const mbtaTextConfig: DefaultStyleMap = {
'line-red': `text-mbta-red`,
'line-orange': `text-mbta-orange`,
'line-green': `text-mbta-green`,
'line-blue': `text-mbta-blue`,
'line-bus': `text-mbta-bus`,
DEFAULT: `text-black`,
};

export const lineColorLightBackground: DefaultStyleMap = {
'line-red': `bg-mbta-lightRed`,
'line-orange': `bg-mbta-lightOrange`,
Expand Down
3 changes: 2 additions & 1 deletion common/types/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AggType } from '../../modules/speed/constants/speeds';
import type { SpeedRestriction } from './dataPoints';
import type { Line } from './lines';

export enum QueryNameKeys {
Expand Down Expand Up @@ -92,5 +93,5 @@ export type FetchSpeedRestrictionsOptions = {
export type FetchSpeedRestrictionsResponse = {
available: boolean;
date: string;
zones: Record<string, any>[];
zones: SpeedRestriction[];
};
2 changes: 1 addition & 1 deletion common/types/dataPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ export type SpeedRestriction = {
reported: string;
speedMph: number;
trackFeet: number;
currentAsOf: Date;
lineId: Line;
currentAsOf: Date;
validAsOf: Date;
};

Expand Down
6 changes: 3 additions & 3 deletions common/utils/headways.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ export const longestHeadway = (headways: SingleDayDataPoint[] | AggregateDataPoi
}
};

export const longestAggregateHeadway = (headways: AggregateDataPoint[]) => {
const longestAggregateHeadway = (headways: AggregateDataPoint[]) => {
return headways.reduce(
(current, datapoint) => (datapoint.min < current.min ? datapoint : current),
headways[0]
);
};

export const longestSingleHeadway = (headways: SingleDayDataPoint[]) => {
const longestSingleHeadway = (headways: SingleDayDataPoint[]) => {
return headways.reduce((current, datapoint) => {
if (datapoint.headway_time_sec && current.headway_time_sec)
return datapoint.headway_time_sec > current.headway_time_sec ? datapoint : current;
return current;
}, headways[0]);
};

export const shortestSingleHeadway = (headways: SingleDayDataPoint[]) => {
const shortestSingleHeadway = (headways: SingleDayDataPoint[]) => {
return headways.reduce((current, datapoint) => {
if (datapoint.headway_time_sec && current.headway_time_sec)
return datapoint.headway_time_sec < current.headway_time_sec ? datapoint : current;
Expand Down
49 changes: 0 additions & 49 deletions common/utils/ridership.ts

This file was deleted.

8 changes: 0 additions & 8 deletions common/utils/slowZoneUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ export const getStationPairName = (from: Station, to: Station, short?: boolean):
return `${from.stop_name}-${to.stop_name}`;
};

const groupByRoute = (data: SlowZone[]) =>
data.reduce((series: Record<string, SlowZone[]>, sz: SlowZone) => {
const key = sz.id;
const s = (series[key] || []).concat(sz);
series[key] = s;
return series;
}, {});

const groupByLine = (data: SlowZone[]) =>
data.reduce((series: Record<string, SlowZone[]>, sz) => {
const key = sz.color;
Expand Down
11 changes: 0 additions & 11 deletions common/utils/stations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { SelectOption } from '../../common/types/inputs';
import type { Line, LineShort } from '../../common/types/lines';
import type { Station } from '../../common/types/stations';
import type { Location } from '../types/charts';
Expand Down Expand Up @@ -40,16 +39,6 @@ export const optionsStation = (line: LineShort, busRoute?: string): Station[] |
return stations[line].stations.sort((a, b) => a.order - b.order);
};

export const swapStations = (
fromStation: SelectOption<Station> | null,
toStation: SelectOption<Station> | null,
setFromStation: (fromStation: SelectOption<Station> | null) => void,
setToStation: (toStation: SelectOption<Station> | null) => void
) => {
setFromStation(toStation);
setToStation(fromStation);
};

const createStationIndex = () => {
const index: Record<string, Station> = {};
Object.values({ ...rtStations, ...busStations }).forEach((line) => {
Expand Down
2 changes: 1 addition & 1 deletion modules/dashboard/HomescreenWidgetTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import classNames from 'classnames';
import Link from 'next/link';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faChevronRight } from '@fortawesome/free-solid-svg-icons';
import { mbtaTextConfig } from '../../common/components/inputs/styles/tailwind';
import {
useDelimitatedRoute,
useGenerateHref,
Expand All @@ -13,6 +12,7 @@ import { LINE_COLORS } from '../../common/constants/colors';
import type { Page } from '../../common/constants/pages';
import { ALL_PAGES } from '../../common/constants/pages';
import { getSelectedDates } from '../../common/state/utils/dateStoreUtils';
import { mbtaTextConfig } from '../../common/styles/general';

interface HomescreenWidgetTitle {
title: string;
Expand Down

0 comments on commit 54ccb64

Please sign in to comment.