Skip to content

Commit

Permalink
Linting update
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Sep 26, 2022
1 parent aaa264f commit 6f6bcc6
Show file tree
Hide file tree
Showing 33 changed files with 187 additions and 162 deletions.
14 changes: 7 additions & 7 deletions global-scoreboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion global-scoreboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions global-scoreboard/src/Components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const UpdateMessage = (props: UpdateMessageProps) => {
{typeof props.message === 'string'
? <span dangerouslySetInnerHTML={{
__html: props.message.trim().startsWith('<')
? props.message.replaceAll(/(\s+|<link.*?stylesheet.*?>|<style[\s\S]*?\/style>)/gu, ' ')
? props.message.replaceAll(/\s+|<link.*?stylesheet.*?>|<style[\s\S]*?\/style>/gu, ' ')
: props.message.replaceAll('\n', '<br/>'),
}}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import type { ChangeEventHandler, FormEvent } from 'react'
import { useState } from 'react'
import { Button, Form, InputGroup } from 'react-bootstrap'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataArray<SpeedruncomGame>>('https://www.speedrun.com/api/v1/games', { name: searchText, max: MAX_PAGINATION }, false)
.then(response => response.data)
Expand All @@ -49,7 +49,7 @@ const GameCategorySearchBar = (props: GameCategorySearchProps) => {
return newGames
})
props.onSearch?.(searchText)
}),
})),
DEBOUNCE_TIME
)

Expand Down
4 changes: 2 additions & 2 deletions global-scoreboard/src/Components/GameSearch/GameSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const GameSearch = () => {
})
}
const handleMinTimeChange: ChangeEventHandler<HTMLInputElement> = 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)
}
Expand All @@ -163,7 +163,7 @@ const GameSearch = () => {
})
}
const handleMaxTimeChange: ChangeEventHandler<HTMLInputElement> = 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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLInputElement> = event =>
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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 */
})))
Expand Down
4 changes: 2 additions & 2 deletions global-scoreboard/src/Components/NavBar/LoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions global-scoreboard/src/Models/GameSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const getAllPlatforms = () =>
apiGet<{ data: PlatformDto[] }>(
'https://www.speedrun.com/api/v1/platforms',
{ max: MAX_PAGINATION },
false
false,
)
.then<PlatformDto[]>(response => response.data)
.then<IdToNameMap>(platforms => Object.fromEntries(platforms.map(platform => [platform.id, platform.name])))
Expand All @@ -56,7 +56,7 @@ export const fetchValueNamesForRun = async (runId: string) => {
return apiGet<EmbeddedSpeedruncomRun>(
`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 },
Expand Down
5 changes: 3 additions & 2 deletions global-scoreboard/src/fetchers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ const apiFetch = <R>(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<R & { token?: string }>(response => response.json())
.then(response => {
// If a token is sent back as part of any response, set it.
Expand Down
12 changes: 6 additions & 6 deletions global-scoreboard/src/serviceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -92,7 +92,7 @@ const registerValidSW = (swUrl: string, config?: Config) => {
})
})
})
.catch(error => {
.catch((error: unknown) => {
console.error('Error during service worker registration:', error)
})
}
Expand All @@ -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.',
)
})
}
Expand Down
9 changes: 5 additions & 4 deletions global-scoreboard/src/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions tournament-scheduler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tournament-scheduler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions tournament-scheduler/src/Components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -148,12 +148,12 @@ const App = () => {
path='/register'
/>
{currentUser !== undefined &&
<Route
element={currentUser
? <ScheduleManagement currentUser={currentUser} />
: <LoginForm onLogin={setCurrentUser} />}
path='/'
/>}
<Route
element={currentUser
? <ScheduleManagement currentUser={currentUser} />
: <LoginForm onLogin={setCurrentUser} />}
path='/'
/>}
</Routes>
</Box>

Expand Down
3 changes: 1 addition & 2 deletions tournament-scheduler/src/Components/DisableDashlane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const DisableDashlane = () => {
observer.observe(document.body, { childList: true })
useEffect(() => () => observer.disconnect())
// eslint-disable-next-line react/no-danger
return <style dangerouslySetInnerHTML={{
__html: `
return <style dangerouslySetInnerHTML={{ __html: `
iframe#kw-iframe-dropdown.kw-iframe, [data-dashlanecreated] {
display: none !important;
visibility: hidden !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import DriveFileMove from '@mui/icons-material/DriveFileMove'
import { IconButton, Menu, MenuItem } from '@mui/material'
import { useState } from 'react'

import type { ScheduleGroup } from 'src/Models/Schedule'
import type { ScheduleGroup } from 'src/Models/ScheduleGroup'

export type MoveToGroupMenuProps = {
onMoveToGroup: (groupId: number | null) => void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useState } from 'react'
import { Link as RouterLink } from 'react-router-dom'

import type { IOrderableProps } from 'src/Models/IOrderable'
import type { ScheduleGroup } from 'src/Models/Schedule'
import type { ScheduleGroup } from 'src/Models/ScheduleGroup'

type ScheduleGroupCardProps = IOrderableProps<ScheduleGroup> & {
group: ScheduleGroup
Expand Down
Loading

0 comments on commit 6f6bcc6

Please sign in to comment.