From 2cd41cc15f21bf60eb1092fd2049a3fe3b0467bb Mon Sep 17 00:00:00 2001 From: Erik Hetland Date: Wed, 18 Oct 2023 18:49:50 +0200 Subject: [PATCH] Add eslint and fix most errors --- .eslintrc.js | 25 + package.json | 7 + src/App.tsx | 2 +- .../ErrorBoundary/ErrorBoundary.tsx | 4 +- src/components/MusicPlayer/MusicPlayer.tsx | 2 +- src/components/Textarea/Textarea.tsx | 2 +- src/context/Auth.tsx | 4 +- .../views/CompetitionAdminEdit.tsx | 32 +- .../views/CompetitionAdminEntry.tsx | 15 +- .../views/CompetitionAdminOverview.tsx | 14 +- .../CompetitionLinksEdit.tsx | 3 +- .../CompetitionLinksEdit/Link.tsx | 2 - .../ContributorEditor/Contributor.tsx | 6 +- .../ContributorEditor/ContributorEditor.tsx | 4 +- .../CreateCompetition/GeneralSettings.tsx | 6 +- .../competitions/CreateCompetition/Misc.tsx | 27 +- .../CreateCompetition/SelectGenre.tsx | 2 +- .../EditRegistration/EditRegistration.tsx | 2 +- src/features/competitions/FileEdit/File.tsx | 2 +- .../competitions/FileUpload/UploadForm.tsx | 5 +- .../competitions/PrizeEdit/PrizeEdit.tsx | 2 +- .../competitions/VoteCard/RateStars.tsx | 1 - .../competitions/VoteCard/VoteCard.tsx | 3 +- src/utils/fetcher.ts | 2 +- src/views/CompetitionDetails.tsx | 20 +- src/views/CompetitionOverview.tsx | 2 +- src/views/CompetitionRegistration.tsx | 26 +- src/views/CompetitionVote.tsx | 8 +- yarn.lock | 1545 ++++++++++++++++- 29 files changed, 1651 insertions(+), 124 deletions(-) create mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..3ccd234 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,25 @@ +/** @type {import('eslint').Linter.Config} */ +module.exports = { + root: true, + extends: [ + // By extending from a plugin config, we can get recommended rules without having to add them manually. + 'eslint:recommended', + 'plugin:jsx-a11y/recommended', + 'plugin:@typescript-eslint/recommended', + // This disables the formatting rules in ESLint that Prettier is going to be responsible for handling. + // Make sure it's always the last config, so it gets the chance to override other configs. + 'eslint-config-prettier', + ], + ignorePatterns: ['*.css'], + overrides: [ + { + files: ['*.ts', '*.tsx', '*.js', '*.jsx'], + parser: '@typescript-eslint/parser', + }, + ], + rules: { + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/ban-ts-comment": "off", + "jsx-a11y/media-has-caption": "off" + } + }; \ No newline at end of file diff --git a/package.json b/package.json index 3e11ff8..bf17af5 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,15 @@ "@types/react-router-dom": "^5.3.2", "@types/styled-components": "^5.1.26", "@types/uuid": "^8.3.1", + "@typescript-eslint/eslint-plugin": "^6.7.4", + "@typescript-eslint/parser": "^6.7.4", "@vitejs/plugin-react": "^4.1.0", "autoprefixer": "^10.4.13", + "eslint": "^8.51.0", + "eslint-config-prettier": "^9.0.0", + "eslint-plugin-jsx-a11y": "^6.7.1", + "eslint-plugin-react": "^7.33.2", + "eslint-plugin-tailwindcss": "^3.13.0", "postcss": "^8.4.31", "prettier": "^2.8.4", "sass": "^1.58.0", diff --git a/src/App.tsx b/src/App.tsx index 223b59b..ab1f465 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo } from "react"; +import React, { useMemo } from "react"; import { Link, Outlet } from "react-router-dom"; import * as Sentry from "@sentry/react"; import { ToastContainer } from "react-toastify"; diff --git a/src/components/ErrorBoundary/ErrorBoundary.tsx b/src/components/ErrorBoundary/ErrorBoundary.tsx index ebf56dc..30c9ea3 100644 --- a/src/components/ErrorBoundary/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary/ErrorBoundary.tsx @@ -7,7 +7,7 @@ class ErrorBoundary extends React.Component { hasError: false, }; - static getDerivedStateFromError(error: Error) { + static getDerivedStateFromError() { return { hasError: true, }; @@ -28,7 +28,7 @@ class ErrorBoundary extends React.Component {

Oh noes! A dead unicorn appears!

- + {this.state.eventId && (
diff --git a/src/components/MusicPlayer/MusicPlayer.tsx b/src/components/MusicPlayer/MusicPlayer.tsx index f4af104..c2f0645 100644 --- a/src/components/MusicPlayer/MusicPlayer.tsx +++ b/src/components/MusicPlayer/MusicPlayer.tsx @@ -15,7 +15,7 @@ export const MusicPlayer = ({ src }: Props) => { useEffect(() => { if (isPlaying) { - player.play().catch((e) => { + player.play().catch(() => { setPlayerError("Could not play this file"); }); } else { diff --git a/src/components/Textarea/Textarea.tsx b/src/components/Textarea/Textarea.tsx index ec60659..f36c6dc 100644 --- a/src/components/Textarea/Textarea.tsx +++ b/src/components/Textarea/Textarea.tsx @@ -1,4 +1,4 @@ -import { ChangeEvent, ChangeEventHandler, forwardRef, InputHTMLAttributes, TextareaHTMLAttributes, useId } from "react"; +import { ChangeEventHandler, forwardRef, TextareaHTMLAttributes, useId } from "react"; import styled from "styled-components"; interface Props extends Omit, "onChange"> { diff --git a/src/context/Auth.tsx b/src/context/Auth.tsx index bb5c543..def0167 100644 --- a/src/context/Auth.tsx +++ b/src/context/Auth.tsx @@ -174,7 +174,7 @@ export const UserProvider = ({ children }: UserProviderProps) => { dispatch({ type: "SET_FETCH_STATUS", status: "resolved" }); dispatch({ type: "SET_ACCESS_TOKEN", token: d.access_token }); }) - .catch((e) => { + .catch(() => { dispatch({ type: "SET_FETCH_STATUS", status: "rejected" }); dispatch({ type: "SET_ACCESS_TOKEN" }); }); @@ -232,7 +232,7 @@ export const useLogin = (code: string | null) => { dispatch({ type: "SET_ACCESS_TOKEN", token: d.access_token }); navigate("/"); }) - .catch((e) => { + .catch(() => { dispatch({ type: "SET_FETCH_STATUS", status: "rejected" }); dispatch({ type: "SET_ACCESS_TOKEN" }); }); diff --git a/src/features/competitionAdmin/views/CompetitionAdminEdit.tsx b/src/features/competitionAdmin/views/CompetitionAdminEdit.tsx index 4eef023..5ac73a0 100644 --- a/src/features/competitionAdmin/views/CompetitionAdminEdit.tsx +++ b/src/features/competitionAdmin/views/CompetitionAdminEdit.tsx @@ -117,10 +117,12 @@ const CompetitionAdminEdit = () => { required: "You must give the competition a start time", }} render={({ field }) => { - const { value, ref, ...props } = field; + const { value, ...props } = field; return (
- + {errors.run_time_start && (
)} diff --git a/src/features/competitionAdmin/views/CompetitionAdminOverview.tsx b/src/features/competitionAdmin/views/CompetitionAdminOverview.tsx index 1dc2513..4058b19 100644 --- a/src/features/competitionAdmin/views/CompetitionAdminOverview.tsx +++ b/src/features/competitionAdmin/views/CompetitionAdminOverview.tsx @@ -1,20 +1,12 @@ import React from "react"; -import { toast } from "react-toastify"; import useSWR from "swr"; import { View } from "../../../components/View"; import { Link } from "../../../components/Link"; -import type { ICompetition, ICompetitionListResponse } from "../../competitions/competition"; -import { httpGet, httpPatch } from "../../../utils/fetcher"; -import { parseError } from "../../../utils/error"; +import type { ICompetitionListResponse } from "../../competitions/competition"; +import { httpGet } from "../../../utils/fetcher"; const CompetitionAdminOverview = () => { - const { data: competitions, mutate } = useSWR("competitions/competitions", httpGet); - - const togglePublish = (c: ICompetition) => () => { - httpPatch(`competitions/competitions/${c.id}`, JSON.stringify({ published: !c.published })) - .then((d) => mutate()) - .catch((err) => parseError(err).forEach((e: any) => toast.error(e))); - }; + const { data: competitions } = useSWR("competitions/competitions", httpGet); if (!competitions) { return null; diff --git a/src/features/competitions/CompetitionLinksEdit/CompetitionLinksEdit.tsx b/src/features/competitions/CompetitionLinksEdit/CompetitionLinksEdit.tsx index 32fb7f3..8c8c53c 100644 --- a/src/features/competitions/CompetitionLinksEdit/CompetitionLinksEdit.tsx +++ b/src/features/competitions/CompetitionLinksEdit/CompetitionLinksEdit.tsx @@ -2,7 +2,6 @@ import React from "react"; import { PrimaryButton, SecondaryButton } from "../../../components/Button"; import { Input } from "../../../components/Input"; import { Select } from "../../../components/Select"; -import { Link } from "./Link"; type Destinations = "twitch" | "discord" | "facebook" | "gathering.org"; @@ -64,7 +63,7 @@ export const CompetitionLinksEdit = ({ label, onChange, value }: IProps) => { value={val.href} />
- handleRemove(i)}> + handleRemove(i)}> Remove diff --git a/src/features/competitions/CompetitionLinksEdit/Link.tsx b/src/features/competitions/CompetitionLinksEdit/Link.tsx index bea0ecd..ba3145d 100644 --- a/src/features/competitions/CompetitionLinksEdit/Link.tsx +++ b/src/features/competitions/CompetitionLinksEdit/Link.tsx @@ -1,7 +1,5 @@ import React from "react"; -interface IProps {} - export const Link = () => { return <>; }; diff --git a/src/features/competitions/ContributorEditor/Contributor.tsx b/src/features/competitions/ContributorEditor/Contributor.tsx index 09791f5..e0be9b4 100644 --- a/src/features/competitions/ContributorEditor/Contributor.tsx +++ b/src/features/competitions/ContributorEditor/Contributor.tsx @@ -1,8 +1,8 @@ -import { FormEventHandler, useRef, useState } from "react"; +import { FormEventHandler, useState } from "react"; import { toast } from "react-toastify"; import { Input } from "../../../components/Input"; import type { User } from "../../../context/Auth"; -import { httpDelete, httpPatch, httpPut } from "../../../utils/fetcher"; +import { httpDelete, httpPatch } from "../../../utils/fetcher"; import type { Contributor as IContributor, IEntry } from "../competition"; interface Props { @@ -33,7 +33,7 @@ export const Contributor = ({ contributor, contributorExtra, user, entry, revali .then(() => { toast.success("Contributor updated"); }) - .catch((err) => { + .catch(() => { toast.error("Something went wrong updating the contributor"); }); }; diff --git a/src/features/competitions/ContributorEditor/ContributorEditor.tsx b/src/features/competitions/ContributorEditor/ContributorEditor.tsx index a6755c9..d1a279e 100644 --- a/src/features/competitions/ContributorEditor/ContributorEditor.tsx +++ b/src/features/competitions/ContributorEditor/ContributorEditor.tsx @@ -22,7 +22,7 @@ export const ContributorEditor = ({ contributorExtra, entry, competition, revali const [searchInput, setSearchInput] = useState(""); const [addContributorError, setAddContributorError] = useState>(); - const { data, isLoading } = useSWR<{ + const { data } = useSWR<{ count: number; next: null | number; previous: null | number; @@ -60,7 +60,7 @@ export const ContributorEditor = ({ contributorExtra, entry, competition, revali is_owner: false, }) ) - .then((res) => { + .then(() => { setShowAddContributor(false); revalidate(); }) diff --git a/src/features/competitions/CreateCompetition/GeneralSettings.tsx b/src/features/competitions/CreateCompetition/GeneralSettings.tsx index 24ffacd..cf652d5 100644 --- a/src/features/competitions/CreateCompetition/GeneralSettings.tsx +++ b/src/features/competitions/CreateCompetition/GeneralSettings.tsx @@ -18,7 +18,7 @@ const initialDate = addHours(new Date(), 1); initialDate.setMinutes(0, 0, 0); export const GeneralSettings = ({ onForward, onPrevious }: IProps) => { - const { register, formState, handleSubmit, control, watch } = useFormContext(); + const { register, formState, handleSubmit, control } = useFormContext(); const onSubmit = () => { onForward(); @@ -65,7 +65,7 @@ export const GeneralSettings = ({ onForward, onPrevious }: IProps) => { const { value, ...props } = field; return ( <> -