Skip to content

Commit 9907957

Browse files
Copilottolauwae
andcommitted
Revert medium and should-not-fix changes, keep only auto-fixable and easy ESLint fixes
Co-authored-by: tolauwae <31000331+tolauwae@users.noreply.github.com>
1 parent e96af3d commit 9907957

10 files changed

Lines changed: 47 additions & 51 deletions

File tree

eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export default [
1313
}, rules: {
1414
'@stylistic/js/indent': ['error', 4, { "SwitchCase": 1 }],
1515
'@typescript-eslint/no-wrapper-object-types': 'off',
16-
'@typescript-eslint/no-namespace': 'off',
1716
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }]
1817
}
1918
},

src/framework/Archiver.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {writeFileSync} from 'fs';
22

33
export class Archiver {
4-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
54
private readonly information: any;
65
public readonly archive: string;
76

src/framework/Testee.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export class Testee { // TODO unified with testbed interface
9191
}
9292

9393
public async initialize(program: string, args: string[] = []): Promise<Testee> {
94-
// eslint-disable-next-line no-async-promise-executor
9594
return new Promise(async (resolve, reject) => {
9695
if (this.specification.type === PlatformType.emu2emu) {
9796
const spec = (this.specification as OutofPlaceSpecification).proxy;
@@ -142,7 +141,6 @@ export class Testee { // TODO unified with testbed interface
142141
}
143142

144143
public async describe(description: TestScenario, suiteResult: SuiteResult, runs: number = 1) {
145-
// eslint-disable-next-line @typescript-eslint/no-this-alias
146144
const testee = this;
147145
const scenarioResult: ScenarioResult = new ScenarioResult(description);
148146

src/framework/scenario/Actions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import {Breakpoint} from '../../debug/Breakpoint';
55
import {breakpointHitParser} from '../../messaging/Parsers';
66

77
export interface Dictionary {
8-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
98
[index: string]: any;
109
}
1110

12-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
11+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1312
export type Assertable<T extends Object | void> = {[index: string]: any};
1413

1514
export function assertable(obj: Object): Assertable<Object> {

src/framework/scenario/Step.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export type Expected<T> =
2424
| { kind: 'behaviour'; value: Behaviour };
2525

2626
export interface Expectation {
27-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2827
[key: string]: Expected<any>;
2928
}
3029

@@ -35,9 +34,7 @@ export enum Kind {
3534

3635
export type Instruction =
3736
/** discrimination union */
38-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3937
| { kind: Kind.Request; value: Request<any> }
40-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4138
| { kind: Kind.Action; value: Action<any> };
4239

4340
export interface Step {

src/manage/Compiler.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ export class AsScriptCompiler extends Compiler {
167167
}
168168

169169
public async map(program: string): Promise<CompileOutput> {
170-
return this.compile(program).then(async (output: CompileOutput) => {
170+
const emitter = this;
171+
return this.compile(program).then(async function (output: CompileOutput) {
171172
output.map = await new AsScriptMapper(program, path.dirname(output.file)).mapping();
172-
this.emit(CompilationEvents.sourcemap);
173+
emitter.emit(CompilationEvents.sourcemap);
173174
return Promise.resolve(output);
174175
});
175176
}
@@ -208,9 +209,9 @@ export class AsScriptCompiler extends Compiler {
208209
// }
209210

210211
// compile AS to Wasm and WAT
211-
const file = `${dir}/upload.wasm`;
212-
const command = await this.getCompilationCommand(program, file);
213-
return new Promise<CompileOutput>((resolve, reject) => {
212+
return new Promise<CompileOutput>(async (resolve, reject) => {
213+
const file = `${dir}/upload.wasm`;
214+
const command = await this.getCompilationCommand(program, file);
214215
let out: string = '';
215216
let err: string = '';
216217

@@ -233,11 +234,13 @@ export class AsScriptCompiler extends Compiler {
233234
});
234235
}
235236

236-
private async getCompilationCommand(program: string, output: string): Promise<string> {
237+
private getCompilationCommand(program: string, output: string): Promise<string> {
237238
// builds asc command based on the version of asc
238-
const version: Version = await AsScriptCompiler.retrieveVersion();
239-
return `npx asc ${program} --exportTable --disable bulk-memory --sourceMap --debug ` +
240-
`${(version.major > 0 || +version.minor >= 20) ? '--outFile' : '--binaryFile'} ${output}`;
239+
return new Promise<string>(async (resolve) => {
240+
const version: Version = await AsScriptCompiler.retrieveVersion();
241+
resolve(`npx asc ${program} --exportTable --disable bulk-memory --sourceMap --debug ` +
242+
`${(version.major > 0 || +version.minor >= 20) ? '--outFile' : '--binaryFile'} ${output}`);
243+
});
241244
}
242245

243246
private static retrieveVersion(): Promise<Version> {

src/manage/Uploader.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ export class EmulatorConnector extends Uploader {
7777
this.port = options.port;
7878
}
7979

80-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8180
upload(compiled: CompileOutput, listener?: (chunk: any) => void): Promise<SubProcess> {
8281
return this.connectSocket(compiled.file, listener);
8382
}
8483

85-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8684
private connectSocket(program: string, listener?: (chunk: any) => void): Promise<SubProcess> {
87-
return new Promise((resolve, _reject) => {
85+
const that = this;
86+
87+
return new Promise(function (resolve, _reject) {
8888
const client = new net.Socket();
89-
client.connect(this.port, () => {
90-
this.emit(UploaderEvents.connected);
89+
client.connect(that.port, () => {
90+
that.emit(UploaderEvents.connected);
9191
if (listener !== undefined) {
9292
client.on('data', listener);
9393
}
@@ -109,7 +109,6 @@ export class EmulatorUploader extends Uploader {
109109
this.args = args;
110110
}
111111

112-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
113112
upload(compiled: CompileOutput, listener?: (chunk: any) => void): Promise<SubProcess> {
114113
return this.connectSocket(compiled.file, listener);
115114
}
@@ -119,16 +118,16 @@ export class EmulatorUploader extends Uploader {
119118
return spawn(this.interpreter, _args);
120119
}
121120

122-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
123121
private connectSocket(program: string, listener?: (chunk: any) => void): Promise<SubProcess> {
122+
const that = this;
124123
const process = this.startWARDuino(program);
125124

126-
return new Promise((resolve, reject) => {
125+
return new Promise(function (resolve, reject) {
127126
if (process === undefined) {
128127
reject('Failed to start process.');
129128
}
130129

131-
this.emit(UploaderEvents.started);
130+
that.emit(UploaderEvents.started);
132131

133132
while (process.stdout === undefined) {
134133
// wait for stdout to become available
@@ -145,12 +144,12 @@ export class EmulatorUploader extends Uploader {
145144
listener(data);
146145
}
147146

148-
this.emit(UploaderEvents.connecting);
147+
that.emit(UploaderEvents.connecting);
149148

150149
if (data.includes('Listening')) {
151150
const client = new net.Socket();
152-
client.connect(this.port, () => {
153-
this.emit(UploaderEvents.connected);
151+
client.connect(that.port, () => {
152+
that.emit(UploaderEvents.connected);
154153
if (listener !== undefined) {
155154
client.on('data', listener);
156155
}
@@ -166,11 +165,11 @@ export class EmulatorUploader extends Uploader {
166165
});
167166

168167
reader.on('close', () => {
169-
this.emit(UploaderEvents.failed);
168+
that.emit(UploaderEvents.failed);
170169
reject(`Could not connect. Error: ${error}`);
171170
});
172171
} else {
173-
this.emit(UploaderEvents.failed);
172+
that.emit(UploaderEvents.failed);
174173
reject();
175174
}
176175
});
@@ -180,7 +179,6 @@ export class EmulatorUploader extends Uploader {
180179
export class ArduinoUploader extends Uploader {
181180
private readonly sdkpath: string;
182181
private readonly fqbn: string;
183-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
184182
private readonly options: SerialPortOpenOptions<any>;
185183

186184
constructor(sdkpath: string, _args: string[] = [], options: SerialOptions) {
@@ -207,12 +205,13 @@ export class ArduinoUploader extends Uploader {
207205
}
208206

209207
private stage(program: string): Promise<void> {
208+
const that = this;
210209
return new Promise<void>((resolve, reject) => {
211210
const compile = exec(`make compile PAUSED=true BINARY=${program}`, {cwd: this.sdkpath});
212211

213212
compile.on('close', (code) => {
214213
if (code !== 0) {
215-
this.emit(UploaderEvents.failed);
214+
that.emit(UploaderEvents.failed);
216215
reject('staging failed: unable to build Arduino program');
217216
return;
218217
}
@@ -222,14 +221,15 @@ export class ArduinoUploader extends Uploader {
222221
}
223222

224223
private flash(): Promise<void> {
224+
const that = this;
225225
return new Promise<void>((resolve, reject) => {
226226
const command = `make flash PORT=${this.options.path} FQBN=${this.fqbn}`;
227227

228228
const upload = exec(command, {cwd: this.sdkpath});
229229

230230
upload.on('close', (code) => {
231231
if (code !== 0) {
232-
this.emit(UploaderEvents.failed);
232+
that.emit(UploaderEvents.failed);
233233
reject(`unable to flash program to ${this.fqbn}`);
234234
return;
235235
}
@@ -239,17 +239,18 @@ export class ArduinoUploader extends Uploader {
239239
}
240240

241241
private connect(): Promise<Serial> {
242+
const that = this;
242243
return new Promise<Serial>((resolve, reject) => {
243244
const channel = new SerialPort(this.options,
244245
(error) => {
245246
if (error) {
246-
this.emit(UploaderEvents.failed);
247+
that.emit(UploaderEvents.failed);
247248
reject(`could not connect to serial port: ${this.options.path}`);
248249
return;
249250
}
250251
}
251252
);
252-
this.emit(UploaderEvents.connected);
253+
that.emit(UploaderEvents.connected);
253254
resolve(new Serial(channel));
254255
});
255256
}

src/messaging/Parsers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export function invokeParser(text: string): WASM.Value<Type> | Exception {
1919
if (exception(text)) {
2020
return {text: text};
2121
}
22-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2322
const stack: {value: any, type: any}[] = stateParser(text).stack!;
2423
if (stack.length == 0) {
2524
return nothing;

src/testbeds/Platform.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ type PromiseResolver<R> = (value: R | PromiseLike<R>) => void;
1010
export abstract class Platform extends EventEmitter implements Testbed {
1111
abstract connection: Connection;
1212

13-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1413
protected requests: [Request<any>, PromiseResolver<any>][];
1514

1615
protected messages: MessageQueue;
@@ -84,7 +83,6 @@ export abstract class Platform extends EventEmitter implements Testbed {
8483
public sendRequest<R>(map: SourceMap.Mapping, request: Request<R>): Promise<R> {
8584
return new Promise((resolve, reject) => {
8685
this.requests.push([request, resolve]);
87-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8886
this.connection.channel.write(`${request.type}${request.payload?.(map) ?? ''}\n`, (err: any) => {
8987
if (err !== null) {
9088
reject(err);

src/util/retry.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
export async function retry<T>(promise: () => Promise<T>, retries: number): Promise<T> {
2-
let attempt: number = 0;
3-
let trying: boolean = true;
4-
while (trying) {
5-
trying = false;
6-
try {
7-
return await promise();
8-
} catch {
9-
trying = ++attempt < retries;
1+
export function retry<T>(promise: () => Promise<T>, retries: number): Promise<T> {
2+
return new Promise<T>(async function (resolve, reject) {
3+
let attempt: number = 0;
4+
let trying: boolean = true;
5+
while (trying) {
6+
trying = false;
7+
try {
8+
const result: T = await promise();
9+
resolve(result);
10+
} catch {
11+
trying = ++attempt < retries;
12+
}
1013
}
11-
}
12-
throw new Error(`exhausted number of retries (${retries})`);
14+
reject(new Error(`exhausted number of retries (${retries})`));
15+
});
1316
}

0 commit comments

Comments
 (0)