patch: Fix linting errors

Signed-off-by: Lorenzo Alberto Maria Ambrosi <lorenzothunder.ambrosi@gmail.com>
This commit is contained in:
Lorenzo Alberto Maria Ambrosi 2021-10-13 17:21:48 +02:00
parent a3c24a26a0
commit 00e8f11913
22 changed files with 72 additions and 76 deletions

View File

@ -217,8 +217,7 @@ function prepareDrive(drive: Drive) {
disabled: true, disabled: true,
icon: 'warning', icon: 'warning',
size: null, size: null,
link: link: 'https://www.raspberrypi.org/documentation/hardware/computemodule/cm-emmc-flashing.md',
'https://www.raspberrypi.org/documentation/hardware/computemodule/cm-emmc-flashing.md',
linkCTA: 'Install', linkCTA: 'Install',
linkTitle: 'Install missing drivers', linkTitle: 'Install missing drivers',
linkMessage: outdent` linkMessage: outdent`
@ -335,7 +334,7 @@ window.addEventListener('beforeunload', async (event) => {
flashingWorkflowUuid, flashingWorkflowUuid,
}); });
popupExists = false; popupExists = false;
} catch (error) { } catch (error: any) {
exceptionReporter.report(error); exceptionReporter.report(error);
} }
}); });

View File

@ -379,8 +379,8 @@ export class DriveSelector extends React.Component<
const displayedDrives = this.getDisplayedDrives(drives); const displayedDrives = this.getDisplayedDrives(drives);
const disabledDrives = this.getDisabledDrives(drives, image); const disabledDrives = this.getDisabledDrives(drives, image);
const numberOfSystemDrives = drives.filter(isSystemDrive).length; const numberOfSystemDrives = drives.filter(isSystemDrive).length;
const numberOfDisplayedSystemDrives = displayedDrives.filter(isSystemDrive) const numberOfDisplayedSystemDrives =
.length; displayedDrives.filter(isSystemDrive).length;
const numberOfHiddenSystemDrives = const numberOfHiddenSystemDrives =
numberOfSystemDrives - numberOfDisplayedSystemDrives; numberOfSystemDrives - numberOfDisplayedSystemDrives;
const hasSystemDrives = selectedList.filter(isSystemDrive).length; const hasSystemDrives = selectedList.filter(isSystemDrive).length;
@ -534,7 +534,7 @@ export class DriveSelector extends React.Component<
if (missingDriversModal.drive !== undefined) { if (missingDriversModal.drive !== undefined) {
openExternal(missingDriversModal.drive.link); openExternal(missingDriversModal.drive.link);
} }
} catch (error) { } catch (error: any) {
logException(error); logException(error);
} finally { } finally {
this.setState({ missingDriversModal: {} }); this.setState({ missingDriversModal: {} });

View File

@ -59,13 +59,8 @@ function FinishPage({ goToMain }: { goToMain: () => void }) {
).map(([, error]: [string, FlashError]) => ({ ).map(([, error]: [string, FlashError]) => ({
...error, ...error,
})); }));
const { const { averageSpeed, blockmappedSize, bytesWritten, failed, size } =
averageSpeed, flashState.getFlashState();
blockmappedSize,
bytesWritten,
failed,
size,
} = flashState.getFlashState();
const { const {
skip, skip,
results = { results = {

View File

@ -76,7 +76,7 @@ function normalizeRecentUrlImages(urls: any[]): URL[] {
.map((url) => { .map((url) => {
try { try {
return new URL(url); return new URL(url);
} catch (error) { } catch (error: any) {
// Invalid URL, skip // Invalid URL, skip
} }
}) })
@ -390,7 +390,7 @@ export class SourceSelector extends React.Component<
) { ) {
try { try {
selected = await replaceWindowsNetworkDriveLetter(selected); selected = await replaceWindowsNetworkDriveLetter(selected);
} catch (error) { } catch (error: any) {
analytics.logException(error); analytics.logException(error);
} }
@ -489,7 +489,7 @@ export class SourceSelector extends React.Component<
}, },
}); });
} }
} catch (error) { } catch (error: any) {
this.handleError( this.handleError(
'Error opening source', 'Error opening source',
sourcePath, sourcePath,
@ -499,7 +499,7 @@ export class SourceSelector extends React.Component<
} finally { } finally {
try { try {
await source.close(); await source.close();
} catch (error) { } catch (error: any) {
// Noop // Noop
} }
} }
@ -589,7 +589,7 @@ export class SourceSelector extends React.Component<
return; return;
} }
await this.selectSource(imagePath, sourceDestination.File).promise; await this.selectSource(imagePath, sourceDestination.File).promise;
} catch (error) { } catch (error: any) {
exceptionReporter.report(error); exceptionReporter.report(error);
} finally { } finally {
this.setState({ imageSelectorOpen: false }); this.setState({ imageSelectorOpen: false });

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
import { scanner } from 'etcher-sdk';
import * as React from 'react'; import * as React from 'react';
import { Flex, Txt } from 'rendition'; import { Flex, Txt } from 'rendition';
@ -37,6 +36,7 @@ import { TargetSelectorButton } from './target-selector-button';
import TgtSvg from '../../../assets/tgt.svg'; import TgtSvg from '../../../assets/tgt.svg';
import DriveSvg from '../../../assets/drive.svg'; import DriveSvg from '../../../assets/drive.svg';
import { warning } from '../../../../shared/messages'; import { warning } from '../../../../shared/messages';
import { DrivelistDrive } from '../../../../shared/drive-constraints';
export const getDriveListLabel = () => { export const getDriveListLabel = () => {
return getSelectedDrives() return getSelectedDrives()
@ -70,9 +70,7 @@ export const TargetSelectorModal = (
/> />
); );
export const selectAllTargets = ( export const selectAllTargets = (modalTargets: DrivelistDrive[]) => {
modalTargets: scanner.adapters.DrivelistDrive[],
) => {
const selectedDrivesFromState = getSelectedDrives(); const selectedDrivesFromState = getSelectedDrives();
const deselected = selectedDrivesFromState.filter( const deselected = selectedDrivesFromState.filter(
(drive) => (drive) =>
@ -114,9 +112,8 @@ export const TargetSelector = ({
const [{ driveListLabel, targets }, setStateSlice] = React.useState( const [{ driveListLabel, targets }, setStateSlice] = React.useState(
getDriveSelectionStateSlice(), getDriveSelectionStateSlice(),
); );
const [showTargetSelectorModal, setShowTargetSelectorModal] = React.useState( const [showTargetSelectorModal, setShowTargetSelectorModal] =
false, React.useState(false);
);
React.useEffect(() => { React.useEffect(() => {
return observe(() => { return observe(() => {

View File

@ -17,6 +17,7 @@
import * as electron from 'electron'; import * as electron from 'electron';
import * as sdk from 'etcher-sdk'; import * as sdk from 'etcher-sdk';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { DrivelistDrive } from '../../../shared/drive-constraints';
import { bytesToMegabytes } from '../../../shared/units'; import { bytesToMegabytes } from '../../../shared/units';
import { Actions, store } from './store'; import { Actions, store } from './store';
@ -84,7 +85,7 @@ export function addFailedDeviceError({
device, device,
error, error,
}: { }: {
device: sdk.scanner.adapters.DrivelistDrive; device: DrivelistDrive;
error: Error; error: Error;
}) { }) {
const failedDeviceErrorsMap = new Map( const failedDeviceErrorsMap = new Map(

View File

@ -51,7 +51,7 @@ async function readConfigFile(filename: string): Promise<_.Dictionary<any>> {
let contents = '{}'; let contents = '{}';
try { try {
contents = await fs.readFile(filename, { encoding: 'utf8' }); contents = await fs.readFile(filename, { encoding: 'utf8' });
} catch (error) { } catch (error: any) {
// noop // noop
} }
try { try {
@ -104,7 +104,7 @@ export async function set(
settings[key] = value; settings[key] = value;
try { try {
await writeConfigFileFn(CONFIG_PATH, settings); await writeConfigFileFn(CONFIG_PATH, settings);
} catch (error) { } catch (error: any) {
// Revert to previous value if persisting settings failed // Revert to previous value if persisting settings failed
settings[key] = previousValue; settings[key] = previousValue;
throw error; throw error;

View File

@ -102,10 +102,9 @@ function validateMixpanelConfig(config: {
* This function sends the debug message to product analytics services. * This function sends the debug message to product analytics services.
*/ */
export function logEvent(message: string, data: _.Dictionary<any> = {}) { export function logEvent(message: string, data: _.Dictionary<any> = {}) {
const { const { applicationSessionUuid, flashingWorkflowUuid } = store
applicationSessionUuid, .getState()
flashingWorkflowUuid, .toJS();
} = store.getState().toJS();
resinCorvus.logEvent(message, { resinCorvus.logEvent(message, {
...data, ...data,
sample: mixpanelSample, sample: mixpanelSample,

View File

@ -15,10 +15,15 @@
*/ */
import * as sdk from 'etcher-sdk'; import * as sdk from 'etcher-sdk';
import {
Adapter,
BlockDeviceAdapter,
UsbbootDeviceAdapter,
} from 'etcher-sdk/build/scanner/adapters';
import { geteuid, platform } from 'process'; import { geteuid, platform } from 'process';
const adapters: sdk.scanner.adapters.Adapter[] = [ const adapters: Adapter[] = [
new sdk.scanner.adapters.BlockDeviceAdapter({ new BlockDeviceAdapter({
includeSystemDrives: () => true, 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 // Can't use permissions.isElevated() here as it returns a promise and we need to set
// module.exports = scanner right now. // module.exports = scanner right now.
if (platform !== 'linux' || geteuid() === 0) { if (platform !== 'linux' || geteuid() === 0) {
adapters.push(new sdk.scanner.adapters.UsbbootDeviceAdapter()); adapters.push(new UsbbootDeviceAdapter());
} }
if ( if (platform === 'win32') {
platform === 'win32' && const {
sdk.scanner.adapters.DriverlessDeviceAdapter !== undefined DriverlessDeviceAdapter: driverless,
) { // tslint:disable-next-line:no-var-requires
adapters.push(new sdk.scanner.adapters.DriverlessDeviceAdapter()); } = require('etcher-sdk/build/scanner/adapters/driverless');
adapters.push(new driverless());
} }
export const scanner = new sdk.scanner.Scanner(adapters); export const scanner = new sdk.scanner.Scanner(adapters);

View File

@ -218,7 +218,7 @@ async function performWrite(
}); });
flashResults.cancelled = cancelled || results.cancelled; flashResults.cancelled = cancelled || results.cancelled;
flashResults.skip = skip; flashResults.skip = skip;
} catch (error) { } catch (error: any) {
// This happens when the child is killed using SIGKILL // This happens when the child is killed using SIGKILL
const SIGKILL_EXIT_CODE = 137; const SIGKILL_EXIT_CODE = 137;
if (error.code === SIGKILL_EXIT_CODE) { if (error.code === SIGKILL_EXIT_CODE) {
@ -287,7 +287,7 @@ export async function flash(
try { try {
const result = await write(image, drives, flashState.setProgressState); const result = await write(image, drives, flashState.setProgressState);
await flashState.unsetFlashingFlag(result); await flashState.unsetFlashingFlag(result);
} catch (error) { } catch (error: any) {
await flashState.unsetFlashingFlag({ await flashState.unsetFlashingFlag({
cancelled: false, cancelled: false,
errorCode: error.code, errorCode: error.code,
@ -349,7 +349,7 @@ export async function cancel(type: string) {
if (socket !== undefined) { if (socket !== undefined) {
ipc.server.emit(socket, status); ipc.server.emit(socket, status);
} }
} catch (error) { } catch (error: any) {
analytics.logException(error); analytics.logException(error);
} }
} }

View File

@ -27,7 +27,7 @@ async function mountSourceDrive() {
if (sourceDrivePath) { if (sourceDrivePath) {
try { try {
await electron.ipcRenderer.invoke('mount-drive', sourceDrivePath); await electron.ipcRenderer.invoke('mount-drive', sourceDrivePath);
} catch (error) { } catch (error: any) {
// noop // noop
} }
} }

View File

@ -117,7 +117,7 @@ async function flashImageToDrive(
} }
goToSuccess(); goToSuccess();
} }
} catch (error) { } catch (error: any) {
notifyFailure(iconPath, basename, drives); notifyFailure(iconPath, basename, drives);
let errorMessage = getErrorMessageFromCode(error.code); let errorMessage = getErrorMessageFromCode(error.code);
if (!errorMessage) { if (!errorMessage) {

View File

@ -300,7 +300,7 @@ ipc.connectTo(IPC_SERVER_ID, () => {
ipc.of[IPC_SERVER_ID].emit('done', { results }); ipc.of[IPC_SERVER_ID].emit('done', { results });
await delay(DISCONNECT_DELAY); await delay(DISCONNECT_DELAY);
await terminate(exitCode); await terminate(exitCode);
} catch (error) { } catch (error: any) {
exitCode = GENERAL_ERROR; exitCode = GENERAL_ERROR;
ipc.of[IPC_SERVER_ID].emit('error', toJSON(error)); ipc.of[IPC_SERVER_ID].emit('error', toJSON(error));
} }

View File

@ -50,7 +50,7 @@ export async function sudo(
stdout: stdout.slice(EXPECTED_SUCCESSFUL_AUTH_MARKER.length), stdout: stdout.slice(EXPECTED_SUCCESSFUL_AUTH_MARKER.length),
stderr, stderr,
}; };
} catch (error) { } catch (error: any) {
if (error.code === 1) { if (error.code === 1) {
if (!error.stdout.startsWith(EXPECTED_SUCCESSFUL_AUTH_MARKER)) { if (!error.stdout.startsWith(EXPECTED_SUCCESSFUL_AUTH_MARKER)) {
return { cancelled: true }; return { cancelled: true };

View File

@ -60,7 +60,7 @@ export async function isElevated(): Promise<boolean> {
// See http://stackoverflow.com/a/28268802 // See http://stackoverflow.com/a/28268802
try { try {
await execAsync('fltmc'); await execAsync('fltmc');
} catch (error) { } catch (error: any) {
if (error.code === os.constants.errno.EPERM) { if (error.code === os.constants.errno.EPERM) {
return false; return false;
} }
@ -146,7 +146,7 @@ async function elevateScriptCatalina(
try { try {
const { cancelled } = await catalinaSudo(cmd); const { cancelled } = await catalinaSudo(cmd);
return { cancelled }; return { cancelled };
} catch (error) { } catch (error: any) {
throw errors.createError({ title: error.stderr }); throw errors.createError({ title: error.stderr });
} }
} }
@ -190,7 +190,7 @@ export async function elevateCommand(
} }
try { try {
return await elevateScriptUnix(path, options.applicationName); return await elevateScriptUnix(path, options.applicationName);
} catch (error) { } catch (error: any) {
// We're hardcoding internal error messages declared by `sudo-prompt`. // We're hardcoding internal error messages declared by `sudo-prompt`.
// There doesn't seem to be a better way to handle these errors, so // 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 // for now, we should make sure we double check if the error messages

View File

@ -37,7 +37,7 @@ async function main() {
SHRINKWRAP_FILENAME, SHRINKWRAP_FILENAME,
JSON.stringify(cleaned, null, JSON_INDENT), JSON.stringify(cleaned, null, JSON_INDENT),
); );
} catch (error) { } catch (error: any) {
console.log(`[ERROR] Couldn't write shrinkwrap file: ${error.stack}`); console.log(`[ERROR] Couldn't write shrinkwrap file: ${error.stack}`);
process.exitCode = 1; process.exitCode = 1;
} }

View File

@ -573,7 +573,8 @@ describe('Model: flashState', function () {
}); });
describe('.getFlashUuid()', 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 () { it('should be initially undefined', function () {
expect(flashState.getFlashUuid()).to.be.undefined; expect(flashState.getFlashUuid()).to.be.undefined;

View File

@ -23,7 +23,7 @@ import * as settings from '../../../lib/gui/app/models/settings';
async function checkError(promise: Promise<any>, fn: (err: Error) => any) { async function checkError(promise: Promise<any>, fn: (err: Error) => any) {
try { try {
await promise; await promise;
} catch (error) { } catch (error: any) {
await fn(error); await fn(error);
return; return;
} }

View File

@ -83,7 +83,7 @@ describe('Browser: imageWriter', () => {
imageWriter.flash(image, [fakeDrive], performWriteStub), imageWriter.flash(image, [fakeDrive], performWriteStub),
]); ]);
assert.fail('Writing twice should fail'); assert.fail('Writing twice should fail');
} catch (error) { } catch (error: any) {
expect(error.message).to.equal( expect(error.message).to.equal(
'There is already a flash in progress', 'There is already a flash in progress',
); );
@ -133,7 +133,7 @@ describe('Browser: imageWriter', () => {
}); });
try { try {
await imageWriter.flash(image, [fakeDrive], performWriteStub); await imageWriter.flash(image, [fakeDrive], performWriteStub);
} catch (error) { } catch (error: any) {
expect(error).to.be.an.instanceof(Error); expect(error).to.be.an.instanceof(Error);
expect(error.message).to.equal('write error'); expect(error.message).to.equal('write error');
} }

View File

@ -1158,7 +1158,7 @@ describe('Shared: DriveConstraints', function () {
'/dev/disk6', '/dev/disk6',
]; ];
const drives = [ const drives = [
({ {
device: drivePaths[0], device: drivePaths[0],
description: 'My Drive', description: 'My Drive',
size: 123456789, size: 123456789,
@ -1166,8 +1166,8 @@ describe('Shared: DriveConstraints', function () {
mountpoints: [{ path: __dirname }], mountpoints: [{ path: __dirname }],
isSystem: false, isSystem: false,
isReadOnly: false, isReadOnly: false,
} as unknown) as constraints.DrivelistDrive, } as unknown as constraints.DrivelistDrive,
({ {
device: drivePaths[1], device: drivePaths[1],
description: 'My Other Drive', description: 'My Other Drive',
size: 123456789, size: 123456789,
@ -1175,8 +1175,8 @@ describe('Shared: DriveConstraints', function () {
mountpoints: [], mountpoints: [],
isSystem: false, isSystem: false,
isReadOnly: true, isReadOnly: true,
} as unknown) as constraints.DrivelistDrive, } as unknown as constraints.DrivelistDrive,
({ {
device: drivePaths[2], device: drivePaths[2],
description: 'My Drive', description: 'My Drive',
size: 1234567, size: 1234567,
@ -1184,8 +1184,8 @@ describe('Shared: DriveConstraints', function () {
mountpoints: [], mountpoints: [],
isSystem: false, isSystem: false,
isReadOnly: false, isReadOnly: false,
} as unknown) as constraints.DrivelistDrive, } as unknown as constraints.DrivelistDrive,
({ {
device: drivePaths[3], device: drivePaths[3],
description: 'My Drive', description: 'My Drive',
size: 123456789, size: 123456789,
@ -1193,8 +1193,8 @@ describe('Shared: DriveConstraints', function () {
mountpoints: [], mountpoints: [],
isSystem: true, isSystem: true,
isReadOnly: false, isReadOnly: false,
} as unknown) as constraints.DrivelistDrive, } as unknown as constraints.DrivelistDrive,
({ {
device: drivePaths[4], device: drivePaths[4],
description: 'My Drive', description: 'My Drive',
size: 128000000001, size: 128000000001,
@ -1202,8 +1202,8 @@ describe('Shared: DriveConstraints', function () {
mountpoints: [], mountpoints: [],
isSystem: false, isSystem: false,
isReadOnly: false, isReadOnly: false,
} as unknown) as constraints.DrivelistDrive, } as unknown as constraints.DrivelistDrive,
({ {
device: drivePaths[5], device: drivePaths[5],
description: 'My Drive', description: 'My Drive',
size: 12345678, size: 12345678,
@ -1211,8 +1211,8 @@ describe('Shared: DriveConstraints', function () {
mountpoints: [], mountpoints: [],
isSystem: false, isSystem: false,
isReadOnly: false, isReadOnly: false,
} as unknown) as constraints.DrivelistDrive, } as unknown as constraints.DrivelistDrive,
({ {
device: drivePaths[6], device: drivePaths[6],
description: 'My Drive', description: 'My Drive',
size: 123456789, size: 123456789,
@ -1220,7 +1220,7 @@ describe('Shared: DriveConstraints', function () {
mountpoints: [], mountpoints: [],
isSystem: false, isSystem: false,
isReadOnly: false, isReadOnly: false,
} as unknown) as constraints.DrivelistDrive, } as unknown as constraints.DrivelistDrive,
]; ];
const image: SourceMetadata = { const image: SourceMetadata = {

View File

@ -30,9 +30,8 @@ describe('Shared: SupportedFormats', function () {
], ],
(imagePath) => { (imagePath) => {
it(`should return true if filename is ${imagePath}`, function () { it(`should return true if filename is ${imagePath}`, function () {
const looksLikeWindowsImage = supportedFormats.looksLikeWindowsImage( const looksLikeWindowsImage =
imagePath, supportedFormats.looksLikeWindowsImage(imagePath);
);
expect(looksLikeWindowsImage).to.be.true; expect(looksLikeWindowsImage).to.be.true;
}); });
}, },
@ -45,9 +44,8 @@ describe('Shared: SupportedFormats', function () {
], ],
(imagePath) => { (imagePath) => {
it(`should return false if filename is ${imagePath}`, function () { it(`should return false if filename is ${imagePath}`, function () {
const looksLikeWindowsImage = supportedFormats.looksLikeWindowsImage( const looksLikeWindowsImage =
imagePath, supportedFormats.looksLikeWindowsImage(imagePath);
);
expect(looksLikeWindowsImage).to.be.false; expect(looksLikeWindowsImage).to.be.false;
}); });
}, },

View File

@ -28,7 +28,7 @@ if (platform() !== 'darwin') {
this.timeout(40000); this.timeout(40000);
const app = new Application({ const app = new Application({
path: (electronPath as unknown) as string, path: electronPath as unknown as string,
args: ['--no-sandbox', '.'], args: ['--no-sandbox', '.'],
}); });