Skip to content

Commit

Permalink
build: add eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
oterral committed Nov 3, 2023
1 parent f0f9fe0 commit 84af622
Show file tree
Hide file tree
Showing 16 changed files with 1,884 additions and 204 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/*
30 changes: 30 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
env: {
"cypress/globals": true,
node: true,
browser: true,
es6: true,
jest: true,
},
parser: "@typescript-eslint/parser",
extends: ["airbnb", "airbnb/hooks", "airbnb-typescript", "prettier"],
plugins: ["@typescript-eslint", "cypress", "prettier"],
parserOptions: {
project: "./tsconfig.json",
},
rules: {
"arrow-body-style": "off",
"react/prop-types": "off",
"react/require-default-props": "off",
"react/jsx-props-no-spreading": "off",
"react/react-in-jsx-scope": "off",
"react/jsx-one-expression-per-line": "off",
"react/jsx-filename-extension": [
"error",
{
extensions: [".js", ".jsx", ".tsx"],
},
],
"prettier/prettier": "error",
},
};
18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,35 @@
"@tailwindcss/container-queries": "^0.1.1",
"@types/geojson": "^7946.0.11",
"@types/preact-custom-element": "^4.0.3",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"concurrently": "^8.2.2",
"esbuild": "^0.19.5",
"esbuild-sass-plugin": "^2.16.0",
"eslint": "^8.52.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "17.1.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-cypress": "2.15.1",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-jsx-a11y": "6.8.0",
"eslint-plugin-prettier": "5.0.1",
"eslint-plugin-react": "7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"fixpack": "^4.0.0",
"husky": "^8.0.3",
"prettier": "^3.0.3",
"standard-version": "^9.5.0",
"tailwindcss": "^3.3.5"
"tailwindcss": "^3.3.5",
"typescript": "^5.2.2"
},
"scripts": {
"build": "yarn build:css && yarn build:js",
"build:css": "yarn tailwind:component && yarn tailwind:website",
"build:js": "node scripts/build.mjs",
"dev": "node scripts/dev.mjs",
"format": "prettier --write 'src/**/*.(tsx|ts|js)'",
"format": "prettier --write 'src/**/*.(tsx|ts|js)' && eslint src/**/*.tsx --fix ",
"lint": "eslint src/**/*.tsx",
"prepare": "husky install",
"publish:beta": "HUSKY=0 yarn release -- --prerelease beta --skip.changelog && yarn run build && HUSKY=0 yarn publish --access public --tag beta && git push origin HEAD && git push --tags ",
"publish:beta:dryrun": "yarn release -- --prerelease beta --dry-run --skip.changelog",
Expand Down
8 changes: 4 additions & 4 deletions src/BaseLayer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { MaplibreLayer } from "mobility-toolbox-js/ol";
import useMapContext from "../utils/hooks/useMapContext";
import { useEffect } from "preact/hooks";
import { memo } from "preact/compat";
import { MobilityMapProps } from "../MobilityMap";
import useMapContext from "../utils/hooks/useMapContext";
import type { MobilityMapProps } from "../MobilityMap";

function BaseLayer({ baselayer = "travic_v2", apikey }: MobilityMapProps) {
const mapContext = useMapContext();
const { map, setBaseLayer } = mapContext;
useEffect(() => {
if (!map || !baselayer || !apikey) {
return;
return () => {};
}
const layer = new MaplibreLayer({
apiKey: apikey,
Expand All @@ -21,7 +21,7 @@ function BaseLayer({ baselayer = "travic_v2", apikey }: MobilityMapProps) {
return () => {
layer.detachFromMap();
};
}, [map, baselayer, apikey]);
}, [map, baselayer, apikey, setBaseLayer]);

return null;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Copyright/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ function Copyright({ options, ...props }: CopyrightProps) {
div.className = "flex flex-wrap-reverse justify-end";

return new CopyrightControl({
target: target,
target,
element: div,
...options,
});
}, [options, target]);

useEffect(() => {
let keys = [];
if (!map || !control) {
return;
return () => {};
}
control.attachToMap(map);

Expand Down
9 changes: 5 additions & 4 deletions src/GeolocationButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Geolocation, Map } from "ol";
import { Geolocation } from "ol";
import { unByKey } from "ol/Observable";
import { fromLonLat } from "ol/proj";
import { useEffect, useMemo } from "preact/hooks";
Expand All @@ -21,7 +21,7 @@ function GeolocationButton({ ...props }: GeolocationButtonProps) {
useEffect(() => {
let keys = [];
if (!map || !geolocation) {
return;
return () => {};
}
keys = [
// First time we zoom and center on the position
Expand Down Expand Up @@ -52,6 +52,7 @@ function GeolocationButton({ ...props }: GeolocationButtonProps) {

return (
<button
type="button"
className="bg-white shadow-lg rounded-full p-1"
onClick={() => {
setIsTracking(!isTracking);
Expand All @@ -62,14 +63,14 @@ function GeolocationButton({ ...props }: GeolocationButtonProps) {
className={isTracking ? "animate-pulse" : ""}
stroke="currentColor"
fill="currentColor"
stroke-width="0"
strokeWidth="0"
viewBox="0 0 512 512"
focusable="false"
height="1.5em"
width="1.5em"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M256 56c110.532 0 200 89.451 200 200 0 110.532-89.451 200-200 200-110.532 0-200-89.451-200-200 0-110.532 89.451-200 200-200m0-48C119.033 8 8 119.033 8 256s111.033 248 248 248 248-111.033 248-248S392.967 8 256 8zm0 168c-44.183 0-80 35.817-80 80s35.817 80 80 80 80-35.817 80-80-35.817-80-80-80z"></path>
<path d="M256 56c110.532 0 200 89.451 200 200 0 110.532-89.451 200-200 200-110.532 0-200-89.451-200-200 0-110.532 89.451-200 200-200m0-48C119.033 8 8 119.033 8 256s111.033 248 248 248 248-111.033 248-248S392.967 8 256 8zm0 168c-44.183 0-80 35.817-80 80s35.817 80 80 80 80-35.817 80-80-35.817-80-80-80z" />
</svg>
</button>
);
Expand Down
8 changes: 8 additions & 0 deletions src/I18NContext/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createContext } from "preact";

export type UseI18NContextType = {
t: (id: string) => string;
};

const I18nContext = createContext({ t: () => {} });
export default I18nContext;
14 changes: 6 additions & 8 deletions src/Map/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { Map as OlMap } from "ol";
import { useEffect, useRef } from "preact/hooks";
import useMapContext from "../utils/hooks/useMapContext";
import { memo } from "preact/compat";
import type { MobilityMapProps } from "../MobilityMap";
import { PreactDOMAttributes, JSX } from "preact";

// @ts-ignore
import olStyle from "ol/ol.css";
import type { MobilityMapProps } from "../MobilityMap";
import useMapContext from "../utils/hooks/useMapContext";

export type RealtimeMapProps = PreactDOMAttributes &
JSX.HTMLAttributes<HTMLDivElement> &
MobilityMapProps;

const TRACKING_ZOOM = 16;

function Map({
apikey,
baselayer = "travic_v2",
center = "831634,5933959",
zoom = "13",
minzoom,
Expand All @@ -30,16 +27,17 @@ function Map({
const { map, setMap } = useMapContext();

useEffect(() => {
let newMap: OlMap;
if (mapRef.current) {
const newMap = new OlMap({ target: mapRef.current, controls: [] });
newMap = new OlMap({ target: mapRef.current, controls: [] });
setMap(newMap);
}

return () => {
map.setTarget();
newMap?.setTarget();
setMap();
};
}, []);
}, [setMap]);

useEffect(() => {
if (!map) {
Expand Down
58 changes: 27 additions & 31 deletions src/MobilityMap/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { createContext } from "preact";
import { memo } from "preact/compat";
import { useMemo, useState } from "preact/hooks";
import { Map as OlMap } from "ol";
import {
MaplibreLayer,
RealtimeLayer as MbtRealtimeLayer,
} from "mobility-toolbox-js/ol";
import rosetta from "rosetta";
// @ts-ignore
import tailwind from "../style.css";
// @ts-ignore
import style from "./index.css";
import Map from "../Map";
import { useState } from "preact/hooks";
import NotificationLayer from "../NotificationLayer";
import RouteSchedule from "../RouteSchedule";
import GeolocationButton from "../GeolocationButton";
import BaseLayer from "../BaseLayer";
import { MapContext } from "../utils/hooks/useMapContext";
import RealtimeLayer from "../RealtimeLayer";
import Overlay from "../Overlay";
import { Map as OlMap } from "ol";
import {
MaplibreLayer,
RealtimeLayer as MbtRealtimeLayer,
} from "mobility-toolbox-js/ol";
import ScaleLine from "../ScaleLine";
import Copyright from "../Copyright";
import I18nContext from "../I18NContext";

const i18n = rosetta({
de: {
Expand Down Expand Up @@ -52,8 +52,6 @@ i18n.locale(
?.split("-")[0] || "en",
);

export const I18nContext = createContext(i18n);

export type MobilityMapProps = {
apikey: string;
baselayer?: string;
Expand Down Expand Up @@ -84,26 +82,28 @@ function MobilityMap({
const [realtimeLayer, setRealtimeLayer] = useState<MbtRealtimeLayer>();
const [map, setMap] = useState<OlMap>();

const mapContextValue = useMemo(() => {
return {
baseLayer,
isFollowing,
isTracking,
lineInfos,
map,
realtimeLayer,
setBaseLayer,
setIsFollowing,
setIsTracking,
setLineInfos,
setMap,
setRealtimeLayer,
};
}, [baseLayer, isFollowing, isTracking, lineInfos, map, realtimeLayer]);

return (
<I18nContext.Provider value={i18n}>
<style>{tailwind}</style>
<style>{style}</style>
<MapContext.Provider
value={{
baseLayer,
isFollowing,
isTracking,
lineInfos,
map,
realtimeLayer,
setBaseLayer,
setIsFollowing,
setIsTracking,
setLineInfos,
setMap,
setRealtimeLayer,
}}
>
<MapContext.Provider value={mapContextValue}>
<div className="@container/main w-full h-full relative border">
<div className="w-full h-full relative flex flex-col @lg/main:flex-row-reverse">
<Map className="flex-1 relative overflow-hidden " {...props}>
Expand All @@ -114,12 +114,8 @@ function MobilityMap({
<GeolocationButton />
</div>
<div className="z-10 absolute left-2 right-2 text-[10px] bottom-2 flex justify-between items-end gap-2">
<ScaleLine
className={"bg-slate-50 bg-opacity-70"}
></ScaleLine>
<Copyright
className={"bg-slate-50 bg-opacity-70"}
></Copyright>
<ScaleLine className="bg-slate-50 bg-opacity-70" />
<Copyright className="bg-slate-50 bg-opacity-70" />
</div>
</Map>
<Overlay
Expand Down
5 changes: 3 additions & 2 deletions src/NotificationLayer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useMemo, useState } from "preact/hooks";
import useMapContext from "../utils/hooks/useMapContext";
import { MobilityMapProps } from "../MobilityMap";
import type { MobilityMapProps } from "../MobilityMap";
import useZoom from "../utils/hooks/useZoom";
import {
addNotificationsLayers,
Expand Down Expand Up @@ -45,7 +45,7 @@ const useNotifications = ({
} else {
setStyleMetadata(baseLayer.mbMap?.getStyle()?.metadata);
}
}, [baseLayer]);
}, [baseLayer, baselayer]);

const now = useMemo(() => {
return notificationat ? new Date(notificationat) : new Date();
Expand Down Expand Up @@ -143,6 +143,7 @@ const useNotifications = ({
styleMetadata,
zoom,
graphMapping,
baseLayer,
]);

return notifications;
Expand Down
7 changes: 3 additions & 4 deletions src/Overlay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PreactDOMAttributes, JSX } from "preact";
import ScrollableHandler, {
ScrollableHandlerProps,
} from "../ScrollableHandler";
import ScrollableHandler from "../ScrollableHandler";
import type { ScrollableHandlerProps } from "../ScrollableHandler";

export type OverlayProps = PreactDOMAttributes &
JSX.HTMLAttributes<HTMLDivElement> & {
Expand Down Expand Up @@ -31,7 +30,7 @@ function Overlay({ children, ScrollableHandlerProps = {} }: OverlayProps) {
height: 4,
borderRadius: 2,
}}
></div>
/>
</ScrollableHandler>
{children}
</>
Expand Down
Loading

1 comment on commit 84af622

@vercel
Copy link

@vercel vercel bot commented on 84af622 Nov 3, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.