Skip to content

Commit

Permalink
style(app, protocol-designer): promote confusing void expression lint…
Browse files Browse the repository at this point in the history
… rule to error, fix all (#15327)

Re-enable lint error for confusing typescript void expressions and fix
all outstanding occurrences of
the error.
  • Loading branch information
b-cooper authored Jun 5, 2024
1 parent e74a3fc commit 42633bd
Show file tree
Hide file tree
Showing 342 changed files with 2,341 additions and 969 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ module.exports = {
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/consistent-indexed-object-style': 'warn',
'@typescript-eslint/no-confusing-void-expression': 'warn',
'@typescript-eslint/ban-types': 'warn',
'@typescript-eslint/non-nullable-type-assertion-style': 'warn',
'@typescript-eslint/await-thenable': 'warn',
Expand Down
8 changes: 4 additions & 4 deletions app-shell-odd/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,23 @@ export function registerConfig(dispatch: Dispatch): (action: Action) => void {
)

if (path === 'devtools') {
systemd.setRemoteDevToolsEnabled(Boolean(nextValue)).catch(err =>
systemd.setRemoteDevToolsEnabled(Boolean(nextValue)).catch(err => {
log().debug('Something wrong when setting remote dev tools', {
err,
})
)
})
}

// Note (kj:08/03/2023) change touchscreen brightness
if (path === 'onDeviceDisplaySettings.brightness') {
systemd.updateBrightness(String(nextValue)).catch(err =>
systemd.updateBrightness(String(nextValue)).catch(err => {
log().debug(
'Something wrong when updating the touchscreen brightness',
{
err,
}
)
)
})
}

log().debug('Updating config', { path, nextValue })
Expand Down
31 changes: 18 additions & 13 deletions app-shell-odd/src/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,25 @@ export function registerDiscovery(

switch (action.type) {
case UI_INITIALIZED:
case DISCOVERY_START:
case DISCOVERY_START: {
handleRobots()
return client.start({ healthPollInterval: FAST_POLL_INTERVAL_MS })

case DISCOVERY_FINISH:
return client.start({ healthPollInterval: SLOW_POLL_INTERVAL_MS })

case DISCOVERY_REMOVE:
return client.removeRobot(
(action.payload as { robotName: string }).robotName
)

case CLEAR_CACHE:
return clearCache()
client.start({ healthPollInterval: FAST_POLL_INTERVAL_MS })
return
}

case DISCOVERY_FINISH: {
client.start({ healthPollInterval: SLOW_POLL_INTERVAL_MS })
return
}

case DISCOVERY_REMOVE: {
client.removeRobot((action.payload as { robotName: string }).robotName)
return
}

case CLEAR_CACHE: {
clearCache()
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion app-shell-odd/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export function fetchToFile(
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (error) {
// if we error out, delete the temp dir to clean up
return remove(destination).then(() => reject(error))
return remove(destination).then(() => {
reject(error)
})
}
resolve(destination)
})
Expand Down
4 changes: 3 additions & 1 deletion app-shell-odd/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ function startUp(): void {

ipcMain.on('dispatch', (_, action) => {
log.debug('Received action via IPC from renderer', { action })
actionHandlers.forEach(handler => handler(action))
actionHandlers.forEach(handler => {
handler(action)
})
})

log.silly('Global references', { mainWindow, rendererLogger })
Expand Down
18 changes: 13 additions & 5 deletions app-shell-odd/src/notifications/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,23 @@ export function connectAsync(brokerURL: string): Promise<mqtt.Client> {
} = {
connect: () => {
removePromiseListeners()
return resolve(client)
resolve(client)
},
// A connection error event will close the connection without a retry.
error: (error: Error | string) => {
removePromiseListeners()
const clientEndPromise = new Promise((resolve, reject) =>
client.end(true, {}, () => resolve(error))
client.end(true, {}, () => {
resolve(error)
})
)
return clientEndPromise.then(() => reject(error))
return clientEndPromise.then(() => {
reject(error)
})
},
end: () => {
promiseListeners.error(`Couldn't connect to ${brokerURL}`)
},
end: () => promiseListeners.error(`Couldn't connect to ${brokerURL}`),
}

function removePromiseListeners(): void {
Expand Down Expand Up @@ -116,6 +122,8 @@ export function establishListeners(): void {
export function closeConnectionForcefully(): Promise<void> {
const { client } = connectionStore
return new Promise<void>((resolve, reject) =>
client?.end(true, {}, () => resolve())
client?.end(true, {}, () => {
resolve()
})
)
}
4 changes: 3 additions & 1 deletion app-shell-odd/src/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export function establishBrokerConnection(): Promise<void> {
notifyLog.debug(`Successfully connected to ${robotName} on ${ip}`)
void connectionStore
.setConnected(client)
.then(() => establishListeners())
.then(() => {
establishListeners()
})
.catch((error: Error) => notifyLog.debug(error.message))
})
.catch((error: Error) => {
Expand Down
4 changes: 3 additions & 1 deletion app-shell-odd/src/notifications/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export function subscribe(topic: NotifyTopic): Promise<void> {
// The client is either already subscribed or the subscription is currently pending.
else {
void waitUntilActiveOrErrored('subscription', topic)
.then(() => sendDeserializedRefetch(topic))
.then(() => {
sendDeserializedRefetch(topic)
})
.catch((error: Error) => {
notifyLog.debug(error.message)
sendDeserializedGenericError(topic)
Expand Down
3 changes: 2 additions & 1 deletion app-shell-odd/src/notifications/unsubscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export function unsubscribe(topic: NotifyTopic): Promise<void> {
.then(() => {
const { client } = connectionStore
if (client == null) {
return reject(new Error('Expected hostData, received null.'))
reject(new Error('Expected hostData, received null.'))
return
}

client.unsubscribe(topic, {}, (error, result) => {
Expand Down
12 changes: 5 additions & 7 deletions app-shell-odd/src/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ export function registerAppRestart(): (action: Action) => unknown {
case APP_RESTART:
systemd
.sendStatus(`restarting app: ${action.payload.message}`)
.catch(err =>
.catch(err => {
log().debug('Something wrong when sending a message', { err })
)
})
console.log(`restarting app: ${action.payload.message}`)
systemd
.restartApp()
.catch(err =>
log().debug('Something wrong when resettings the app', { err })
)
systemd.restartApp().catch(err => {
log().debug('Something wrong when resettings the app', { err })
})
break
}
}
Expand Down
32 changes: 19 additions & 13 deletions app-shell-odd/src/system-update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ export function registerRobotSystemUpdate(dispatch: Dispatch): Dispatch {
const systemFile =
massStorageUpdateSet?.system ?? systemUpdateSet?.system
if (systemFile == null) {
return dispatch({
dispatch({
type: 'robotUpdate:UNEXPECTED_ERROR',
payload: { message: 'System update file not downloaded' },
})
return
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
readFileInfoAndDispatch(dispatch, systemFile)
Expand Down Expand Up @@ -157,7 +158,7 @@ export function registerRobotSystemUpdate(dispatch: Dispatch): Dispatch {
}

const getVersionFromOpenedZipIfValid = (zip: StreamZip): Promise<string> =>
new Promise((resolve, reject) =>
new Promise((resolve, reject) => {
Object.values(zip.entries()).forEach(entry => {
if (
entry.isFile &&
Expand All @@ -182,7 +183,7 @@ const getVersionFromOpenedZipIfValid = (zip: StreamZip): Promise<string> =>
}
}
})
)
})

interface FileDetails {
path: string
Expand Down Expand Up @@ -322,13 +323,12 @@ export function getLatestSystemUpdateFiles(
.then(filepaths => {
return cacheUpdateSet(filepaths)
})
.then(
updateInfo =>
massStorageUpdateSet === null &&
.then(updateInfo => {
massStorageUpdateSet === null &&
dispatchUpdateInfo({ force: false, ...updateInfo }, dispatch)
)
})
.catch((error: Error) => {
return dispatch({
dispatch({
type: 'robotUpdate:DOWNLOAD_ERROR',
payload: { error: error.message, target: 'flex' },
})
Expand All @@ -347,16 +347,20 @@ export function getCachedSystemUpdateFiles(
): Promise<unknown> {
if (systemUpdateSet) {
return getInfoFromUpdateSet(systemUpdateSet)
.then(updateInfo =>
.then(updateInfo => {
dispatchUpdateInfo({ force: false, ...updateInfo }, dispatch)
)
.catch(err => console.log(`Could not get info from update set: ${err}`))
})
.catch(err => {
console.log(`Could not get info from update set: ${err}`)
})
} else {
dispatchUpdateInfo(
{ version: null, releaseNotes: null, force: false },
dispatch
)
return new Promise(resolve => resolve('no files'))
return new Promise(resolve => {
resolve('no files')
})
}
}

Expand All @@ -366,7 +370,9 @@ function getInfoFromUpdateSet(
const version = getLatestVersion()
const releaseNotesContentPromise = filepaths.releaseNotes
? readFile(filepaths.releaseNotes, 'utf8')
: new Promise<string | null>(resolve => resolve(null))
: new Promise<string | null>(resolve => {
resolve(null)
})
return releaseNotesContentPromise
.then(releaseNotes => ({
version: version,
Expand Down
4 changes: 3 additions & 1 deletion app-shell-odd/src/system-update/release-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ export function readUserFileInfo(systemFile: string): Promise<UserFileInfo> {
versionInfo,
}))

result.finally(() => zip.close())
result.finally(() => {
zip.close()
})

return result
})
Expand Down
26 changes: 19 additions & 7 deletions app-shell-odd/src/systemd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,30 @@ const provideExports = (): SystemD => {
}
} else {
return {
ready: () => new Promise<string>(resolve => resolve('fake notify done')),
ready: () =>
new Promise<string>(resolve => {
resolve('fake notify done')
}),
sendStatus: text =>
new Promise<string>(resolve => resolve(`fake status done for ${text}`)),
new Promise<string>(resolve => {
resolve(`fake status done for ${text}`)
}),
setRemoteDevToolsEnabled: enabled =>
new Promise<string>(resolve => resolve(`dev tools set to ${enabled}`)),
new Promise<string>(resolve => {
resolve(`dev tools set to ${enabled}`)
}),
getisRobotServerReady: () =>
new Promise<boolean>(resolve => resolve(true)),
restartApp: () => new Promise<string>(resolve => resolve('')),
new Promise<boolean>(resolve => {
resolve(true)
}),
restartApp: () =>
new Promise<string>(resolve => {
resolve('')
}),
updateBrightness: text =>
new Promise<string>(resolve =>
new Promise<string>(resolve => {
resolve(`fake brightness ${text} was set`)
),
}),
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions app-shell-odd/src/usb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ const enumerateMassStorage = (path: string): Promise<string[]> =>
? new Promise<void>(resolve =>
setTimeout(resolve, MOUNT_ENUMERATION_DELAY_MS)
)
: new Promise<void>(resolve => resolve())
: new Promise<void>(resolve => {
resolve()
})
)
.then(() => fsPromises.readdir(path, { withFileTypes: true }))
.then(entries =>
Promise.all(
entries.map(entry =>
entry.isDirectory() && !isWeirdDirectoryAndShouldSkip(entry.name)
? enumerateMassStorage(join(path, entry.name))
: new Promise<string[]>(resolve =>
: new Promise<string[]>(resolve => {
resolve([join(path, entry.name)])
)
})
)
)
)
Expand Down
14 changes: 8 additions & 6 deletions app-shell/src/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,24 @@ export function registerDiscovery(
case UI_INITIALIZED:
case DISCOVERY_START: {
handleRobots()
return client.start({
client.start({
healthPollInterval: FAST_POLL_INTERVAL_MS,
})
return
}
case DISCOVERY_FINISH: {
return client.start({
client.start({
healthPollInterval: SLOW_POLL_INTERVAL_MS,
})
return
}
case DISCOVERY_REMOVE: {
return client.removeRobot(
(action.payload as { robotName: string }).robotName
)
client.removeRobot((action.payload as { robotName: string }).robotName)
return
}
case CLEAR_CACHE: {
return clearCache()
clearCache()
return
}
case USB_HTTP_REQUESTS_START: {
const usbHttpAgent = getSerialPortHttpAgent()
Expand Down
5 changes: 4 additions & 1 deletion app-shell/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export function fetchToFile(
// its callbacks when the streams are done
pump(inputStream, progressReader, outputStream, error => {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (error) return reject(error)
if (error) {
reject(error)
return
}
resolve(destination)
})
})
Expand Down
Loading

0 comments on commit 42633bd

Please sign in to comment.