-
Notifications
You must be signed in to change notification settings - Fork 7
Fix ESLint configuration, fix errors, add as GitHub action #232
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
base: main
Are you sure you want to change the base?
Changes from 14 commits
bdab6c4
7c03b77
dd5acb3
1cd3610
1ca7d1c
f881109
e865dc1
5d3adaa
9e09bb4
3e17928
427fc7a
f11003d
1b985a6
874db79
3b978d6
cd500a5
a361887
dba64f0
5aac8c9
99328e5
250f1e2
bdcb707
d497ff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: Lint Typescript | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
|
|
||
| # Run build first to ensure all files exist | ||
jmccand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - name: Build frontend | ||
| run: npm ci && npm run build | ||
|
|
||
| # Run ESLint + TypeScript checks | ||
| - name: Run lint | ||
| run: npm run lint | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,11 @@ | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import { useMemo, useEffect, useRef, useState } from "react"; | ||
| import { renderToStaticMarkup } from "react-dom/server"; | ||
| import '../styles/MapKitMap.css'; | ||
| import ShuttleIcon from "./ShuttleIcon"; | ||
|
|
||
| import type { ShuttleRouteData, ShuttleStopData } from "../ts/types/route"; | ||
| import '../styles/MapKitMap.css'; | ||
| import type { VehicleInformationMap } from "../ts/types/vehicleLocation"; | ||
| import type { Route } from "../ts/types/schedule"; | ||
| import { log } from "../ts/logger"; | ||
|
|
||
| async function generateRoutePolylines(updatedRouteData: ShuttleRouteData) { | ||
| // Use MapKit Directions API to generate polylines for each route segment | ||
|
|
@@ -108,14 +106,13 @@ type MapKitMapProps = { | |
| export default function MapKitMap({ routeData, vehicles, generateRoutes = false, selectedRoute, setSelectedRoute, isFullscreen = false }: MapKitMapProps) { | ||
| const mapRef = useRef(null); | ||
| const [mapLoaded, setMapLoaded] = useState(false); | ||
| const token = import.meta.env.VITE_MAPKIT_KEY; | ||
| const token = useMemo(() => { return (import.meta.env.VITE_MAPKIT_KEY || '') as string; }, []); | ||
| const [map, setMap] = useState<(mapkit.Map | null)>(null); | ||
| const vehicleOverlays = useRef<Record<string, mapkit.ShuttleAnnotation>>({}); | ||
|
|
||
|
|
||
| const circleWidth = 15; | ||
| const selectedMarkerRef = useRef<mapkit.MarkerAnnotation | null>(null); | ||
| const overlays: mapkit.Overlay[] = []; | ||
|
|
||
| // source: https://developer.apple.com/documentation/mapkitjs/loading-the-latest-version-of-mapkit-js | ||
| const setupMapKitJs = async () => { | ||
|
|
@@ -138,7 +135,7 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
| setMapLoaded(true); | ||
| }; | ||
| mapkitScript(); | ||
| }, []); | ||
| }, [token]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since token never changes, we shouldnt
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will change. I pass
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eslint github actions doesnt fail on warnings i thought?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think by default it doesn't, but if you pass
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to enforce 0 warnings? I feel like sometimes the warnings are fine as react dependency arrays don't really need some of the dependencies eslint is hinting at |
||
|
|
||
| // create the map | ||
| useEffect(() => { | ||
|
|
@@ -298,13 +295,14 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
| map._hoverCleanup(); | ||
| } | ||
| }; | ||
| }, [mapLoaded]); | ||
| }, [map, mapLoaded, setSelectedRoute]); | ||
jmccand marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // add fixed details to the map | ||
| // includes routes and stops | ||
| useEffect(() => { | ||
| if (!map || !routeData) return; | ||
|
|
||
| const overlays: mapkit.Overlay[] = []; | ||
|
|
||
| // display stop overlays | ||
| for (const [route, thisRouteData] of Object.entries(routeData)) { | ||
|
|
@@ -337,7 +335,7 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
|
|
||
| function displayRouteOverlays(routeData: ShuttleRouteData) { | ||
| // display route overlays | ||
| for (const [_route, thisRouteData] of Object.entries(routeData)) { | ||
| for (const [_, thisRouteData] of Object.entries(routeData)) { | ||
| // for route (WEST, NORTH) | ||
| const routePolylines = thisRouteData.ROUTES?.map( | ||
| // for segment (STOP1 -> STOP2, STOP2 -> STOP3, ...) | ||
|
|
@@ -360,7 +358,7 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
|
|
||
| if (generateRoutes) { | ||
| // generate polylines for routes | ||
| const routeDataCopy = JSON.parse(JSON.stringify(routeData)); // deep copy to avoid mutating original | ||
| const routeDataCopy = JSON.parse(JSON.stringify(routeData)) as ShuttleRouteData; | ||
| generateRoutePolylines(routeDataCopy).then((updatedRouteData) => { | ||
| displayRouteOverlays(updatedRouteData); | ||
| map.addOverlays(overlays); | ||
|
|
@@ -371,7 +369,7 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
| map.addOverlays(overlays); | ||
| } | ||
|
|
||
| }, [map, routeData]); | ||
| }, [map, routeData, generateRoutes]); | ||
|
|
||
| // display vehicles on map | ||
| useEffect(() => { | ||
|
|
@@ -391,7 +389,7 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
| const routeKey = vehicle.route_name as keyof typeof routeData; | ||
| const info = routeData[routeKey] as { COLOR?: string }; | ||
| return info.COLOR ?? "#444444"; | ||
|
|
||
| })(); | ||
|
|
||
| // Render ShuttleIcon JSX to a static SVG string | ||
|
|
@@ -405,7 +403,7 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
| existingAnnotation.subtitle = `${vehicle.speed_mph.toFixed(1)} mph`; | ||
|
|
||
| // Handle route status updates | ||
| // If shuttle does not have a route null | ||
| // If shuttle does not have a route null | ||
| if (vehicle.route_name === null) { | ||
| // shuttle off-route (exiting) | ||
| if (existingAnnotation.lockedRoute) { | ||
|
|
||
jmccand marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,52 @@ | ||
| import js from '@eslint/js' | ||
| import globals from 'globals' | ||
| import reactHooks from 'eslint-plugin-react-hooks' | ||
| import reactRefresh from 'eslint-plugin-react-refresh' | ||
| import tseslint from 'typescript-eslint' | ||
| import { defineConfig, globalIgnores } from 'eslint/config' | ||
| // eslint.config.js | ||
| import tsParser from "@typescript-eslint/parser"; | ||
| import tsPlugin from "@typescript-eslint/eslint-plugin"; | ||
| import reactPlugin from "eslint-plugin-react"; | ||
| import reactHooksPlugin from "eslint-plugin-react-hooks"; | ||
| import jsxA11yPlugin from "eslint-plugin-jsx-a11y"; | ||
|
|
||
| export default defineConfig([ | ||
| globalIgnores(['dist']), | ||
| export default [ | ||
| { | ||
| files: ['client/**/*.{ts,tsx}'], | ||
| extends: [ | ||
| js.configs.recommended, | ||
| tseslint.configs.recommended, | ||
| reactHooks.configs['recommended-latest'], | ||
| reactRefresh.configs.vite, | ||
| ], | ||
| // Ignore build and dependency folders | ||
| ignores: ["**/node_modules", "**/dist", "**/.vite"] | ||
| }, | ||
| { | ||
| files: ["client/src/**/*.{ts,tsx}"], | ||
| languageOptions: { | ||
| ecmaVersion: 2020, | ||
| globals: globals.browser, | ||
| parser: tsParser, | ||
| parserOptions: { | ||
| project: "./tsconfig.app.json", | ||
| ecmaFeatures: { jsx: true } | ||
| } | ||
| }, | ||
| plugins: { | ||
| "@typescript-eslint": tsPlugin, | ||
| "react": reactPlugin, | ||
| "react-hooks": reactHooksPlugin, | ||
| "jsx-a11y": jsxA11yPlugin | ||
| }, | ||
| rules: { | ||
| '@typescript-eslint/no-unused-vars': ['error', { varsIgnorePattern: '^_' }], | ||
| ...tsPlugin.configs.recommended.rules, | ||
| ...reactPlugin.configs.recommended.rules, | ||
| ...reactHooksPlugin.configs.recommended.rules, | ||
| ...jsxA11yPlugin.configs.recommended.rules, | ||
| "react/react-in-jsx-scope": "off", | ||
| "@typescript-eslint/no-unused-vars": [ | ||
| "warn", | ||
| { | ||
| argsIgnorePattern: "^_", | ||
| varsIgnorePattern: "^_", | ||
| caughtErrorsIgnorePattern: "^_" | ||
| } | ||
| ], | ||
| "@typescript-eslint/no-unsafe-member-access": "error", | ||
| "@typescript-eslint/no-unsafe-assignment": "warn", | ||
| "@typescript-eslint/no-unsafe-call": "warn", | ||
| }, | ||
| }, | ||
| ]) | ||
| settings: { | ||
| react: { | ||
| version: "detect", | ||
| }, | ||
| }, | ||
| } | ||
| ]; |
Uh oh!
There was an error while loading. Please reload this page.