Skip to content

Commit

Permalink
[Tech] Fix some of the smaller ESLint warnings (#3958)
Browse files Browse the repository at this point in the history
* Make `@typescript-eslint/await-thenable` an error

* Make `@typescript-eslint/no-redundant-type-constituents` an error

* Make `@typescript-eslint/no-unnecessary-type-assertion` an error

* Remove unused `eslint-disable` comments
  • Loading branch information
CommandMC authored Aug 22, 2024
1 parent 7862e53 commit dbe780d
Show file tree
Hide file tree
Showing 28 changed files with 48 additions and 71 deletions.
3 changes: 0 additions & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ export default tseslint.config(
files: ['**/*.ts', '**/*.tsx'],
rules: {
// FIXME: All of these rules should be errors instead
'@typescript-eslint/await-thenable': 'warn',
'@typescript-eslint/no-base-to-string': 'warn',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-for-in-array': 'warn',
'@typescript-eslint/no-redundant-type-constituents': 'warn',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
Expand Down
4 changes: 1 addition & 3 deletions src/backend/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ export async function getSteamLibraries(): Promise<string[]> {
if (!json.libraryfolders) {
return libraries
}
const folders = Object.values(json.libraryfolders) as Array<{
path: string
}>
const folders: { path: string }[] = Object.values(json.libraryfolders)
return [...libraries, ...folders.map((folder) => folder.path)].filter(
(path) => existsSync(path)
)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/downloadmanager/downloadqueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function cancelCurrentDownload({ removeDownloaded = false }) {
removeFromQueue(currentElement.params.appName)

if (removeDownloaded) {
const { appName, runner } = currentElement!.params
const { appName, runner } = currentElement.params
const { folder_name } = gameManagerMap[runner].getGameInfo(appName)
if (folder_name) {
removeFolder(currentElement.params.path, folder_name)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/game_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ abstract class GameConfig {
} else {
// No upgrades necessary, load config.
// `this.version` should be `currentGameConfigVersion` at this point.
this.config = (await this.getSettings()) as GameSettings
this.config = await this.getSettings()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const RunnerToLogPrefixMap = {
sideload: LogPrefix.Sideload
}

type LogInputType = unknown[] | unknown
type LogInputType = unknown

interface LogOptions {
prefix?: LogPrefix
Expand Down
1 change: 0 additions & 1 deletion src/backend/preload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { contextBridge } from 'electron'
import api from './api'
Expand Down
4 changes: 2 additions & 2 deletions src/backend/storeManagers/gog/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export async function launch(
if (wineLaunchPrepFailReason) {
showDialogBoxModalAuto({
title: t('box.error.launchAborted', 'Launch aborted'),
message: wineLaunchPrepFailReason!,
message: wineLaunchPrepFailReason,
type: 'ERROR'
})
}
Expand Down Expand Up @@ -1273,7 +1273,7 @@ export async function isGameAvailable(appName: string): Promise<boolean> {
return new Promise((resolve) => {
const info = getGameInfo(appName)
if (info && info.is_installed) {
if (info.install.install_path && existsSync(info.install.install_path!)) {
if (info.install.install_path && existsSync(info.install.install_path)) {
resolve(true)
} else {
resolve(false)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/storeManagers/gog/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ export async function getLinuxInstallersLanguages(appName: string) {
const possibleLanguages: string[] = []

for (const installer of linuxInstallers) {
possibleLanguages.push(installer.language as string)
possibleLanguages.push(installer.language)
}

return possibleLanguages
Expand Down
4 changes: 2 additions & 2 deletions src/backend/storeManagers/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ export async function launch(
if (wineLaunchPrepFailReason) {
showDialogBoxModalAuto({
title: t('box.error.launchAborted', 'Launch aborted'),
message: wineLaunchPrepFailReason!,
message: wineLaunchPrepFailReason,
type: 'ERROR'
})
}
Expand Down Expand Up @@ -1041,7 +1041,7 @@ export async function isGameAvailable(appName: string): Promise<boolean> {
return new Promise((resolve) => {
const info = getGameInfo(appName)
if (info && info.is_installed) {
if (info.install.install_path && existsSync(info.install.install_path!)) {
if (info.install.install_path && existsSync(info.install.install_path)) {
resolve(true)
} else {
resolve(false)
Expand Down
6 changes: 2 additions & 4 deletions src/backend/storeManagers/legendary/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function refreshInstalled() {
try {
installedCache = Object.entries(
JSON.parse(readFileSync(installedJSON, 'utf-8'))
) as [string, InstalledJsonMetadata][]
)
} catch (error) {
// disabling log here because its giving false positives on import command
logError(
Expand Down Expand Up @@ -743,9 +743,7 @@ export async function getGameSdl(
const sdlList: SelectiveDownload[] = []

list.forEach((key) => {
const { name, description, tags } = response.data[
key
] as SelectiveDownload
const { name, description, tags } = response.data[key]
if (key === '__required') {
sdlList.unshift({ name, description, tags, required: true })
} else {
Expand Down
2 changes: 0 additions & 2 deletions src/backend/storeManagers/sideload/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ export function addNewApp({
return
}

/* eslint-disable @typescript-eslint/no-unused-vars */

export function installState() {
logWarning(`installState not implemented on Sideload Library Manager`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/utils/compatibility_layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export async function getLinuxWineSet(
})

const defaultWineSet = new Set<WineInstallation>()
const defaultWine = await getDefaultWine()
const defaultWine = getDefaultWine()
if (!defaultWine.name.includes('Not Found')) {
defaultWineSet.add(defaultWine)
}
Expand Down
5 changes: 0 additions & 5 deletions src/backend/utils/systeminfo/heroicVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import pkg_json from 'backend/../../package.json'

function getHeroicVersion(): string {
const VERSION_NUMBER = app.getVersion()
// FIXME: Currently ESLint doesn't know that these are type-checked. I believe
// TS 5.X introduced support for this properly, so come back to this
// once we update to that
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const BETA_VERSION_NAME = pkg_json.versionNames.beta
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const STABLE_VERSION_NAME = pkg_json.versionNames.stable
const isBetaOrAlpha =
VERSION_NUMBER.includes('alpha') || VERSION_NUMBER.includes('beta')
Expand Down
2 changes: 1 addition & 1 deletion src/backend/utils/systeminfo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async function getSystemInfo(cache = true): Promise<SystemInformation> {

const sysinfo: SystemInformation = {
CPU: {
model: cpus[0]!.model,
model: cpus[0].model,
// FIXME: Technically the user could be on a server with more than one
// physical CPU installed, but I'd say that's rather unlikely
cores: cpus.length
Expand Down
7 changes: 4 additions & 3 deletions src/common/typedefs/ipcBridge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import {
ExtraInfo,
LaunchOption,
DownloadManagerState,
InstallInfo
InstallInfo,
WikiInfo
} from 'common/types'
import { SelectiveDownload } from 'common/types/legendary'
import { GameOverride, SelectiveDownload } from 'common/types/legendary'
import { GOGCloudSavesLocation } from 'common/types/gog'
import {
NileLoginData,
Expand Down Expand Up @@ -279,7 +280,7 @@ interface AsyncIPCFunctions {
toggleDXVKNVAPI: (args: ToolArgs) => Promise<boolean>
pathExists: (path: string) => Promise<boolean>
getLaunchOptions: (appName: string, runner: Runner) => Promise<LaunchOption[]>
getGameOverride: () => Promise<GameOverride | null>
getGameOverride: () => Promise<GameOverride>
getGameSdl: (appName: string) => Promise<SelectiveDownload[]>
getPlaytimeFromRunner: (
runner: Runner,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/UI/Dialog/components/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Dialog: React.FC<DialogProps> = ({
const { disableDialogBackdropClose } = useContext(ContextProvider)

useEffect(() => {
setFocusOnClose(document.querySelector('*:focus') as HTMLElement)
setFocusOnClose(document.querySelector<HTMLElement>('*:focus'))
}, [])

const close = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/UI/LibraryFilters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default function LibraryFilters() {
<ToggleSwitch
key={store}
htmlId={store}
handleChange={() => toggleStoreFilter(store as Category)}
handleChange={() => toggleStoreFilter(store)}
value={storesFilters[store]}
title={t(RunnerToStore[store])}
/>
Expand Down
7 changes: 3 additions & 4 deletions src/frontend/components/UI/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DMQueueElement } from 'common/types'

import HeroicIcon from 'frontend/assets/heroic-icon.svg?react'
import { useNavigate } from 'react-router-dom'
import { WebviewTag } from 'electron'

let sidebarSize = localStorage.getItem('sidebar-width') || 240
const minWidth = 60
Expand Down Expand Up @@ -82,9 +83,7 @@ export default React.memo(function Sidebar() {
localStorage.setItem('sidebar-width', sidebarSize.toString())

// Re-enable pointer events on webview element
const webviewEl = document.querySelector(
'webview'
) as HTMLDivElement | null
const webviewEl = document.querySelector<WebviewTag>('webview')
if (webviewEl) {
webviewEl.style.pointerEvents = 'auto'
}
Expand All @@ -95,7 +94,7 @@ export default React.memo(function Sidebar() {
document.body.addEventListener('mousemove', onMouseMove)

// Disable pointer events on webview element
const webviewEl = document.querySelector('webview') as HTMLDivElement | null
const webviewEl = document.querySelector<WebviewTag>('webview')
if (webviewEl) {
webviewEl.style.pointerEvents = 'none'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ const CompatibilityInfo = ({ gameInfo }: Props) => {
{t('info.protondb-compatibility-info', 'Proton Compatibility Tier')}
:
</b>
{steamInfo!.compatibilityLevel!.charAt(0).toUpperCase() +
steamInfo!.compatibilityLevel!.slice(1)}
{steamInfo.compatibilityLevel!.charAt(0).toUpperCase() +
steamInfo.compatibilityLevel!.slice(1)}
</a>
)}
{hasSteamDeckCompat && (
Expand Down
20 changes: 9 additions & 11 deletions src/frontend/screens/Game/GamePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default React.memo(function GamePage(): JSX.Element | null {
>(undefined)
const [hasError, setHasError] = useState<{
error: boolean
message: string | unknown
message: unknown
}>({ error: false, message: '' })

const anticheatInfo = hasAnticheatInfo(gameInfo)
Expand Down Expand Up @@ -244,16 +244,14 @@ export default React.memo(function GamePage(): JSX.Element | null {
])

useEffect(() => {
window.api
.getWikiGameInfo(gameInfo.title, appName, runner)
.then((info: WikiInfo) => {
if (
info &&
(info.applegamingwiki || info.howlongtobeat || info.pcgamingwiki)
) {
setWikiInfo(info)
}
})
window.api.getWikiGameInfo(gameInfo.title, appName, runner).then((info) => {
if (
info &&
(info.applegamingwiki || info.howlongtobeat || info.pcgamingwiki)
) {
setWikiInfo(info)
}
})
}, [appName])

function handleUpdate() {
Expand Down
16 changes: 7 additions & 9 deletions src/frontend/screens/Game/GameSubMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './index.css'

import React, { useContext, useEffect, useState } from 'react'

import { GameInfo, GameStatus, Runner, WikiInfo } from 'common/types'
import { GameInfo, GameStatus, Runner } from 'common/types'

import { createNewWindow, repair } from 'frontend/helpers'
import { useTranslation } from 'react-i18next'
Expand Down Expand Up @@ -215,14 +215,12 @@ export default function GamesSubmenu({

useEffect(() => {
// Get steam id and set direct proton db link
window.api
.getWikiGameInfo(title, appName, runner)
.then((info: WikiInfo) => {
const steamID = info?.pcgamingwiki?.steamID ?? info?.gamesdb?.steamID
if (steamID) {
setProtonDBurl(`https://www.protondb.com/app/${steamID}`)
}
})
window.api.getWikiGameInfo(title, appName, runner).then((info) => {
const steamID = info?.pcgamingwiki?.steamID ?? info?.gamesdb?.steamID
if (steamID) {
setProtonDBurl(`https://www.protondb.com/app/${steamID}`)
}
})
}, [title, appName])

const refreshCircle = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface Props {

type DiskSpaceInfo = {
notEnoughDiskSpace: boolean
message: string | `ERROR`
message: string
validPath: boolean
validFlatpakPath: boolean
spaceLeftAfter: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ export default function SideloadDialog({
appName
}: Props) {
const { t } = useTranslation('gamepage')
const [title, setTitle] = useState<string | never>(
t('sideload.field.title', 'Title')
)
const [title, setTitle] = useState<string>(t('sideload.field.title', 'Title'))
const [selectedExe, setSelectedExe] = useState('')
const [gameUrl, setGameUrl] = useState('')
const [customUserAgent, setCustomUserAgent] = useState('')
Expand Down
5 changes: 2 additions & 3 deletions src/frontend/screens/Library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,8 @@ export default React.memo(function Library(): JSX.Element {
const header = document.querySelector('.Header')
if (header) {
const headerHeight = header.getBoundingClientRect().height
const libraryHeader = document.querySelector(
'.libraryHeader'
) as HTMLDivElement
const libraryHeader =
document.querySelector<HTMLDivElement>('.libraryHeader')
libraryHeader &&
libraryHeader.style.setProperty(
'--header-height',
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/screens/Settings/components/Tools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export default function Tools() {
return <></>
}

type Tool = 'winecfg' | string
async function callTools(tool: Tool, exe?: string) {
async function callTools(tool: 'winecfg' | 'runExe', exe?: string) {
const toolStates = {
winecfg: setWinecfgRunning,
runExe: setRunExeRunning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default function AdvancedSetting() {
}

async function cancelEosOverlayInstallOrUpdate() {
await window.api.abort(eosOverlayAppName)
window.api.abort(eosOverlayAppName)
setEosOverlayInstallingOrUpdating(false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default function GamesSettings() {
}
// Get the latest used tab index for the current game
const localStorageKey = gameInfo
? `${gameInfo!.app_name}-setting_tab`
? `${gameInfo.app_name}-setting_tab`
: 'default'
const latestTabIndex =
localStorage.getItem(localStorageKey) || getStartingTab(platform, gameInfo)
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/state/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ class GlobalState extends PureComponent<Props> {
}

gogLogout = async () => {
await window.api.logoutGOG()
window.api.logoutGOG()
this.setState({
gog: {
library: [],
Expand Down

0 comments on commit dbe780d

Please sign in to comment.