Skip to content

Commit

Permalink
fix(app, components, protocol-designer, shared-data): import type lin…
Browse files Browse the repository at this point in the history
…t rule to error, fix occurrences (#15168)

Removes ~1000 lint warnings and standardizes the separation of type
imports from module imports
  • Loading branch information
b-cooper authored May 15, 2024
1 parent b6eea4a commit bda3836
Show file tree
Hide file tree
Showing 648 changed files with 1,963 additions and 1,803 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ module.exports = {
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/consistent-type-imports': 'warn',
'@typescript-eslint/consistent-indexed-object-style': 'warn',
'@typescript-eslint/no-confusing-void-expression': 'warn',
'@typescript-eslint/ban-types': 'warn',
Expand Down
2 changes: 1 addition & 1 deletion api-client/src/calibration/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Mount } from '../pipettes'
import type { Mount } from '../pipettes'

export interface PipOffsetDeletionParams {
calType: 'pipetteOffset'
Expand Down
8 changes: 5 additions & 3 deletions api-client/src/modules/api-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ModuleType } from '@opentrons/shared-data'

import type { Coordinates, ModuleModel } from '@opentrons/shared-data'
import type {
ModuleType,
Coordinates,
ModuleModel,
} from '@opentrons/shared-data'

type PortGroup = 'main' | 'left' | 'right' | 'front' | 'unknown'
interface PhysicalPort {
Expand Down
6 changes: 2 additions & 4 deletions api-client/src/modules/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import type {
ThermocyclerModuleModel,
MagneticModuleModel,
HeaterShakerModuleModel,
} from '@opentrons/shared-data'

import {
TEMPERATURE_MODULE_TYPE,
MAGNETIC_MODULE_TYPE,
THERMOCYCLER_MODULE_TYPE,
HEATERSHAKER_MODULE_TYPE,
} from '@opentrons/shared-data'

import * as ApiTypes from './api-types'
import type * as ApiTypes from './api-types'

export * from './api-types'

// common types
Expand Down
2 changes: 1 addition & 1 deletion api-client/src/protocols/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '../utils'
import { simpleAnalysisFileFixture } from '../__fixtures__'

import { RunTimeCommand } from '@opentrons/shared-data'
import type { RunTimeCommand } from '@opentrons/shared-data'

const mockRunTimeCommands: RunTimeCommand[] = simpleAnalysisFileFixture.commands as any
const mockLoadLiquidRunTimeCommands = [
Expand Down
18 changes: 14 additions & 4 deletions api-client/src/request.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import axios, { AxiosRequestConfig } from 'axios'

import type { Method, AxiosPromise, AxiosResponse } from 'axios'
import Axios from 'axios'

import type {
AxiosRequestConfig,
Method,
AxiosPromise,
AxiosResponse,
} from 'axios'
import type { HostConfig } from './types'

export type ResponsePromise<Data> = AxiosPromise<Data>
Expand All @@ -26,7 +31,12 @@ export function request<ResData, ReqData = null>(
config: HostConfig,
params?: AxiosRequestConfig['params']
): ResponsePromise<ResData> {
const { hostname, port, requestor = axios.request, token } = config
const {
hostname,
port,
requestor = (...args) => Axios.request(...args),
token,
} = config

const tokenHeader = token != null ? { authenticationBearer: token } : {}
const headers = { ...DEFAULT_HEADERS, ...tokenHeader }
Expand Down
2 changes: 1 addition & 1 deletion api-client/src/sessions/createSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { POST, request } from '../request'
import type { ResponsePromise } from '../request'
import type { HostConfig } from '../types'
import type { Session } from './types'
import { SessionType } from '.'
import type { SessionType } from '.'

export interface CreateSessionData {
sessionType: SessionType
Expand Down
3 changes: 2 additions & 1 deletion app-shell-odd/src/http.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// fetch wrapper to throw if response is not ok
import fs from 'fs'
import { remove } from 'fs-extra'
import { Transform, Readable } from 'stream'
import pump from 'pump'
import _fetch from 'node-fetch'
import FormData from 'form-data'
import { Transform } from 'stream'

import { HTTP_API_VERSION } from './constants'

import type { Readable } from 'stream'
import type { Request, RequestInit, Response } from 'node-fetch'

type RequestInput = Request | string
Expand Down
3 changes: 1 addition & 2 deletions app-shell-odd/src/notifications/subscribe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import mqtt from 'mqtt'

import { connectionStore } from './store'
import {
sendDeserialized,
Expand All @@ -8,6 +6,7 @@ import {
} from './deserialize'
import { notifyLog } from './notifyLog'

import type mqtt from 'mqtt'
import type { NotifyTopic } from '@opentrons/app/src/redux/shell/types'

/**
Expand Down
3 changes: 2 additions & 1 deletion app-shell/src/http.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// fetch wrapper to throw if response is not ok
import fs from 'fs'
import fsPromises from 'fs/promises'
import { Transform, Readable } from 'stream'
import { Transform } from 'stream'
import pump from 'pump'
import _fetch from 'node-fetch'
import FormData from 'form-data'

import type { Request, RequestInit, Response } from 'node-fetch'
import type { Readable } from 'stream'

type RequestInput = Request | string

Expand Down
2 changes: 1 addition & 1 deletion app-shell/src/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
cleanUpUnreachableRobots,
getHealthyRobotDataForNotifyConnections,
closeConnectionsForcefullyFor,
RobotData,
} from './connect'
import { subscribe } from './subscribe'
import { notifyLog } from './notifyLog'

import type { DiscoveryClientRobot } from '@opentrons/discovery-client'
import type { BrowserWindow } from 'electron'
import type { Action, Dispatch } from '../types'
import type { RobotData } from './connect'

// Manages MQTT broker connections through a connection store. Broker connections are added based on health status
// reported by discovery-client and broker connectivity status reported by MQTT. Because a robot may have several IPs,
Expand Down
3 changes: 1 addition & 2 deletions app-shell/src/notifications/subscribe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import mqtt from 'mqtt'

import { connectionStore } from './store'
import {
sendDeserialized,
Expand All @@ -8,6 +6,7 @@ import {
} from './deserialize'
import { notifyLog } from './notifyLog'

import type mqtt from 'mqtt'
import type { NotifyTopic } from '@opentrons/app/src/redux/shell/types'

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { vi, it, expect, describe, beforeEach } from 'vitest'
import { when } from 'vitest-when'
import electron from 'electron'
import * as ProtocolAnalysis from '@opentrons/app/src/redux/protocol-analysis'
import * as Cfg from '@opentrons/app/src/redux/config'

import * as Dialogs from '../../dialogs'
import { Config, getConfig, handleConfigChange } from '../../config'
import { getConfig, handleConfigChange } from '../../config'
import { getValidLabwareFilePaths } from '../../labware'
import { selectPythonPath, getPythonPath } from '../getPythonPath'
import { executeAnalyzeCli } from '../executeAnalyzeCli'
import { writeFailedAnalysis } from '../writeFailedAnalysis'
import { createLogger } from '../../log'

import {
registerProtocolAnalysis,
analyzeProtocolSource,
CONFIG_PYTHON_PATH_TO_PYTHON_OVERRIDE,
} from '..'
import { Dispatch } from '../../types'
import type electron from 'electron'
import type { createLogger } from '../../log'
import type { Dispatch } from '../../types'
import type { Config } from '../../config'

vi.mock('../../labware')
vi.mock('../../dialogs')
Expand Down
2 changes: 1 addition & 1 deletion app-shell/src/protocol-analysis/writeFailedAnalysis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writeFile } from 'fs/promises'
import uuid from 'uuid/v4'

import { ProtocolAnalysisOutput } from '@opentrons/shared-data'
import type { ProtocolAnalysisOutput } from '@opentrons/shared-data'

const UNEXPECTED_ERROR_TYPE = 'UnexpectedAnalysisError'

Expand Down
15 changes: 8 additions & 7 deletions app-shell/src/robot-update/release-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import { move, readdir, remove, readFile } from 'fs-extra'
import StreamZip from 'node-stream-zip'
import getStream from 'get-stream'

import type { RobotUpdateTarget } from '@opentrons/app/src/redux/robot-update/types'

import { createLogger } from '../log'
import { fetchToFile } from '../http'
import { Dispatch } from '../types'
import { CURRENT_VERSION } from '../update'

import type { RobotUpdateTarget } from '@opentrons/app/src/redux/robot-update/types'
import type { Dispatch } from '../types'
import type { DownloadProgress } from '../http'
import type { ReleaseSetUrls, ReleaseSetFilepaths, UserFileInfo } from './types'

Expand Down Expand Up @@ -94,16 +93,16 @@ export function downloadAndNotify(
return move(tempPath, path, { overwrite: true })
.then(() => {
if (isReleaseNotesDownload) {
return readFile(path, 'utf8').then(releaseNotes =>
return readFile(path, 'utf8').then(releaseNotes => {
dispatch({
type: 'robotUpdate:UPDATE_INFO',
payload: { releaseNotes, target, version: CURRENT_VERSION },
})
)
})
}
// This action will only have an effect if the user is actively waiting for the download to complete.
else {
return dispatch({
dispatch({
type: 'robotUpdate:DOWNLOAD_DONE',
payload: target,
})
Expand Down Expand Up @@ -151,7 +150,9 @@ export function readUpdateFileInfo(systemFile: string): Promise<UserFileInfo> {
versionInfo,
}))

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

return result
})
Expand Down
2 changes: 1 addition & 1 deletion app-shell/src/system-info/__tests__/dispatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as Fixtures from '@opentrons/app/src/redux/system-info/__fixtures__'
import * as SystemInfo from '@opentrons/app/src/redux/system-info'
import { uiInitialized } from '@opentrons/app/src/redux/shell/actions'
import * as OS from '../../os'
import { createLogger } from '../../log'
import { createUsbDeviceMonitor, getWindowsDriverVersion } from '../usb-devices'
import {
getActiveInterfaces,
Expand All @@ -16,6 +15,7 @@ import { registerSystemInfo } from '..'
import type { Dispatch } from '../../types'
import type { UsbDeviceMonitor } from '../usb-devices'
import type { NetworkInterfaceMonitor } from '../network-interfaces'
import type { createLogger } from '../../log'

vi.mock('../../os')
vi.mock('../usb-devices')
Expand Down
3 changes: 2 additions & 1 deletion app-shell/src/system-info/__tests__/usb-devices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { usb } from 'usb'
import { vi, it, expect, describe, afterEach } from 'vitest'

import * as Fixtures from '@opentrons/app/src/redux/system-info/__fixtures__'
import { createLogger } from '../../log'
import { createUsbDeviceMonitor, getWindowsDriverVersion } from '../usb-devices'
import { isWindows } from '../../os'

import type { createLogger } from '../../log'

vi.mock('execa')
vi.mock('usb')
vi.mock('electron-store')
Expand Down
6 changes: 4 additions & 2 deletions app-shell/src/usb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ipcMain, IpcMainInvokeEvent } from 'electron'
import axios, { AxiosRequestConfig } from 'axios'
import { ipcMain } from 'electron'
import axios from 'axios'
import FormData from 'form-data'

import {
Expand All @@ -17,6 +17,8 @@ import {
USB_DEVICE_REMOVED,
} from './constants'

import type { IpcMainInvokeEvent } from 'electron'
import type { AxiosRequestConfig } from 'axios'
import type { IPCSafeFormData } from '@opentrons/app/src/redux/shell/types'
import type { UsbDevice } from '@opentrons/app/src/redux/system-info/types'
import type { PortInfo } from '@opentrons/usb-bridge/node-client'
Expand Down
2 changes: 1 addition & 1 deletion app/src/App/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react'
import type * as React from 'react'

export interface RouteProps {
/**
Expand Down
7 changes: 3 additions & 4 deletions app/src/atoms/Interstitial/Interstitial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import {
SPACING,
Overlay,
} from '@opentrons/components'
import {
InterstitialTitleBar,
InterstitialTitleBarProps,
} from './InterstitiallTitleBar'
import { InterstitialTitleBar } from './InterstitiallTitleBar'

import type { InterstitialTitleBarProps } from './InterstitiallTitleBar'
export interface InterstitialProps {
titleBar: InterstitialTitleBarProps
contentsClassName?: string
Expand Down
14 changes: 8 additions & 6 deletions app/src/atoms/MenuList/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
TYPOGRAPHY,
ALIGN_CENTER,
RESPONSIVENESS,
StyleProps,
} from '@opentrons/components'
import type { StyleProps } from '@opentrons/components'

interface ButtonProps extends StyleProps {
/** optional isAlert boolean to turn the background red, only seen in ODD */
Expand Down Expand Up @@ -34,21 +34,23 @@ export const MenuItem = styled.button<ButtonProps>`
text-align: ${TYPOGRAPHY.textAlignCenter};
font-size: ${TYPOGRAPHY.fontSize28};
background-color: ${({ isAlert }) =>
isAlert ? COLORS.red50 : COLORS.transparent};
color: ${({ isAlert }) => (isAlert ? COLORS.white : COLORS.black90)};
isAlert != null ? COLORS.red50 : COLORS.transparent};
color: ${({ isAlert }) =>
isAlert != null ? COLORS.white : COLORS.black90};
padding: ${SPACING.spacing24};
height: 5.5rem;
line-height: ${TYPOGRAPHY.lineHeight36};
&:hover,
&:active {
background-color: ${({ isAlert }) =>
isAlert ? COLORS.red50 : COLORS.grey35};
isAlert != null ? COLORS.red50 : COLORS.grey35};
}
&:disabled {
background-color: ${({ isAlert }) =>
isAlert ? COLORS.red50 : COLORS.transparent};
color: ${({ isAlert }) => (isAlert ? COLORS.white : COLORS.grey50)};
isAlert != null ? COLORS.red50 : COLORS.transparent};
color: ${({ isAlert }) =>
isAlert != null ? COLORS.white : COLORS.grey50};
}
}
`
2 changes: 1 addition & 1 deletion app/src/molecules/JogControls/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
HORIZONTAL_PLANE,
VERTICAL_PLANE,
NULL_STEP_SIZE_MM,
Expand Down
2 changes: 1 addition & 1 deletion app/src/molecules/LegacyModal/LegacyModalShell.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react'
import styled from 'styled-components'
import {
StyleProps,
COLORS,
POSITION_FIXED,
POSITION_ABSOLUTE,
Expand All @@ -15,6 +14,7 @@ import {
styleProps,
SPACING,
} from '@opentrons/components'
import type { StyleProps } from '@opentrons/components'
export interface LegacyModalShellProps extends StyleProps {
/** Modal content */
children: React.ReactNode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { describe, it, expect } from 'vitest'
import '@testing-library/jest-dom/vitest'
import {
transfer_settings,
import { transfer_settings } from '@opentrons/shared-data'
import { createSnippet } from '../createSnippet'
import type {
ModuleModel,
CompletedProtocolAnalysis,
} from '@opentrons/shared-data'
import { createSnippet } from '../createSnippet'

const protocolWithMagTempTC = ({
...transfer_settings,
Expand Down
Loading

0 comments on commit bda3836

Please sign in to comment.