From 00e8f11913eb9eaadb09909cc530693aac825e9f Mon Sep 17 00:00:00 2001 From: Lorenzo Alberto Maria Ambrosi Date: Wed, 13 Oct 2021 17:21:48 +0200 Subject: [PATCH] patch: Fix linting errors Signed-off-by: Lorenzo Alberto Maria Ambrosi --- lib/gui/app/app.ts | 5 ++-- .../drive-selector/drive-selector.tsx | 6 ++-- lib/gui/app/components/finish/finish.tsx | 9 ++---- .../source-selector/source-selector.tsx | 10 +++---- .../target-selector/target-selector.tsx | 11 +++----- lib/gui/app/models/flash-state.ts | 3 +- lib/gui/app/models/settings.ts | 4 +-- lib/gui/app/modules/analytics.ts | 7 ++--- lib/gui/app/modules/drive-scanner.ts | 22 +++++++++------ lib/gui/app/modules/image-writer.ts | 6 ++-- lib/gui/app/os/dialog.ts | 2 +- lib/gui/app/pages/main/Flash.tsx | 2 +- lib/gui/modules/child-writer.ts | 2 +- lib/shared/catalina-sudo/sudo.ts | 2 +- lib/shared/permissions.ts | 6 ++-- scripts/clean-shrinkwrap.ts | 2 +- tests/gui/models/flash-state.spec.ts | 3 +- tests/gui/models/settings.spec.ts | 2 +- tests/gui/modules/image-writer.spec.ts | 4 +-- tests/shared/drive-constraints.spec.ts | 28 +++++++++---------- tests/shared/supported-formats.spec.ts | 10 +++---- tests/spectron/runner.spec.ts | 2 +- 22 files changed, 72 insertions(+), 76 deletions(-) diff --git a/lib/gui/app/app.ts b/lib/gui/app/app.ts index 86dfe26a..79765c24 100644 --- a/lib/gui/app/app.ts +++ b/lib/gui/app/app.ts @@ -217,8 +217,7 @@ function prepareDrive(drive: Drive) { disabled: true, icon: 'warning', size: null, - link: - 'https://www.raspberrypi.org/documentation/hardware/computemodule/cm-emmc-flashing.md', + link: 'https://www.raspberrypi.org/documentation/hardware/computemodule/cm-emmc-flashing.md', linkCTA: 'Install', linkTitle: 'Install missing drivers', linkMessage: outdent` @@ -335,7 +334,7 @@ window.addEventListener('beforeunload', async (event) => { flashingWorkflowUuid, }); popupExists = false; - } catch (error) { + } catch (error: any) { exceptionReporter.report(error); } }); diff --git a/lib/gui/app/components/drive-selector/drive-selector.tsx b/lib/gui/app/components/drive-selector/drive-selector.tsx index ee8a60f4..4088271a 100644 --- a/lib/gui/app/components/drive-selector/drive-selector.tsx +++ b/lib/gui/app/components/drive-selector/drive-selector.tsx @@ -379,8 +379,8 @@ export class DriveSelector extends React.Component< const displayedDrives = this.getDisplayedDrives(drives); const disabledDrives = this.getDisabledDrives(drives, image); const numberOfSystemDrives = drives.filter(isSystemDrive).length; - const numberOfDisplayedSystemDrives = displayedDrives.filter(isSystemDrive) - .length; + const numberOfDisplayedSystemDrives = + displayedDrives.filter(isSystemDrive).length; const numberOfHiddenSystemDrives = numberOfSystemDrives - numberOfDisplayedSystemDrives; const hasSystemDrives = selectedList.filter(isSystemDrive).length; @@ -534,7 +534,7 @@ export class DriveSelector extends React.Component< if (missingDriversModal.drive !== undefined) { openExternal(missingDriversModal.drive.link); } - } catch (error) { + } catch (error: any) { logException(error); } finally { this.setState({ missingDriversModal: {} }); diff --git a/lib/gui/app/components/finish/finish.tsx b/lib/gui/app/components/finish/finish.tsx index 508bb3fa..3a1ed86c 100644 --- a/lib/gui/app/components/finish/finish.tsx +++ b/lib/gui/app/components/finish/finish.tsx @@ -59,13 +59,8 @@ function FinishPage({ goToMain }: { goToMain: () => void }) { ).map(([, error]: [string, FlashError]) => ({ ...error, })); - const { - averageSpeed, - blockmappedSize, - bytesWritten, - failed, - size, - } = flashState.getFlashState(); + const { averageSpeed, blockmappedSize, bytesWritten, failed, size } = + flashState.getFlashState(); const { skip, results = { diff --git a/lib/gui/app/components/source-selector/source-selector.tsx b/lib/gui/app/components/source-selector/source-selector.tsx index d3e62fdb..1f82391b 100644 --- a/lib/gui/app/components/source-selector/source-selector.tsx +++ b/lib/gui/app/components/source-selector/source-selector.tsx @@ -76,7 +76,7 @@ function normalizeRecentUrlImages(urls: any[]): URL[] { .map((url) => { try { return new URL(url); - } catch (error) { + } catch (error: any) { // Invalid URL, skip } }) @@ -390,7 +390,7 @@ export class SourceSelector extends React.Component< ) { try { selected = await replaceWindowsNetworkDriveLetter(selected); - } catch (error) { + } catch (error: any) { analytics.logException(error); } @@ -489,7 +489,7 @@ export class SourceSelector extends React.Component< }, }); } - } catch (error) { + } catch (error: any) { this.handleError( 'Error opening source', sourcePath, @@ -499,7 +499,7 @@ export class SourceSelector extends React.Component< } finally { try { await source.close(); - } catch (error) { + } catch (error: any) { // Noop } } @@ -589,7 +589,7 @@ export class SourceSelector extends React.Component< return; } await this.selectSource(imagePath, sourceDestination.File).promise; - } catch (error) { + } catch (error: any) { exceptionReporter.report(error); } finally { this.setState({ imageSelectorOpen: false }); diff --git a/lib/gui/app/components/target-selector/target-selector.tsx b/lib/gui/app/components/target-selector/target-selector.tsx index 7be61e8d..7c132ab0 100644 --- a/lib/gui/app/components/target-selector/target-selector.tsx +++ b/lib/gui/app/components/target-selector/target-selector.tsx @@ -14,7 +14,6 @@ * limitations under the License. */ -import { scanner } from 'etcher-sdk'; import * as React from 'react'; import { Flex, Txt } from 'rendition'; @@ -37,6 +36,7 @@ import { TargetSelectorButton } from './target-selector-button'; import TgtSvg from '../../../assets/tgt.svg'; import DriveSvg from '../../../assets/drive.svg'; import { warning } from '../../../../shared/messages'; +import { DrivelistDrive } from '../../../../shared/drive-constraints'; export const getDriveListLabel = () => { return getSelectedDrives() @@ -70,9 +70,7 @@ export const TargetSelectorModal = ( /> ); -export const selectAllTargets = ( - modalTargets: scanner.adapters.DrivelistDrive[], -) => { +export const selectAllTargets = (modalTargets: DrivelistDrive[]) => { const selectedDrivesFromState = getSelectedDrives(); const deselected = selectedDrivesFromState.filter( (drive) => @@ -114,9 +112,8 @@ export const TargetSelector = ({ const [{ driveListLabel, targets }, setStateSlice] = React.useState( getDriveSelectionStateSlice(), ); - const [showTargetSelectorModal, setShowTargetSelectorModal] = React.useState( - false, - ); + const [showTargetSelectorModal, setShowTargetSelectorModal] = + React.useState(false); React.useEffect(() => { return observe(() => { diff --git a/lib/gui/app/models/flash-state.ts b/lib/gui/app/models/flash-state.ts index e0a3ce96..edbb96ca 100644 --- a/lib/gui/app/models/flash-state.ts +++ b/lib/gui/app/models/flash-state.ts @@ -17,6 +17,7 @@ import * as electron from 'electron'; import * as sdk from 'etcher-sdk'; import * as _ from 'lodash'; +import { DrivelistDrive } from '../../../shared/drive-constraints'; import { bytesToMegabytes } from '../../../shared/units'; import { Actions, store } from './store'; @@ -84,7 +85,7 @@ export function addFailedDeviceError({ device, error, }: { - device: sdk.scanner.adapters.DrivelistDrive; + device: DrivelistDrive; error: Error; }) { const failedDeviceErrorsMap = new Map( diff --git a/lib/gui/app/models/settings.ts b/lib/gui/app/models/settings.ts index 25c9cd7a..36712884 100644 --- a/lib/gui/app/models/settings.ts +++ b/lib/gui/app/models/settings.ts @@ -51,7 +51,7 @@ async function readConfigFile(filename: string): Promise<_.Dictionary> { let contents = '{}'; try { contents = await fs.readFile(filename, { encoding: 'utf8' }); - } catch (error) { + } catch (error: any) { // noop } try { @@ -104,7 +104,7 @@ export async function set( settings[key] = value; try { await writeConfigFileFn(CONFIG_PATH, settings); - } catch (error) { + } catch (error: any) { // Revert to previous value if persisting settings failed settings[key] = previousValue; throw error; diff --git a/lib/gui/app/modules/analytics.ts b/lib/gui/app/modules/analytics.ts index d63969a5..2cd894a7 100644 --- a/lib/gui/app/modules/analytics.ts +++ b/lib/gui/app/modules/analytics.ts @@ -102,10 +102,9 @@ function validateMixpanelConfig(config: { * This function sends the debug message to product analytics services. */ export function logEvent(message: string, data: _.Dictionary = {}) { - const { - applicationSessionUuid, - flashingWorkflowUuid, - } = store.getState().toJS(); + const { applicationSessionUuid, flashingWorkflowUuid } = store + .getState() + .toJS(); resinCorvus.logEvent(message, { ...data, sample: mixpanelSample, diff --git a/lib/gui/app/modules/drive-scanner.ts b/lib/gui/app/modules/drive-scanner.ts index a76c2939..84a1af3f 100644 --- a/lib/gui/app/modules/drive-scanner.ts +++ b/lib/gui/app/modules/drive-scanner.ts @@ -15,10 +15,15 @@ */ import * as sdk from 'etcher-sdk'; +import { + Adapter, + BlockDeviceAdapter, + UsbbootDeviceAdapter, +} from 'etcher-sdk/build/scanner/adapters'; import { geteuid, platform } from 'process'; -const adapters: sdk.scanner.adapters.Adapter[] = [ - new sdk.scanner.adapters.BlockDeviceAdapter({ +const adapters: Adapter[] = [ + new BlockDeviceAdapter({ includeSystemDrives: () => true, }), ]; @@ -26,14 +31,15 @@ const adapters: sdk.scanner.adapters.Adapter[] = [ // Can't use permissions.isElevated() here as it returns a promise and we need to set // module.exports = scanner right now. if (platform !== 'linux' || geteuid() === 0) { - adapters.push(new sdk.scanner.adapters.UsbbootDeviceAdapter()); + adapters.push(new UsbbootDeviceAdapter()); } -if ( - platform === 'win32' && - sdk.scanner.adapters.DriverlessDeviceAdapter !== undefined -) { - adapters.push(new sdk.scanner.adapters.DriverlessDeviceAdapter()); +if (platform === 'win32') { + const { + DriverlessDeviceAdapter: driverless, + // tslint:disable-next-line:no-var-requires + } = require('etcher-sdk/build/scanner/adapters/driverless'); + adapters.push(new driverless()); } export const scanner = new sdk.scanner.Scanner(adapters); diff --git a/lib/gui/app/modules/image-writer.ts b/lib/gui/app/modules/image-writer.ts index c4ab0ab7..44462210 100644 --- a/lib/gui/app/modules/image-writer.ts +++ b/lib/gui/app/modules/image-writer.ts @@ -218,7 +218,7 @@ async function performWrite( }); flashResults.cancelled = cancelled || results.cancelled; flashResults.skip = skip; - } catch (error) { + } catch (error: any) { // This happens when the child is killed using SIGKILL const SIGKILL_EXIT_CODE = 137; if (error.code === SIGKILL_EXIT_CODE) { @@ -287,7 +287,7 @@ export async function flash( try { const result = await write(image, drives, flashState.setProgressState); await flashState.unsetFlashingFlag(result); - } catch (error) { + } catch (error: any) { await flashState.unsetFlashingFlag({ cancelled: false, errorCode: error.code, @@ -349,7 +349,7 @@ export async function cancel(type: string) { if (socket !== undefined) { ipc.server.emit(socket, status); } - } catch (error) { + } catch (error: any) { analytics.logException(error); } } diff --git a/lib/gui/app/os/dialog.ts b/lib/gui/app/os/dialog.ts index ce906265..cdce28c2 100644 --- a/lib/gui/app/os/dialog.ts +++ b/lib/gui/app/os/dialog.ts @@ -27,7 +27,7 @@ async function mountSourceDrive() { if (sourceDrivePath) { try { await electron.ipcRenderer.invoke('mount-drive', sourceDrivePath); - } catch (error) { + } catch (error: any) { // noop } } diff --git a/lib/gui/app/pages/main/Flash.tsx b/lib/gui/app/pages/main/Flash.tsx index 544878d2..4fc526ca 100644 --- a/lib/gui/app/pages/main/Flash.tsx +++ b/lib/gui/app/pages/main/Flash.tsx @@ -117,7 +117,7 @@ async function flashImageToDrive( } goToSuccess(); } - } catch (error) { + } catch (error: any) { notifyFailure(iconPath, basename, drives); let errorMessage = getErrorMessageFromCode(error.code); if (!errorMessage) { diff --git a/lib/gui/modules/child-writer.ts b/lib/gui/modules/child-writer.ts index fa98a45e..7a5041c1 100644 --- a/lib/gui/modules/child-writer.ts +++ b/lib/gui/modules/child-writer.ts @@ -300,7 +300,7 @@ ipc.connectTo(IPC_SERVER_ID, () => { ipc.of[IPC_SERVER_ID].emit('done', { results }); await delay(DISCONNECT_DELAY); await terminate(exitCode); - } catch (error) { + } catch (error: any) { exitCode = GENERAL_ERROR; ipc.of[IPC_SERVER_ID].emit('error', toJSON(error)); } diff --git a/lib/shared/catalina-sudo/sudo.ts b/lib/shared/catalina-sudo/sudo.ts index b6c39f0c..ad96a82c 100644 --- a/lib/shared/catalina-sudo/sudo.ts +++ b/lib/shared/catalina-sudo/sudo.ts @@ -50,7 +50,7 @@ export async function sudo( stdout: stdout.slice(EXPECTED_SUCCESSFUL_AUTH_MARKER.length), stderr, }; - } catch (error) { + } catch (error: any) { if (error.code === 1) { if (!error.stdout.startsWith(EXPECTED_SUCCESSFUL_AUTH_MARKER)) { return { cancelled: true }; diff --git a/lib/shared/permissions.ts b/lib/shared/permissions.ts index 8ae73264..7ec380b9 100755 --- a/lib/shared/permissions.ts +++ b/lib/shared/permissions.ts @@ -60,7 +60,7 @@ export async function isElevated(): Promise { // See http://stackoverflow.com/a/28268802 try { await execAsync('fltmc'); - } catch (error) { + } catch (error: any) { if (error.code === os.constants.errno.EPERM) { return false; } @@ -146,7 +146,7 @@ async function elevateScriptCatalina( try { const { cancelled } = await catalinaSudo(cmd); return { cancelled }; - } catch (error) { + } catch (error: any) { throw errors.createError({ title: error.stderr }); } } @@ -190,7 +190,7 @@ export async function elevateCommand( } try { return await elevateScriptUnix(path, options.applicationName); - } catch (error) { + } catch (error: any) { // We're hardcoding internal error messages declared by `sudo-prompt`. // There doesn't seem to be a better way to handle these errors, so // for now, we should make sure we double check if the error messages diff --git a/scripts/clean-shrinkwrap.ts b/scripts/clean-shrinkwrap.ts index 5636ef5c..78bc946d 100644 --- a/scripts/clean-shrinkwrap.ts +++ b/scripts/clean-shrinkwrap.ts @@ -37,7 +37,7 @@ async function main() { SHRINKWRAP_FILENAME, JSON.stringify(cleaned, null, JSON_INDENT), ); - } catch (error) { + } catch (error: any) { console.log(`[ERROR] Couldn't write shrinkwrap file: ${error.stack}`); process.exitCode = 1; } diff --git a/tests/gui/models/flash-state.spec.ts b/tests/gui/models/flash-state.spec.ts index e5d966a0..9f0babfd 100644 --- a/tests/gui/models/flash-state.spec.ts +++ b/tests/gui/models/flash-state.spec.ts @@ -573,7 +573,8 @@ describe('Model: flashState', function () { }); describe('.getFlashUuid()', function () { - const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/; + const UUID_REGEX = + /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/; it('should be initially undefined', function () { expect(flashState.getFlashUuid()).to.be.undefined; diff --git a/tests/gui/models/settings.spec.ts b/tests/gui/models/settings.spec.ts index cab37a74..152b0d7a 100644 --- a/tests/gui/models/settings.spec.ts +++ b/tests/gui/models/settings.spec.ts @@ -23,7 +23,7 @@ import * as settings from '../../../lib/gui/app/models/settings'; async function checkError(promise: Promise, fn: (err: Error) => any) { try { await promise; - } catch (error) { + } catch (error: any) { await fn(error); return; } diff --git a/tests/gui/modules/image-writer.spec.ts b/tests/gui/modules/image-writer.spec.ts index 4b38c844..64cf1255 100644 --- a/tests/gui/modules/image-writer.spec.ts +++ b/tests/gui/modules/image-writer.spec.ts @@ -83,7 +83,7 @@ describe('Browser: imageWriter', () => { imageWriter.flash(image, [fakeDrive], performWriteStub), ]); assert.fail('Writing twice should fail'); - } catch (error) { + } catch (error: any) { expect(error.message).to.equal( 'There is already a flash in progress', ); @@ -133,7 +133,7 @@ describe('Browser: imageWriter', () => { }); try { await imageWriter.flash(image, [fakeDrive], performWriteStub); - } catch (error) { + } catch (error: any) { expect(error).to.be.an.instanceof(Error); expect(error.message).to.equal('write error'); } diff --git a/tests/shared/drive-constraints.spec.ts b/tests/shared/drive-constraints.spec.ts index e6738ae6..e802f4ff 100644 --- a/tests/shared/drive-constraints.spec.ts +++ b/tests/shared/drive-constraints.spec.ts @@ -1158,7 +1158,7 @@ describe('Shared: DriveConstraints', function () { '/dev/disk6', ]; const drives = [ - ({ + { device: drivePaths[0], description: 'My Drive', size: 123456789, @@ -1166,8 +1166,8 @@ describe('Shared: DriveConstraints', function () { mountpoints: [{ path: __dirname }], isSystem: false, isReadOnly: false, - } as unknown) as constraints.DrivelistDrive, - ({ + } as unknown as constraints.DrivelistDrive, + { device: drivePaths[1], description: 'My Other Drive', size: 123456789, @@ -1175,8 +1175,8 @@ describe('Shared: DriveConstraints', function () { mountpoints: [], isSystem: false, isReadOnly: true, - } as unknown) as constraints.DrivelistDrive, - ({ + } as unknown as constraints.DrivelistDrive, + { device: drivePaths[2], description: 'My Drive', size: 1234567, @@ -1184,8 +1184,8 @@ describe('Shared: DriveConstraints', function () { mountpoints: [], isSystem: false, isReadOnly: false, - } as unknown) as constraints.DrivelistDrive, - ({ + } as unknown as constraints.DrivelistDrive, + { device: drivePaths[3], description: 'My Drive', size: 123456789, @@ -1193,8 +1193,8 @@ describe('Shared: DriveConstraints', function () { mountpoints: [], isSystem: true, isReadOnly: false, - } as unknown) as constraints.DrivelistDrive, - ({ + } as unknown as constraints.DrivelistDrive, + { device: drivePaths[4], description: 'My Drive', size: 128000000001, @@ -1202,8 +1202,8 @@ describe('Shared: DriveConstraints', function () { mountpoints: [], isSystem: false, isReadOnly: false, - } as unknown) as constraints.DrivelistDrive, - ({ + } as unknown as constraints.DrivelistDrive, + { device: drivePaths[5], description: 'My Drive', size: 12345678, @@ -1211,8 +1211,8 @@ describe('Shared: DriveConstraints', function () { mountpoints: [], isSystem: false, isReadOnly: false, - } as unknown) as constraints.DrivelistDrive, - ({ + } as unknown as constraints.DrivelistDrive, + { device: drivePaths[6], description: 'My Drive', size: 123456789, @@ -1220,7 +1220,7 @@ describe('Shared: DriveConstraints', function () { mountpoints: [], isSystem: false, isReadOnly: false, - } as unknown) as constraints.DrivelistDrive, + } as unknown as constraints.DrivelistDrive, ]; const image: SourceMetadata = { diff --git a/tests/shared/supported-formats.spec.ts b/tests/shared/supported-formats.spec.ts index 17bb856a..9a4ea041 100644 --- a/tests/shared/supported-formats.spec.ts +++ b/tests/shared/supported-formats.spec.ts @@ -30,9 +30,8 @@ describe('Shared: SupportedFormats', function () { ], (imagePath) => { it(`should return true if filename is ${imagePath}`, function () { - const looksLikeWindowsImage = supportedFormats.looksLikeWindowsImage( - imagePath, - ); + const looksLikeWindowsImage = + supportedFormats.looksLikeWindowsImage(imagePath); expect(looksLikeWindowsImage).to.be.true; }); }, @@ -45,9 +44,8 @@ describe('Shared: SupportedFormats', function () { ], (imagePath) => { it(`should return false if filename is ${imagePath}`, function () { - const looksLikeWindowsImage = supportedFormats.looksLikeWindowsImage( - imagePath, - ); + const looksLikeWindowsImage = + supportedFormats.looksLikeWindowsImage(imagePath); expect(looksLikeWindowsImage).to.be.false; }); }, diff --git a/tests/spectron/runner.spec.ts b/tests/spectron/runner.spec.ts index d96682af..6bda036d 100644 --- a/tests/spectron/runner.spec.ts +++ b/tests/spectron/runner.spec.ts @@ -28,7 +28,7 @@ if (platform() !== 'darwin') { this.timeout(40000); const app = new Application({ - path: (electronPath as unknown) as string, + path: electronPath as unknown as string, args: ['--no-sandbox', '.'], });