From eca190fb7a3f65868f7a4bca0a562624e5da27b8 Mon Sep 17 00:00:00 2001 From: viet nguyen Date: Thu, 21 Sep 2023 13:40:02 -0700 Subject: [PATCH] refactor: upgrade ts-standard and autofix --- .../postLoginAction/setDefaultRoles-step0.js | 2 +- jest.config.js | 2 +- package.json | 12 +- src/components/GitHubStars.tsx | 2 +- src/components/area/panel/listItem.tsx | 2 +- src/components/area/panel/panelOverview.tsx | 2 +- src/components/basecamp/Users.tsx | 2 +- src/components/crag/ClimbListPreview.tsx | 2 +- src/components/crag/disciplineDist.tsx | 2 +- src/components/crag/mediumHistogram.tsx | 2 +- src/components/crag/tinyHistogram.tsx | 2 +- src/components/edit/AddChildAreaForm.tsx | 2 +- src/components/edit/Triggers.tsx | 2 +- .../editor/__tests__/InplaceTextInput.tsx | 1 + src/components/finder/CragRow.tsx | 2 +- src/components/lco/PageBanner.tsx | 4 +- src/components/logbook/OverviewChart.tsx | 2 +- src/components/logbook/Stats.tsx | 2 +- src/components/maps/BaseMap.tsx | 2 +- src/components/maps/CragsMap.tsx | 2 +- src/components/maps/ui/PieIcon.tsx | 2 +- src/components/media/Tag.tsx | 2 +- src/components/search/Autocomplete.tsx | 2 +- src/components/search/Autocomplete2.tsx | 4 +- src/components/search/CragsNearBy.tsx | 6 +- src/components/search/ResultTemplates.tsx | 2 +- src/components/search/sources/PoiSource.tsx | 2 +- src/components/search/sources/PoiSource2.tsx | 4 +- .../sources/TypesenseXSearchSources.tsx | 2 +- src/components/ui/BaseButton.tsx | 2 +- src/components/ui/ComboBox.tsx | 2 +- src/components/ui/RadiusRangeSlider.tsx | 4 +- src/components/ui/Statistics/DensityBar.tsx | 2 +- src/components/users/FavouriteButton.tsx | 2 +- src/components/users/TickCard.tsx | 2 +- src/components/users/TickForm.tsx | 10 +- src/js/GeoHelpers.ts | 4 +- src/js/auth/CurrentUserClient.ts | 4 +- src/js/graphql/Client.ts | 8 +- src/js/graphql/api.ts | 4 +- src/js/graphql/contribAPI.ts | 2 +- src/js/graphql/gql/contribs.ts | 8 +- src/js/hooks/useMediaCmd.tsx | 4 +- src/js/hooks/useUpdateAreasCmd.tsx | 4 +- src/js/stores/media.ts | 2 +- src/js/stores/wizards.ts | 6 +- src/js/types.ts | 4 +- src/js/types/INext.ts | 2 +- src/js/types/User.ts | 2 +- src/js/utils.ts | 8 +- src/pages/api/user/fav.ts | 4 +- src/pages/api/user/metadataClient.ts | 6 +- src/pages/api/user/ticks.ts | 2 - src/pages/areas/[id].tsx | 2 +- src/pages/climbs/[id].tsx | 4 +- src/pages/p/[...slug].tsx | 2 +- src/pages/u2/[...slug].tsx | 2 +- yarn.lock | 1372 +++++++++++------ 58 files changed, 987 insertions(+), 570 deletions(-) diff --git a/AuthProvider/postLoginAction/setDefaultRoles-step0.js b/AuthProvider/postLoginAction/setDefaultRoles-step0.js index a058fb55a..bf8d74120 100644 --- a/AuthProvider/postLoginAction/setDefaultRoles-step0.js +++ b/AuthProvider/postLoginAction/setDefaultRoles-step0.js @@ -30,7 +30,7 @@ exports.onExecutePostLogin = async ({ secrets, user, authorization, stats }, api clientSecret: secrets.clientSecret, scope: 'update:roles' }) - + const params = { id: user.user_id } const data = { roles: [EDITOR_ROLE_ID] } diff --git a/jest.config.js b/jest.config.js index b2e513f87..dcb7716b5 100644 --- a/jest.config.js +++ b/jest.config.js @@ -10,7 +10,7 @@ const createJestConfig = nextJest({ // Add any custom config to be passed to Jest const customJestConfig = { setupFilesAfterEnv: ['/setupTests.ts'], - testEnvironment: 'jest-environment-jsdom', + testEnvironment: 'jest-environment-jsdom' // moduleDirectories: ['node_modules', '/'], diff --git a/package.json b/package.json index 0ace15af5..752fef438 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,6 @@ "@radix-ui/react-tabs": "^1.0.1", "@radix-ui/react-toggle": "^1.0.1", "@turf/bbox": "^6.5.0", - "@types/underscore": "^1.11.4", - "@types/uuid": "^8.3.4", "@udecode/zustood": "^1.1.3", "auth0": "^2.42.0", "awesome-debounce-promise": "^2.1.0", @@ -49,7 +47,6 @@ "next": "12.3.4", "next-auth": "^4.22.1", "nprogress": "^0.2.0", - "raw-body": "^2.5.1", "rc-slider": "^10.0.0-alpha.5", "react": "^18.0.0", "react-content-loader": "^6.2.0", @@ -107,6 +104,8 @@ "@types/nprogress": "^0.2.0", "@types/react": "^18.0.9", "@types/react-beautiful-dnd": "^13.1.0", + "@types/underscore": "^1.11.9", + "@types/uuid": "^9.0.4", "autoprefixer": "^10.4.1", "eslint-plugin-jest": "^27.1.4", "husky": "^7.0.4", @@ -117,7 +116,7 @@ "react-test-renderer": "^18.0.0", "resize-observer-polyfill": "^1.5.1", "tailwindcss": "^3.1.8", - "ts-standard": "11.0.0", + "ts-standard": "^12.0.2", "typescript": "4.9.5" }, "repository": { @@ -135,9 +134,8 @@ "plugins": [ "jest" ], - "envs": { - "browser": true, - "es2021": true + "environment": { + "browser": true }, "files": [ "src/**/*.js", diff --git a/src/components/GitHubStars.tsx b/src/components/GitHubStars.tsx index 7f4fc87ee..6e3f0f854 100644 --- a/src/components/GitHubStars.tsx +++ b/src/components/GitHubStars.tsx @@ -6,7 +6,7 @@ import GithubIcon from '../assets/icons/github.inline.svg' * Render GitHub stargazers button */ const GitHubStars: React.FC = () => { - const { data } = useSWRImmutable<{ stargazers_count: number}>('https://api.github.com/repos/openbeta/open-tacos', fetcher) + const { data } = useSWRImmutable<{ stargazers_count: number }>('https://api.github.com/repos/openbeta/open-tacos', fetcher) return ( diff --git a/src/components/area/panel/listItem.tsx b/src/components/area/panel/listItem.tsx index 01c16d083..85813833a 100644 --- a/src/components/area/panel/listItem.tsx +++ b/src/components/area/panel/listItem.tsx @@ -40,7 +40,7 @@ export interface ListItemProps extends ListItemEntity { * use-cases. You'll need to change this to account for overflow rules after the * state is expanded. */ -function Expandable (props: {expand: boolean, children: any}): JSX.Element { +function Expandable (props: { expand: boolean, children: any }): JSX.Element { const ref = React.useRef(null) const contentHeight = ref.current !== null ? ref.current?.clientHeight : 0 diff --git a/src/components/area/panel/panelOverview.tsx b/src/components/area/panel/panelOverview.tsx index ba127342b..9e267aac7 100644 --- a/src/components/area/panel/panelOverview.tsx +++ b/src/components/area/panel/panelOverview.tsx @@ -3,7 +3,7 @@ import { ListItemEntity } from './listItem' import { BarChart, Bar, Cell, XAxis, Tooltip, ResponsiveContainer } from 'recharts' import { CategoricalChartState } from 'recharts/types/chart/generateCategoricalChart' -const CustomTooltip: React.FC = (data: {label: string, payload: any[] }) => { +const CustomTooltip: React.FC = (data: { label: string, payload: any[] }) => { let tags: Array<[string, number]> = [] if (data?.payload?.length > 0) { diff --git a/src/components/basecamp/Users.tsx b/src/components/basecamp/Users.tsx index 8787e3ffd..00dd64232 100644 --- a/src/components/basecamp/Users.tsx +++ b/src/components/basecamp/Users.tsx @@ -44,7 +44,7 @@ export default function Users (): JSX.Element { ) } -const LinkProfile = ({ nick }: {nick: string}): JSX.Element => {nick} +const LinkProfile = ({ nick }: { nick: string }): JSX.Element => {nick} const fetcher = async (url: string): Promise => (await axios.get(url)).data interface HtmlFormProps { diff --git a/src/components/crag/ClimbListPreview.tsx b/src/components/crag/ClimbListPreview.tsx index 3ff721112..4f3720189 100644 --- a/src/components/crag/ClimbListPreview.tsx +++ b/src/components/crag/ClimbListPreview.tsx @@ -67,7 +67,7 @@ export const ClimbListPreview = ({ editable }: Props): JSX.Element => { ) } -type ClimbEntryDirtyType = Record +type ClimbEntryDirtyType = Record type ClimbEntryProps = EditableClimbTypeWithFieldId & { index: number defaultDict?: Dictionary diff --git a/src/components/crag/disciplineDist.tsx b/src/components/crag/disciplineDist.tsx index 650f5df51..ee40f5f57 100644 --- a/src/components/crag/disciplineDist.tsx +++ b/src/components/crag/disciplineDist.tsx @@ -7,7 +7,7 @@ interface DisiplineDistributionProps { } export default function DisciplineDistribution (props: DisiplineDistributionProps): JSX.Element { - const data: Array<{value: number, label: string}> = Object.keys(props.data) + const data: Array<{ value: number, label: string }> = Object.keys(props.data) .filter(i => i !== '__typename') .map(key => { return { diff --git a/src/components/crag/mediumHistogram.tsx b/src/components/crag/mediumHistogram.tsx index 7eec19c4a..2384936a4 100644 --- a/src/components/crag/mediumHistogram.tsx +++ b/src/components/crag/mediumHistogram.tsx @@ -18,7 +18,7 @@ interface MediumHistogramProps { columnLabels?: string[] } -function Column ({ val, vert, label }: {val: number, vert: number, label?: string}): JSX.Element { +function Column ({ val, vert, label }: { val: number, vert: number, label?: string }): JSX.Element { const cells = Array(vert).fill(0).map((_, index) => { if (index < val) { return false diff --git a/src/components/crag/tinyHistogram.tsx b/src/components/crag/tinyHistogram.tsx index 5f05eb27f..47ada6a19 100644 --- a/src/components/crag/tinyHistogram.tsx +++ b/src/components/crag/tinyHistogram.tsx @@ -16,7 +16,7 @@ interface TinyHistogramProps { title?: string } -function Column ({ val, vert }: {val: number, vert: number}): JSX.Element { +function Column ({ val, vert }: { val: number, vert: number }): JSX.Element { const cells = Array(vert).fill(0).map((_, index) => { if (index < val) { return false diff --git a/src/components/edit/AddChildAreaForm.tsx b/src/components/edit/AddChildAreaForm.tsx index 20bc1a267..cc5321608 100644 --- a/src/components/edit/AddChildAreaForm.tsx +++ b/src/components/edit/AddChildAreaForm.tsx @@ -91,7 +91,7 @@ const Step1 = (props: ChildAreaBaseProps): JSX.Element => { // Form declaration const form = useForm({ mode: 'onSubmit', - defaultValues: { newAreaName: '', shortCode: '', parentName: parentName } + defaultValues: { newAreaName: '', shortCode: '', parentName } }) const { handleSubmit, formState: { isSubmitting, isSubmitSuccessful }, setFocus } = form diff --git a/src/components/edit/Triggers.tsx b/src/components/edit/Triggers.tsx index 880234b7c..e2fe7e48a 100644 --- a/src/components/edit/Triggers.tsx +++ b/src/components/edit/Triggers.tsx @@ -88,7 +88,7 @@ export const DeleteAreaTriggerButtonSm = ({ disabled }: TriggerButtonProps): JSX ) -export type AddAreaTriggerProps = Omit & { children?: JSX.Element} +export type AddAreaTriggerProps = Omit & { children?: JSX.Element } /** * A high level component that triggers the Add Area dialog. See {@link DeleteAreaTrigger} for a customization example. diff --git a/src/components/editor/__tests__/InplaceTextInput.tsx b/src/components/editor/__tests__/InplaceTextInput.tsx index b72ab0694..4efed6004 100644 --- a/src/components/editor/__tests__/InplaceTextInput.tsx +++ b/src/components/editor/__tests__/InplaceTextInput.tsx @@ -1,4 +1,5 @@ import React from 'react' +import '@testing-library/jest-dom' import { render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import InplaceTextInput from '../InplaceTextInput' diff --git a/src/components/finder/CragRow.tsx b/src/components/finder/CragRow.tsx index 4a98dca0e..20327c16d 100644 --- a/src/components/finder/CragRow.tsx +++ b/src/components/finder/CragRow.tsx @@ -7,7 +7,7 @@ import { MiniCrumbs } from '../ui/BreadCrumbs' import useResponsive from '../../js/hooks/useResponsive' import { cragFiltersStore } from '../../js/stores' -type CragRowProps = Pick +type CragRowProps = Pick export default function CragRow ({ areaName, totalClimbs, metadata, aggregate, pathTokens }: CragRowProps): JSX.Element { const getClimbsForYou = cragFiltersStore.get.inMyRangeCount(aggregate) diff --git a/src/components/lco/PageBanner.tsx b/src/components/lco/PageBanner.tsx index affeb3d0f..42add87e3 100644 --- a/src/components/lco/PageBanner.tsx +++ b/src/components/lco/PageBanner.tsx @@ -25,7 +25,7 @@ export interface LCOProfileType { donation?: string } -interface PageBannerProps{orgs: OrganizationType[]} +interface PageBannerProps {orgs: OrganizationType[]} const getLcoList = (orgs: OrganizationType[]): LCOProfileType[] => { return orgs.filter(org => org.orgType === 'LOCAL_CLIMBING_ORGANIZATION') @@ -80,7 +80,7 @@ export const PageBanner: React.FC = ({ orgs }) => { ) } -const LcoCardTrigger: React.FC<{ profile: LCOProfileType}> = ({ profile }): JSX.Element => { +const LcoCardTrigger: React.FC<{ profile: LCOProfileType }> = ({ profile }): JSX.Element => { return ( diff --git a/src/components/logbook/OverviewChart.tsx b/src/components/logbook/OverviewChart.tsx index e73c58b95..00e1ea401 100644 --- a/src/components/logbook/OverviewChart.tsx +++ b/src/components/logbook/OverviewChart.tsx @@ -150,7 +150,7 @@ const xAxisFormatter = (data: any): any => { /** * Make median score looks like a candle stick */ -const CustomizeMedianDot: React.FC = (props) => { +const CustomizeMedianDot: React.FC = (props) => { const { cx, cy, payload } = props if (cx == null || cy == null || payload == null) return null const lengthOffset = payload.total * 1.2 diff --git a/src/components/logbook/Stats.tsx b/src/components/logbook/Stats.tsx index d9a1bf2d6..e88871ab6 100644 --- a/src/components/logbook/Stats.tsx +++ b/src/components/logbook/Stats.tsx @@ -2,7 +2,7 @@ import { groupBy } from 'underscore' import { formatDistanceToNowStrict, format, endOfDay, differenceInCalendarDays } from 'date-fns' import { TickType } from '../../js/types' -const Stats: React.FC<{ tickList: TickType[]}> = ({ tickList }) => { +const Stats: React.FC<{ tickList: TickType[] }> = ({ tickList }) => { const sortedList = tickList const total = tickList.length const totalTime = formatDistanceToNowStrict(sortedList[0].dateClimbed) diff --git a/src/components/maps/BaseMap.tsx b/src/components/maps/BaseMap.tsx index 447174632..adec5fbbe 100644 --- a/src/components/maps/BaseMap.tsx +++ b/src/components/maps/BaseMap.tsx @@ -105,7 +105,7 @@ export default function BaseMap ({ onMove={onMoveHandler} onLoad={onMapLoad} interactive - style={{ height: height }} + style={{ height }} ref={mapRef} > {children} diff --git a/src/components/maps/CragsMap.tsx b/src/components/maps/CragsMap.tsx index 840709e02..3e5e11db1 100644 --- a/src/components/maps/CragsMap.tsx +++ b/src/components/maps/CragsMap.tsx @@ -20,7 +20,7 @@ export default function CragsMap (): JSX.Element { const [viewstate, height, setViewState] = useAutoSizing({ geojson, elementId: mapElementId }) // track current mouseover marker - const [hoverMarker, setHoverMarker] = useState(null) + const [hoverMarker, setHoverMarker] = useState(null) const onHoverHandler = useCallback((event: MapLayerMouseEvent) => { const { features } = event diff --git a/src/components/maps/ui/PieIcon.tsx b/src/components/maps/ui/PieIcon.tsx index b1abab6c9..f543eae59 100644 --- a/src/components/maps/ui/PieIcon.tsx +++ b/src/components/maps/ui/PieIcon.tsx @@ -35,7 +35,7 @@ export function getTotal (aggregatedTypes: Array<[string, number]>): number { }, 0) } -export function getPieIcon ({ data, text }: {data: PieData, text: string}): string { +export function getPieIcon ({ data, text }: { data: PieData, text: string }): string { const padding = 20 const radius = 55 const center = [radius + padding, radius + padding] diff --git a/src/components/media/Tag.tsx b/src/components/media/Tag.tsx index f45144a20..3fcd8a8db 100644 --- a/src/components/media/Tag.tsx +++ b/src/components/media/Tag.tsx @@ -39,7 +39,7 @@ export default function Tag ({ mediaId, tag, onDelete, size = 'md', showDelete =