internal: Add lints for promises (#3733)

* Add lints for floating and misued promises

* Add logging async errors in main

* Add async error catch in test-utils

* Change any to unknown

* Trap promise errors and ignore more await warnings

* Add more ignores and toSync helper

* Fix more lint warnings

* Add more ignores and fixes

* Add more reject reporting

* Add accepting arbitrary parameters to toSync()

* Fix more lints

* Revert unintentional change to non-arrow function

* Revert unintentional change to use arrow function

* Fix new warnings in main with auto updater

* Fix formatting

* Change lints to error

This is what the recommended type checked rules do.

* Fix to properly report promise rejections

* Fix formatting

* Fix formatting

* Remove unused import

* Remove unused convenience function

* Move type helpers

* Fix to not return promise when caller doesn't expect it

* Add ignores to lsp code
This commit is contained in:
Jonathan Tran
2024-09-09 18:17:45 -04:00
committed by GitHub
parent 0a72d7a39a
commit 25443eba31
59 changed files with 786 additions and 528 deletions

View File

@ -20,6 +20,8 @@ import { createAndOpenNewProject, getSettingsFolderPaths } from 'lib/desktopFS'
import { useDotDotSlash } from 'hooks/useDotDotSlash'
import { ForwardedRef, forwardRef, useEffect } from 'react'
import { useLspContext } from 'components/LspProvider'
import { toSync } from 'lib/utils'
import { reportRejection } from 'lib/trap'
interface AllSettingsFieldsProps {
searchParamTab: SettingsLevel
@ -54,7 +56,7 @@ export const AllSettingsFields = forwardRef(
)
: undefined
async function restartOnboarding() {
function restartOnboarding() {
send({
type: `set.app.onboardingStatus`,
data: { level: 'user', value: '' },
@ -82,6 +84,7 @@ export const AllSettingsFields = forwardRef(
}
}
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
navigateToOnboardingStart()
}, [isFileSettings, navigate, state])
@ -190,7 +193,7 @@ export const AllSettingsFields = forwardRef(
{isDesktop() && (
<ActionButton
Element="button"
onClick={async () => {
onClick={toSync(async () => {
const paths = await getSettingsFolderPaths(
projectPath ? decodeURIComponent(projectPath) : undefined
)
@ -199,7 +202,7 @@ export const AllSettingsFields = forwardRef(
return new Error('finalPath undefined')
}
window.electron.showInFolder(finalPath)
}}
}, reportRejection)}
iconStart={{
icon: 'folder',
size: 'sm',
@ -211,14 +214,14 @@ export const AllSettingsFields = forwardRef(
)}
<ActionButton
Element="button"
onClick={async () => {
onClick={toSync(async () => {
const defaultDirectory = await getInitialDefaultDir()
send({
type: 'Reset settings',
defaultDirectory,
})
toast.success('Settings restored to default')
}}
}, reportRejection)}
iconStart={{
icon: 'refresh',
size: 'sm',