Skip to content

Commit

Permalink
style(app, protocol-designer, components): promote no-unsafe-argument…
Browse files Browse the repository at this point in the history
… from warn to error, fix all (#15402)

Promote the typescript eslint rule for no-unsafe-argument to error and
fix all outstanding instances
in the mono repo
  • Loading branch information
b-cooper authored Jun 20, 2024
1 parent 53eb97b commit 0c54e07
Show file tree
Hide file tree
Showing 168 changed files with 1,015 additions and 627 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ module.exports = {
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/consistent-indexed-object-style': 'warn',
'@typescript-eslint/ban-types': 'warn',
'@typescript-eslint/non-nullable-type-assertion-style': 'warn',
Expand All @@ -126,11 +125,13 @@ module.exports = {
'**/__fixtures__/**.@(js|ts|tsx)',
'**/fixtures/**.@(js|ts|tsx)',
'scripts/*.@(js|ts|tsx)',
'**/**test.@(js|ts|tsx)',
],
rules: {
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-confusing-void-expression': 'warn',
'node/handle-callback-err': 'off',
},
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/js-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ jobs:
make setup-js
# Use the if to run all the lint checks even of some fail
shell: bash
- name: 'lint js'
if: always() && steps.setup-js.outcome == 'success'
run: make lint-js
- name: 'typechecks'
if: always() && steps.setup-js.outcome == 'success'
run: make check-js
- name: 'lint js'
if: always() && steps.setup-js.outcome == 'success'
run: make lint-js
- name: 'circular deps'
if: always() && steps.setup-js.outcome == 'success'
run: make circular-dependencies-js
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ lint-js: lint-js-eslint lint-js-prettier

.PHONY: lint-js-eslint
lint-js-eslint:
yarn eslint --quiet=$(quiet) --ignore-pattern "node_modules/" --cache ".*.@(js|ts|tsx)" "**/*.@(js|ts|tsx)"
yarn eslint --quiet=$(quiet) --ignore-pattern "node_modules/" ".*.@(js|ts|tsx)" "**/*.@(js|ts|tsx)"

.PHONY: lint-js-prettier
lint-js-prettier:
Expand Down
4 changes: 2 additions & 2 deletions app-shell-odd/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export function getOverrides(path?: string): unknown {

export function getConfig<P extends keyof Config>(path: P): Config[P]
export function getConfig(): Config
export function getConfig(path?: any): any {
const result = store().get(path)
export function getConfig(path?: string): any {
const result = path == null ? null : store().get(path)
const over = getOverrides(path)

if (over != null) {
Expand Down
3 changes: 2 additions & 1 deletion app-shell-odd/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ function createTransports(): Transport[] {
format: winston.format.combine(
winston.format.printf(info => {
const { level, message, timestamp, label } = info
const time = timeFromStamp(timestamp)
const time =
typeof timestamp === 'string' ? timeFromStamp(timestamp) : ''
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
const print = `${time} [${label}] ${level}: ${message}`
const meta = inspect(info.meta, { depth: 6 })
Expand Down
7 changes: 4 additions & 3 deletions app-shell-odd/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
} from './notifications'

import type { BrowserWindow } from 'electron'
import type { Dispatch, Logger } from './types'
import type { Action, Dispatch, Logger } from './types'
import type { LogEntry } from 'winston'

/**
* node 17 introduced a change to default IP resolving to prefer IPv6 which causes localhost requests to fail
Expand Down Expand Up @@ -121,7 +122,7 @@ function startUp(): void {
ipcMain.on('dispatch', (_, action) => {
log.debug('Received action via IPC from renderer', { action })
actionHandlers.forEach(handler => {
handler(action)
handler(action as Action)
})
})

Expand All @@ -147,7 +148,7 @@ function createRendererLogger(): Logger {
log.info('Creating renderer logger')

const logger = createLogger('renderer')
ipcMain.on('log', (_, info) => logger.log(info))
ipcMain.on('log', (_, info) => logger.log(info as LogEntry))

return logger
}
Expand Down
2 changes: 1 addition & 1 deletion app-shell-odd/src/notifications/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function deserializeExpectedMessages(
if (!isValidNotifyResponse) {
reject(error)
} else {
resolve(JSON.parse(message))
resolve(JSON.parse(message) as NotifyBrokerResponses)
}
})
}
2 changes: 1 addition & 1 deletion app-shell-odd/src/system-update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const getVersionFromOpenedZipIfValid = (zip: StreamZip): Promise<string> =>
reject(new Error('not a Flex release file'))
}
const fileVersion = parsedContents?.opentrons_api_version
const version = Semver.valid(fileVersion)
const version = Semver.valid(fileVersion as string)
if (version === null) {
reject(new Error(`${fileVersion} is not a valid version`))
} else {
Expand Down
2 changes: 1 addition & 1 deletion app-shell/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function getConfig<P extends keyof Config>(path: P): Config[P]
export function getConfig(): Config
export function getConfig(path?: any): any {
const result = store().get(path)
const over = getOverrides(path)
const over = getOverrides(path as string | undefined)

if (over != null) {
if (typeof result === 'object' && result != null) {
Expand Down
2 changes: 1 addition & 1 deletion app-shell/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function createTransports(): Transport[] {
format: winston.format.combine(
winston.format.printf(info => {
const { level, message, timestamp, label } = info
const time = timeFromStamp(timestamp)
const time = timeFromStamp(timestamp as string)
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
const print = `${time} [${label}] ${level}: ${message}`
const meta = inspect(info.meta, { depth: 6 })
Expand Down
7 changes: 4 additions & 3 deletions app-shell/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { registerUsb } from './usb'
import { registerNotify, closeAllNotifyConnections } from './notifications'

import type { BrowserWindow } from 'electron'
import type { Dispatch, Logger } from './types'
import type { Action, Dispatch, Logger } from './types'
import type { LogEntry } from 'winston'

/**
* node 17 introduced a change to default IP resolving to prefer IPv6 which causes localhost requests to fail
Expand Down Expand Up @@ -114,7 +115,7 @@ function startUp(): void {
ipcMain.on('dispatch', (_, action) => {
log.debug('Received action via IPC from renderer', { action })
actionHandlers.forEach(handler => {
handler(action)
handler(action as Action)
})
})

Expand All @@ -125,7 +126,7 @@ function createRendererLogger(): Logger {
log.info('Creating renderer logger')

const logger = createLogger('renderer')
ipcMain.on('log', (_, info) => logger.log(info))
ipcMain.on('log', (_, info) => logger.log(info as LogEntry))

return logger
}
Expand Down
2 changes: 1 addition & 1 deletion app-shell/src/notifications/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function deserializeExpectedMessages(
if (!isValidNotifyResponse) {
reject(error)
} else {
resolve(JSON.parse(message))
resolve(JSON.parse(message) as NotifyBrokerResponses)
}
})
}
2 changes: 1 addition & 1 deletion app-shell/src/protocol-analysis/executeAnalyzeCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export function executeAnalyzeCli(
? error.stderr
: error.message

throw new Error(message)
throw new Error(message as string)
})
}
2 changes: 1 addition & 1 deletion app-shell/src/protocol-analysis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function registerProtocolAnalysis(
selectPythonPath(pathToPythonOverride)

handleConfigChange(CONFIG_PYTHON_PATH_TO_PYTHON_OVERRIDE, newValue => {
selectPythonPath(newValue)
selectPythonPath(newValue as string | null)
})

return function handleIncomingAction(action: Action): void {
Expand Down
2 changes: 1 addition & 1 deletion app-shell/src/protocol-storage/file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function addProtocolFile(
protocolsDirPath: string
): Promise<string> {
const protocolKey = uuid()
const protocolDirPath = path.join(protocolsDirPath, protocolKey)
const protocolDirPath = path.join(protocolsDirPath, protocolKey as string)

const srcDirPath = path.join(protocolDirPath, PROTOCOL_SRC_DIRECTORY_NAME)
const analysisDirPath = path.join(
Expand Down
6 changes: 4 additions & 2 deletions app-shell/src/usb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ async function usbListener(
// check for formDataProxy
if (data?.proxiedFormData != null) {
// reconstruct FormData
const formData = reconstructFormData(data.proxiedFormData)
const formData = reconstructFormData(
data.proxiedFormData as IPCSafeFormData
)
formHeaders = formData.getHeaders()
data = formData
}
Expand Down Expand Up @@ -166,7 +168,7 @@ function tryCreateAndStartUsbHttpRequests(dispatch: Dispatch): void {
const message = err?.message ?? err
usbLog.error(`Failed to create serial port: ${message}`)
}
if (agent) {
if (agent != null) {
ipcMain.removeHandler('usb:request')
ipcMain.handle('usb:request', usbListener)
dispatch(usbRequestsStart())
Expand Down
2 changes: 1 addition & 1 deletion app/src/App/DesktopAppFallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function DesktopAppFallback({ error }: FallbackProps): JSX.Element {
})
// route to the root page and initiate an electron browser window reload via app-shell
history.push('/')
dispatch(reloadUi(error.message))
dispatch(reloadUi(error.message as string))
}

return (
Expand Down
2 changes: 1 addition & 1 deletion app/src/App/OnDeviceDisplayAppFallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function OnDeviceDisplayAppFallback({
name: ANALYTICS_ODD_APP_ERROR,
properties: { errorMessage: error.message, robotSerialNumber },
})
dispatch(appRestart(error.message))
dispatch(appRestart(error.message as string))
}
const modalHeader: ModalHeaderBaseProps = {
title: t('error_boundary_title'),
Expand Down
2 changes: 1 addition & 1 deletion app/src/App/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function useProtocolReceiptToast(): void {
makeToast(
t('protocol_added', {
protocol_name: truncateString(name, 30),
}),
}) as string,
'success',
{
closeButton: true,
Expand Down
2 changes: 1 addition & 1 deletion app/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const i18nConfig: InitOptions = {
defaultNS: 'shared',
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
format: function (value, format, lng) {
format: function (value: string, format, lng) {
if (format === 'upperCase') return value.toUpperCase()
if (format === 'lowerCase') return value.toLowerCase()
if (format === 'capitalize') return capitalize(value)
Expand Down
13 changes: 7 additions & 6 deletions app/src/molecules/Command/CommandText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { MoveLabwareCommandText } from './MoveLabwareCommandText'
import type { RobotType, RunTimeCommand } from '@opentrons/shared-data'
import type { StyleProps } from '@opentrons/components'
import type { CommandTextData } from './types'
import type { TFunction } from 'i18next'

const SIMPLE_TRANSLATION_KEY_BY_COMMAND_TYPE: {
[commandType in RunTimeCommand['commandType']]?: string
Expand Down Expand Up @@ -114,7 +115,7 @@ export function CommandText(props: Props): JSX.Element | null {
const steps = profile.map(
({ holdSeconds, celsius }: { holdSeconds: number; celsius: number }) =>
t('tc_run_profile_steps', {
celsius: celsius,
celsius,
seconds: holdSeconds,
}).trim()
)
Expand Down Expand Up @@ -217,7 +218,7 @@ export function CommandText(props: Props): JSX.Element | null {
? getLabwareDisplayLocation(
commandTextData,
labwareLocation,
t,
t as TFunction,
robotType
)
: ''
Expand Down Expand Up @@ -298,7 +299,7 @@ export function CommandText(props: Props): JSX.Element | null {
const addressableAreaDisplayName = getAddressableAreaDisplayName(
commandTextData,
command.id,
t
t as TFunction
)

return (
Expand All @@ -313,7 +314,7 @@ export function CommandText(props: Props): JSX.Element | null {
const addressableAreaDisplayName = getAddressableAreaDisplayName(
commandTextData,
command.id,
t
t as TFunction
)
return (
<StyledText as={as} {...styleProps}>
Expand Down Expand Up @@ -361,7 +362,7 @@ export function CommandText(props: Props): JSX.Element | null {
case 'waitForResume': {
return (
<StyledText as={as} {...styleProps}>
{command.params?.message && command.params.message !== ''
{command.params?.message != null && command.params.message !== ''
? command.params.message
: t('wait_for_resume')}
</StyledText>
Expand All @@ -373,7 +374,7 @@ export function CommandText(props: Props): JSX.Element | null {
if ('waitForResume' in command.params) {
return (
<StyledText as={as} {...styleProps}>
{command.params?.message && command.params.message !== ''
{command.params?.message != null && command.params.message !== ''
? command.params.message
: t('wait_for_resume')}
</StyledText>
Expand Down
7 changes: 4 additions & 3 deletions app/src/molecules/Command/MoveLabwareCommandText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
RobotType,
} from '@opentrons/shared-data'
import type { CommandTextData } from './types'
import type { TFunction } from 'i18next'

interface MoveLabwareCommandTextProps {
command: MoveLabwareRunTimeCommand
Expand All @@ -29,7 +30,7 @@ export function MoveLabwareCommandText(
const newDisplayLocation = getLabwareDisplayLocation(
commandTextData,
newLocation,
t,
t as TFunction,
robotType
)

Expand All @@ -47,7 +48,7 @@ export function MoveLabwareCommandText(
? getLabwareDisplayLocation(
commandTextData,
oldLocation,
t,
t as TFunction,
robotType
)
: '',
Expand All @@ -60,7 +61,7 @@ export function MoveLabwareCommandText(
? getLabwareDisplayLocation(
commandTextData,
oldLocation,
t,
t as TFunction,
robotType
)
: '',
Expand Down
Loading

0 comments on commit 0c54e07

Please sign in to comment.