chore: integrate ESLint

This commit is contained in:
Simon Chan 2022-12-22 01:42:24 +08:00
parent 8bcd0ab913
commit aa033e4de6
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
177 changed files with 5604 additions and 3798 deletions

View file

@ -1,7 +1,13 @@
import { GatherStringStream, DecodeUtf8Stream } from '@yume-chan/stream-extra';
import { DecodeUtf8Stream, GatherStringStream } from "@yume-chan/stream-extra";
import { AdbCommandBase } from '../base.js';
import { AdbSubprocessNoneProtocol, AdbSubprocessProtocol, AdbSubprocessProtocolConstructor, AdbSubprocessShellProtocol } from './protocols/index.js';
import { AdbCommandBase } from "../base.js";
import {
AdbSubprocessNoneProtocol,
AdbSubprocessShellProtocol,
type AdbSubprocessProtocol,
type AdbSubprocessProtocolConstructor,
} from "./protocols/index.js";
export interface AdbSubprocessOptions {
/**
@ -30,7 +36,7 @@ export interface AdbSubprocessWaitResult {
export class AdbSubprocess extends AdbCommandBase {
private async createProtocol(
mode: 'pty' | 'raw',
mode: "pty" | "raw",
command?: string | string[],
options?: Partial<AdbSubprocessOptions>
): Promise<AdbSubprocessProtocol> {
@ -46,14 +52,14 @@ export class AdbSubprocess extends AdbCommandBase {
}
if (!Constructor) {
throw new Error('No specified protocol is supported by the device');
throw new Error("No specified protocol is supported by the device");
}
if (Array.isArray(command)) {
command = command.join(' ');
command = command.join(" ");
} else if (command === undefined) {
// spawn the default shell
command = '';
command = "";
}
return await Constructor[mode](this.adb, command);
}
@ -68,7 +74,7 @@ export class AdbSubprocess extends AdbCommandBase {
command?: string | string[],
options?: Partial<AdbSubprocessOptions>
): Promise<AdbSubprocessProtocol> {
return this.createProtocol('pty', command, options);
return this.createProtocol("pty", command, options);
}
/**
@ -81,7 +87,7 @@ export class AdbSubprocess extends AdbCommandBase {
command: string | string[],
options?: Partial<AdbSubprocessOptions>
): Promise<AdbSubprocessProtocol> {
return this.createProtocol('raw', command, options);
return this.createProtocol("raw", command, options);
}
/**
@ -100,13 +106,9 @@ export class AdbSubprocess extends AdbCommandBase {
const stderr = new GatherStringStream();
const [, , exitCode] = await Promise.all([
shell.stdout
.pipeThrough(new DecodeUtf8Stream())
.pipeTo(stdout),
shell.stderr
.pipeThrough(new DecodeUtf8Stream())
.pipeTo(stderr),
shell.exit
shell.stdout.pipeThrough(new DecodeUtf8Stream()).pipeTo(stdout),
shell.stderr.pipeThrough(new DecodeUtf8Stream()).pipeTo(stderr),
shell.exit,
]);
return {
@ -121,11 +123,12 @@ export class AdbSubprocess extends AdbCommandBase {
* @param command The command to run
* @returns The entire output of the command
*/
public async spawnAndWaitLegacy(command: string | string[]): Promise<string> {
const { stdout } = await this.spawnAndWait(
command,
{ protocols: [AdbSubprocessNoneProtocol] }
);
public async spawnAndWaitLegacy(
command: string | string[]
): Promise<string> {
const { stdout } = await this.spawnAndWait(command, {
protocols: [AdbSubprocessNoneProtocol],
});
return stdout;
}
}