Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit a655677

Browse files
committed
Fix lint errors
1 parent fd921c3 commit a655677

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/serialmonitor/serialportctrl.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Licensed under the MIT license.
33

44
import * as os from "os";
5+
import { SerialPort } from "serialport";
6+
import * as strftime from "strftime";
57
import { BufferedOutputChannel } from "./outputBuffer";
6-
import { SerialPort } from 'serialport';
7-
import * as strftime from 'strftime';
88

99
interface ISerialPortDetail {
1010
port: string;
@@ -22,12 +22,12 @@ export class SerialPortCtrl {
2222
*
2323
*/
2424
public static async list(): Promise<ISerialPortDetail[]> {
25-
return (await SerialPort.list()).map(port => {
25+
return (await SerialPort.list()).map((port) => {
2626
return {
2727
port: port.path,
2828
desc: (port as any).friendlyName ?? port.manufacturer,
2929
vendorId: port.vendorId,
30-
productId: port.productId
30+
productId: port.productId,
3131
};
3232
});
3333
}
@@ -60,30 +60,33 @@ export class SerialPortCtrl {
6060
this._bufferedOutputChannel.appendLine(`[Starting] Opening the serial port - ${this._currentPort}`);
6161
this.showOutputChannel();
6262

63-
if (this.isActive) await this.close();
63+
if (this.isActive) { await this.close(); }
6464

6565
await new Promise<void>((resolve, reject) => {
6666
this._port = new SerialPort(
6767
{ autoOpen: false, path: this._currentPort, baudRate: this._currentBaudRate },
6868
(err) => {
69-
if (err) reject(err);
69+
if (err) { reject(err); }
7070
});
7171
this._port.open((err) => {
72-
if (err) reject(err);
73-
else resolve();
72+
if (err) {
73+
reject(err);
74+
} else {
75+
resolve();
76+
}
7477
});
7578
});
7679

7780
let lastDataEndedWithNewline = true;
7881
this._port.on("data", (data) => {
79-
const text: string = data.toString('utf8');
82+
const text: string = data.toString("utf8");
8083
if (this._currentTimestampFormat) {
8184
const timestamp = strftime(this._currentTimestampFormat);
8285
this._bufferedOutputChannel.append(
8386
// Timestamps should only be added at the beginning of a line.
8487
// Look for newlines except at the very end of the string.
85-
(lastDataEndedWithNewline ? timestamp : '') +
86-
text.replace(/\n(?!$)/g, "\n" + timestamp)
88+
(lastDataEndedWithNewline ? timestamp : "") +
89+
text.replace(/\n(?!$)/g, "\n" + timestamp),
8790
);
8891
lastDataEndedWithNewline = text.endsWith("\n");
8992
} else {
@@ -109,14 +112,14 @@ export class SerialPortCtrl {
109112
}
110113

111114
public async changePort(newPort: string): Promise<void> {
112-
if (newPort === this._currentPort) return;
115+
if (newPort === this._currentPort) { return; }
113116
this._currentPort = newPort;
114-
if (!this.isActive) return;
117+
if (!this.isActive) { return; }
115118
await this.close();
116119
}
117120

118121
public async stop(): Promise<boolean> {
119-
if (!this.isActive) return false;
122+
if (!this.isActive) { return false; }
120123

121124
await this.close();
122125
if (this._bufferedOutputChannel) {
@@ -128,7 +131,7 @@ export class SerialPortCtrl {
128131

129132
public async changeBaudRate(newRate: number): Promise<void> {
130133
this._currentBaudRate = newRate;
131-
if (!this.isActive) return;
134+
if (!this.isActive) { return; }
132135
await this.stop();
133136
await this.open();
134137
}
@@ -140,9 +143,12 @@ export class SerialPortCtrl {
140143
private close(): Promise<void> {
141144
return new Promise((resolve, reject) => {
142145
this._port.close((err) => {
143-
if (err) reject(err);
144-
this._port = undefined;
145-
resolve();
146+
if (err) {
147+
reject(err);
148+
} else {
149+
this._port = undefined;
150+
resolve();
151+
}
146152
})
147153
});
148154
}

0 commit comments

Comments
 (0)