diff --git a/global-scoreboard/package-lock.json b/global-scoreboard/package-lock.json index 00cb5528..dabaadd3 100644 --- a/global-scoreboard/package-lock.json +++ b/global-scoreboard/package-lock.json @@ -40,7 +40,7 @@ "async": "^3.2.4", "ejs": "^3.1.8", "eslint": "^8.23.1", - "eslint-config-beslogic": "^1.4.8", + "eslint-config-beslogic": "^1.4.12", "eslint-plugin-jsx-a11y": "^6.6.1", "eslint-plugin-react": "^7.31.8", "eslint-plugin-react-hooks": "^4.6.0", @@ -7152,9 +7152,9 @@ } }, "node_modules/eslint-config-beslogic": { - "version": "1.4.8", - "resolved": "https://registry.npmjs.org/eslint-config-beslogic/-/eslint-config-beslogic-1.4.8.tgz", - "integrity": "sha512-bPCMgz/ev7zehl3VyIxoBQpeosMxJfzaCSTo0Tj7tio3A9ivsERvMrs6+QmocfRvWHlaRrhh/HPeawNAKe/K4w==", + "version": "1.4.12", + "resolved": "https://registry.npmjs.org/eslint-config-beslogic/-/eslint-config-beslogic-1.4.12.tgz", + "integrity": "sha512-7ZdT3F3wfOSdXMkzGSUm28DmLyLKKjX8Hw3UKhPo39MZTH/grCVCv9j/dxlB010LaiBBGijFTDh61F5WjRkI8A==", "dev": true, "dependencies": { "@babel/eslint-parser": "^7.0", @@ -22890,9 +22890,9 @@ } }, "eslint-config-beslogic": { - "version": "1.4.8", - "resolved": "https://registry.npmjs.org/eslint-config-beslogic/-/eslint-config-beslogic-1.4.8.tgz", - "integrity": "sha512-bPCMgz/ev7zehl3VyIxoBQpeosMxJfzaCSTo0Tj7tio3A9ivsERvMrs6+QmocfRvWHlaRrhh/HPeawNAKe/K4w==", + "version": "1.4.12", + "resolved": "https://registry.npmjs.org/eslint-config-beslogic/-/eslint-config-beslogic-1.4.12.tgz", + "integrity": "sha512-7ZdT3F3wfOSdXMkzGSUm28DmLyLKKjX8Hw3UKhPo39MZTH/grCVCv9j/dxlB010LaiBBGijFTDh61F5WjRkI8A==", "dev": true, "requires": { "@angular-eslint/eslint-plugin": "^13.1", diff --git a/global-scoreboard/package.json b/global-scoreboard/package.json index e8d157d1..e5bd048b 100644 --- a/global-scoreboard/package.json +++ b/global-scoreboard/package.json @@ -57,7 +57,7 @@ "async": "^3.2.4", "ejs": "^3.1.8", "eslint": "^8.23.1", - "eslint-config-beslogic": "^1.4.8", + "eslint-config-beslogic": "^1.4.12", "eslint-plugin-jsx-a11y": "^6.6.1", "eslint-plugin-react": "^7.31.8", "eslint-plugin-react-hooks": "^4.6.0", diff --git a/global-scoreboard/src/Components/App.tsx b/global-scoreboard/src/Components/App.tsx index 2c7380e7..6a0b1710 100644 --- a/global-scoreboard/src/Components/App.tsx +++ b/global-scoreboard/src/Components/App.tsx @@ -32,8 +32,8 @@ const App = () => { currentUserPromise() .then((response: { user: Player | undefined }) => response.user) .then(setCurrentUser) - .catch((error: Response) => { - if (error.status === StatusCodes.UNAUTHORIZED) { + .catch((error: unknown) => { + if (error instanceof Response && error.status === StatusCodes.UNAUTHORIZED) { setCurrentUser(null) } else { console.error(error) diff --git a/global-scoreboard/src/Components/Dashboard/TableElements/PlayerNameCell.tsx b/global-scoreboard/src/Components/Dashboard/TableElements/PlayerNameCell.tsx index b12cc9d9..1a03b6bf 100644 --- a/global-scoreboard/src/Components/Dashboard/TableElements/PlayerNameCell.tsx +++ b/global-scoreboard/src/Components/Dashboard/TableElements/PlayerNameCell.tsx @@ -12,7 +12,7 @@ type PlayerNameCellProps = { } const backupFlag = (element: HTMLImageElement) => { - const backupSource = element.src.replace(/\/[\da-z]+?\.png/, '.png') + const backupSource = element.src.replace(/\/[\da-z]+\.png/u, '.png') if (backupSource.endsWith('flags.png')) { element.removeAttribute('src') } else { diff --git a/global-scoreboard/src/Components/Dashboard/UpdateMessage.tsx b/global-scoreboard/src/Components/Dashboard/UpdateMessage.tsx index b41a090c..c9921058 100644 --- a/global-scoreboard/src/Components/Dashboard/UpdateMessage.tsx +++ b/global-scoreboard/src/Components/Dashboard/UpdateMessage.tsx @@ -120,7 +120,7 @@ const UpdateMessage = (props: UpdateMessageProps) => { {typeof props.message === 'string' ? |)/gu, ' ') + ? props.message.replaceAll(/\s+||/gu, ' ') : props.message.replaceAll('\n', '
'), }} /> diff --git a/global-scoreboard/src/Components/Dashboard/UpdateRunnerForm.tsx b/global-scoreboard/src/Components/Dashboard/UpdateRunnerForm.tsx index fcc932ce..54f0f924 100644 --- a/global-scoreboard/src/Components/Dashboard/UpdateRunnerForm.tsx +++ b/global-scoreboard/src/Components/Dashboard/UpdateRunnerForm.tsx @@ -1,4 +1,3 @@ - import type { ChangeEventHandler, FormEvent } from 'react' import { useState } from 'react' import { Button, Form, InputGroup } from 'react-bootstrap' diff --git a/global-scoreboard/src/Components/GameSearch/GameCategorySearchBar.tsx b/global-scoreboard/src/Components/GameSearch/GameCategorySearchBar.tsx index 0b724fe4..28e40824 100644 --- a/global-scoreboard/src/Components/GameSearch/GameCategorySearchBar.tsx +++ b/global-scoreboard/src/Components/GameSearch/GameCategorySearchBar.tsx @@ -37,7 +37,7 @@ const DEBOUNCE_TIME = math.MS_IN_SECOND * math.HALF const GameCategorySearchBar = (props: GameCategorySearchProps) => { const handleOnChange = debounce( (searchText: string) => - !searchText + (!searchText ? props.onClear?.() : apiGet>('https://www.speedrun.com/api/v1/games', { name: searchText, max: MAX_PAGINATION }, false) .then(response => response.data) @@ -49,7 +49,7 @@ const GameCategorySearchBar = (props: GameCategorySearchProps) => { return newGames }) props.onSearch?.(searchText) - }), + })), DEBOUNCE_TIME ) diff --git a/global-scoreboard/src/Components/GameSearch/GameSearch.tsx b/global-scoreboard/src/Components/GameSearch/GameSearch.tsx index 6a4183af..9c6c9a9f 100644 --- a/global-scoreboard/src/Components/GameSearch/GameSearch.tsx +++ b/global-scoreboard/src/Components/GameSearch/GameSearch.tsx @@ -150,7 +150,7 @@ const GameSearch = () => { }) } const handleMinTimeChange: ChangeEventHandler = event => { - if (!(/^[1-9]?[\d:]{0,7}\d?$/).test(event.currentTarget.value)) return + if (!(/^[1-9]?[\d:]{0,7}\d?$/u).test(event.currentTarget.value)) return doMinTimeChange(event.currentTarget.value) setLocalStorageItem('selectedMinTime', event.currentTarget.value) } @@ -163,7 +163,7 @@ const GameSearch = () => { }) } const handleMaxTimeChange: ChangeEventHandler = event => { - if (!(/^[1-9]?[\d:]{0,7}\d?$/).test(event.currentTarget.value)) return + if (!(/^[1-9]?[\d:]{0,7}\d?$/u).test(event.currentTarget.value)) return doMaxTimeChange(event.currentTarget.value) setLocalStorageItem('selectedMaxTime', event.currentTarget.value) } diff --git a/global-scoreboard/src/Components/GameSearch/ScoreDropCalculator.tsx b/global-scoreboard/src/Components/GameSearch/ScoreDropCalculator.tsx index 387f014f..71b2da1e 100644 --- a/global-scoreboard/src/Components/GameSearch/ScoreDropCalculator.tsx +++ b/global-scoreboard/src/Components/GameSearch/ScoreDropCalculator.tsx @@ -64,7 +64,7 @@ const ScoreDropCalculator = () => { const [requiredNewPlayers, setRequiredNewPlayers] = useState(0) const [calculatedRunScore, setCalculatedRunScore] = useState(0) const [calculatedRunId, setCalculatedRunId] = useState('') - // eslint-disable-next-line id-length + // eslint-disable-next-line id-length, no-autofix/id-length const [calculatedVariables, setCalculatedVariables] = useState({ m: 0, t: 0, w: 0, N: 0, p: 0, x: 0, n: 0 }) const handleOnChange: ChangeEventHandler = event => @@ -79,7 +79,7 @@ const ScoreDropCalculator = () => { getGameSubCategories(run.game).then(subCategories => getLeaderboardRuns(run.game, run.category, filterSubCatVariables(run.values, subCategories)).then(records => { /* eslint-disable extra-rules/no-commented-out-code */ - /* eslint-disable id-length */ + /* eslint-disable id-length, no-autofix/id-length */ /* eslint-disable max-len */ /* eslint-disable @typescript-eslint/no-magic-numbers */ const primaryTimes = records @@ -88,7 +88,7 @@ const ScoreDropCalculator = () => { const m = math.mean(primaryTimes) const t = run.times.primary_t - const w = primaryTimes[primaryTimes.length - 1] + const w = primaryTimes.at(-1) const N = primaryTimes.length // Original algorithm (https://github.com/Avasam/speedrun.com_global_scoreboard_webapp/blob/main/README.md) @@ -126,7 +126,7 @@ const ScoreDropCalculator = () => { console.info(allVariables) /* eslint-enable extra-rules/no-commented-out-code */ - /* eslint-enable id-length */ + /* eslint-enable id-length, no-autofix/id-length */ /* eslint-enable max-len */ /* eslint-enable @typescript-eslint/no-magic-numbers */ }))) diff --git a/global-scoreboard/src/Components/NavBar/LoginModal.tsx b/global-scoreboard/src/Components/NavBar/LoginModal.tsx index 336f9bda..916bec6e 100644 --- a/global-scoreboard/src/Components/NavBar/LoginModal.tsx +++ b/global-scoreboard/src/Components/NavBar/LoginModal.tsx @@ -32,8 +32,8 @@ const LoginModal = (props: LoginModalProps) => { setLoginErrorMessage('') apiPost<{ user: Player }>('login', { speedruncomApiKey: speedruncomApiKeyInput }) .then(response => props.onLogin(response.user)) - .catch((error: Response) => { - if (error.status === StatusCodes.UNAUTHORIZED) { + .catch((error: unknown) => { + if (error instanceof Response && error.status === StatusCodes.UNAUTHORIZED) { void error.json() .then((data: UpdateRunnerResult) => data.message ?? '') .then(setLoginErrorMessage) diff --git a/global-scoreboard/src/Models/GameSearch.ts b/global-scoreboard/src/Models/GameSearch.ts index 5d4b23df..d6015ebf 100644 --- a/global-scoreboard/src/Models/GameSearch.ts +++ b/global-scoreboard/src/Models/GameSearch.ts @@ -43,7 +43,7 @@ export const getAllPlatforms = () => apiGet<{ data: PlatformDto[] }>( 'https://www.speedrun.com/api/v1/platforms', { max: MAX_PAGINATION }, - false + false, ) .then(response => response.data) .then(platforms => Object.fromEntries(platforms.map(platform => [platform.id, platform.name]))) @@ -56,7 +56,7 @@ export const fetchValueNamesForRun = async (runId: string) => { return apiGet( `https://www.speedrun.com/api/v1/runs/${runId}?embed=game,category`, undefined, - false + false, ) .then<[IdToNameMap, IdToNameMap]>(response => [ { [response.data.game.data.id]: response.data.game.data.names.international }, diff --git a/global-scoreboard/src/fetchers/api.ts b/global-scoreboard/src/fetchers/api.ts index ba7abbdd..d7cbb9a6 100644 --- a/global-scoreboard/src/fetchers/api.ts +++ b/global-scoreboard/src/fetchers/api.ts @@ -32,9 +32,10 @@ const apiFetch = (method: RequestInit['method'], url: string, body?: RequestI : undefined, body, }) - .then(response => response.status >= FIRST_HTTP_CODE && response.status <= LAST_HTTP_CODE + .then(response => (response.status >= FIRST_HTTP_CODE && response.status <= LAST_HTTP_CODE + // eslint-disable-next-line etc/throw-error ? Promise.reject(response) - : response) + : response)) .then(response => response.json()) .then(response => { // If a token is sent back as part of any response, set it. diff --git a/global-scoreboard/src/serviceWorker.ts b/global-scoreboard/src/serviceWorker.ts index 168f30e3..a50db90a 100644 --- a/global-scoreboard/src/serviceWorker.ts +++ b/global-scoreboard/src/serviceWorker.ts @@ -17,7 +17,7 @@ const isLocalhost = Boolean( window.location.hostname === '[::1]' || // 127.0.0.1/8 is considered localhost for IPv4. // eslint-disable-next-line unicorn/no-unsafe-regex - (/^127(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3}$/).test(window.location.hostname) + (/^127(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3}$/u).test(window.location.hostname), ) type Config = { @@ -30,7 +30,7 @@ export const register = (config?: Config) => { // The URL constructor is available in all browsers that support SW. const publicUrl = new URL( process.env.PUBLIC_URL, - window.location.href + window.location.href, ) // Our service worker won't work if PUBLIC_URL is on a different origin // from what our page is served on. This might happen if a CDN is used to @@ -49,7 +49,7 @@ export const register = (config?: Config) => { void navigator.serviceWorker.ready.then(() => console.info( 'This web app is being served cache-first by a service ' + - 'worker. To learn more, visit https://bit.ly/CRA-PWA' + 'worker. To learn more, visit https://bit.ly/CRA-PWA', )) } else { // Is not localhost. Just register service worker @@ -75,7 +75,7 @@ const registerValidSW = (swUrl: string, config?: Config) => { // content until all client tabs are closed. console.info( 'New content is available and will be used when all ' + - 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' + 'tabs for this page are closed. See https://bit.ly/CRA-PWA.', ) // Execute callback @@ -92,7 +92,7 @@ const registerValidSW = (swUrl: string, config?: Config) => { }) }) }) - .catch(error => { + .catch((error: unknown) => { console.error('Error during service worker registration:', error) }) } @@ -119,7 +119,7 @@ const checkValidServiceWorker = (swUrl: string, config?: Config) => { }) .catch(() => { console.info( - 'No internet connection found. App is running in offline mode.' + 'No internet connection found. App is running in offline mode.', ) }) } diff --git a/global-scoreboard/src/utils/time.ts b/global-scoreboard/src/utils/time.ts index 082bc7ef..03686a17 100644 --- a/global-scoreboard/src/utils/time.ts +++ b/global-scoreboard/src/utils/time.ts @@ -13,11 +13,12 @@ export const timeStringToSeconds = (timeString: string) => { if (!timeString) return '' const time = timeString.split(':') // eslint-disable-next-line @typescript-eslint/no-magic-numbers - const hour = time[time.length - 3] ?? '0' - const min = time[time.length - 2] ?? '0' - const sec = time[time.length - 1] + const hour = time.at(-3) ?? '0' + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + const min = time.at(-2) ?? '0' + const sec = time.at(-1) - return +hour * math.SECONDS_IN_HOUR + +min * math.SECONDS_IN_MINUTE + +sec + return Number(hour) * math.SECONDS_IN_HOUR + Number(min) * math.SECONDS_IN_MINUTE + Number(sec) } // From https://stackoverflow.com/a/17727953 diff --git a/tournament-scheduler/package-lock.json b/tournament-scheduler/package-lock.json index 452903b0..ec46f48d 100644 --- a/tournament-scheduler/package-lock.json +++ b/tournament-scheduler/package-lock.json @@ -35,7 +35,7 @@ "async": "^3.2.4", "ejs": "^3.1.8", "eslint": "^8.23.1", - "eslint-config-beslogic": "^1.4.8", + "eslint-config-beslogic": "^1.4.12", "eslint-plugin-jsx-a11y": "^6.6.1", "eslint-plugin-react": "^7.31.8", "eslint-plugin-react-hooks": "^4.6.0", @@ -7715,9 +7715,9 @@ } }, "node_modules/eslint-config-beslogic": { - "version": "1.4.8", - "resolved": "https://registry.npmjs.org/eslint-config-beslogic/-/eslint-config-beslogic-1.4.8.tgz", - "integrity": "sha512-bPCMgz/ev7zehl3VyIxoBQpeosMxJfzaCSTo0Tj7tio3A9ivsERvMrs6+QmocfRvWHlaRrhh/HPeawNAKe/K4w==", + "version": "1.4.12", + "resolved": "https://registry.npmjs.org/eslint-config-beslogic/-/eslint-config-beslogic-1.4.12.tgz", + "integrity": "sha512-7ZdT3F3wfOSdXMkzGSUm28DmLyLKKjX8Hw3UKhPo39MZTH/grCVCv9j/dxlB010LaiBBGijFTDh61F5WjRkI8A==", "dev": true, "dependencies": { "@babel/eslint-parser": "^7.0", @@ -25250,9 +25250,9 @@ } }, "eslint-config-beslogic": { - "version": "1.4.8", - "resolved": "https://registry.npmjs.org/eslint-config-beslogic/-/eslint-config-beslogic-1.4.8.tgz", - "integrity": "sha512-bPCMgz/ev7zehl3VyIxoBQpeosMxJfzaCSTo0Tj7tio3A9ivsERvMrs6+QmocfRvWHlaRrhh/HPeawNAKe/K4w==", + "version": "1.4.12", + "resolved": "https://registry.npmjs.org/eslint-config-beslogic/-/eslint-config-beslogic-1.4.12.tgz", + "integrity": "sha512-7ZdT3F3wfOSdXMkzGSUm28DmLyLKKjX8Hw3UKhPo39MZTH/grCVCv9j/dxlB010LaiBBGijFTDh61F5WjRkI8A==", "dev": true, "requires": { "@angular-eslint/eslint-plugin": "^13.1", diff --git a/tournament-scheduler/package.json b/tournament-scheduler/package.json index d184c8c3..8dd24393 100644 --- a/tournament-scheduler/package.json +++ b/tournament-scheduler/package.json @@ -51,7 +51,7 @@ "async": "^3.2.4", "ejs": "^3.1.8", "eslint": "^8.23.1", - "eslint-config-beslogic": "^1.4.8", + "eslint-config-beslogic": "^1.4.12", "eslint-plugin-jsx-a11y": "^6.6.1", "eslint-plugin-react": "^7.31.8", "eslint-plugin-react-hooks": "^4.6.0", diff --git a/tournament-scheduler/src/Components/App.tsx b/tournament-scheduler/src/Components/App.tsx index c87e8f8d..61791c8d 100644 --- a/tournament-scheduler/src/Components/App.tsx +++ b/tournament-scheduler/src/Components/App.tsx @@ -53,8 +53,8 @@ const App = () => { getCurrentUser() .then(response => response.user) .then(setCurrentUser) - .catch((error: Response) => { - if (error.status === StatusCodes.UNAUTHORIZED) { + .catch((error: unknown) => { + if (error instanceof Response && error.status === StatusCodes.UNAUTHORIZED) { setCurrentUser(null) } else { console.error(error) @@ -148,12 +148,12 @@ const App = () => { path='/register' /> {currentUser !== undefined && - - : } - path='/' - />} + + : } + path='/' + />} diff --git a/tournament-scheduler/src/Components/DisableDashlane.tsx b/tournament-scheduler/src/Components/DisableDashlane.tsx index 8e3e999d..2fb3d83f 100644 --- a/tournament-scheduler/src/Components/DisableDashlane.tsx +++ b/tournament-scheduler/src/Components/DisableDashlane.tsx @@ -10,8 +10,7 @@ const DisableDashlane = () => { observer.observe(document.body, { childList: true }) useEffect(() => () => observer.disconnect()) // eslint-disable-next-line react/no-danger - return