Skip to content

Commit

Permalink
💄 Lint
Browse files Browse the repository at this point in the history
- Enforce consistent indentation
- Require `const` declarations for variables that are never reassigned after declared
- Prefer using the primitive string as a type name, rather than the upper-cased String
  • Loading branch information
tolauwae committed Dec 6, 2024
1 parent 9c00306 commit 6b887b4
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 139 deletions.
8 changes: 4 additions & 4 deletions src/framework/Scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function trees(input: TestScenario[]): TestScenario[][][] {
input.sort(comparator);

// output
let forest: TestScenario[][][] = [];
const forest: TestScenario[][][] = [];

// scenario that have already been seen
const seen = new Set<TestScenario>();
Expand All @@ -100,7 +100,7 @@ function trees(input: TestScenario[]): TestScenario[][][] {
continue;
}
// start a new tree
let t: TestScenario[][] = tree(test);
const t: TestScenario[][] = tree(test);
forest.push(t);
pointer = forest.length - 1;

Expand Down Expand Up @@ -129,7 +129,7 @@ function trees(input: TestScenario[]): TestScenario[][][] {
function tree(root: TestScenario): TestScenario[][] {
let result: TestScenario[][] = [];

let lifo: TestScenario[] = [...root.dependencies ?? []];
const lifo: TestScenario[] = [...root.dependencies ?? []];
for (const test of lifo) {
const c = tree(test);
result = merge(c, result);
Expand Down Expand Up @@ -188,7 +188,7 @@ function levels(input: TestScenario[]): TestScenario[][] {
const test: TestScenario = input.shift()!;

// skip any test with unresolved dependencies
let skip: boolean = (test.dependencies ?? []).some((dependence: TestScenario) => input.includes(dependence));
const skip: boolean = (test.dependencies ?? []).some((dependence: TestScenario) => input.includes(dependence));

if (skip) {
input.push(test);
Expand Down
2 changes: 0 additions & 2 deletions src/framework/TestResult.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import {v4 as randomUUID} from 'uuid';

/* eslint-disable @typescript-eslint/naming-convention */
export enum Status {
FAILED = 'failed',
BROKEN = 'broken',
PASSED = 'passed',
SKIPPED = 'skipped',
}

/* eslint-disable @typescript-eslint/naming-convention */
export enum Stage {
SCHEDULED = 'scheduled',
RUNNING = 'running',
Expand Down
2 changes: 1 addition & 1 deletion src/framework/Testee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class Testee { // TODO unified with testbed interface
return;
}

let compiled: CompileOutput = await new CompilerFactory(WABT).pickCompiler(description.program).compile(description.program);
const compiled: CompileOutput = await new CompilerFactory(WABT).pickCompiler(description.program).compile(description.program);
try {
await timeout<Object | void>(`uploading module`, testee.timeout, testee.bed()!.sendRequest(new SourceMap.Mapping(), Message.updateModule(compiled.file))).catch((e) => Promise.reject(e));
testee.current = description.program;
Expand Down
52 changes: 26 additions & 26 deletions src/manage/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ enum CompilationEvents {

export interface CompileOutput {
file: string;
out?: String;
err?: String;
out?: string;
err?: string;
map?: SourceMap.Mapping;
}

Expand All @@ -33,13 +33,13 @@ export class CompilerFactory {
}

public pickCompiler(file: string): Compiler {
let fileType = getFileExtension(file);
const fileType = getFileExtension(file);
switch (fileType) {
case 'wast' :
case 'wat' :
return this.wat;
case 'ts' :
return this.asc;
case 'wast' :
case 'wat' :
return this.wat;
case 'ts' :
return this.asc;
}
throw new Error('Unsupported file type');
}
Expand Down Expand Up @@ -95,15 +95,15 @@ export class WatCompiler extends Compiler {
return new Promise<CompileOutput>((resolve, reject) => {
const file = `${dir}/upload.wasm`;
const command = `${this.wabt}/wat2wasm --no-canonicalize-leb128s --disable-bulk-memory --debug-names -v -o ${file} ${program}`;
let out: String = '';
let err: String = '';
let out: string = '';
let err: string = '';

function handle(error: ExecException | null, stdout: String, stderr: any) {
function handle(error: ExecException | null, stdout: string, stderr: any) {

Check failure

Code scanning / ESLint

Disallow unused variables Error

'stderr' is defined but never used.

Check failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.
out = stdout;
err = error?.message ?? '';
}

let compile = exec(command, handle);
const compile = exec(command, handle);
this.emit(CompilationEvents.started, command);

compile.on('close', (code) => {
Expand All @@ -124,7 +124,7 @@ export class WatCompiler extends Compiler {
return new Promise<CompileOutput>((resolve, reject) => {
const command = `${this.wabt}/wasm-objdump -x -m ${output.file}`;

let compile = exec(command, (error: ExecException | null, stdout: String, stderr: any) => {
const compile = exec(command, (error: ExecException | null, stdout: string, stderr: any) => {

Check failure

Code scanning / ESLint

Disallow unused variables Error

'stderr' is defined but never used.

Check failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.
output.map = this.parseWasmObjDump(output, stdout.toString());
this.emit(CompilationEvents.sourcemap);
resolve(output);
Expand Down Expand Up @@ -212,17 +212,17 @@ export class AsScriptCompiler extends Compiler {

// compile AS to Wasm and WAT
return new Promise<CompileOutput>(async (resolve, reject) => {
let file = `${dir}/upload.wasm`;
const file = `${dir}/upload.wasm`;
const command = await this.getCompilationCommand(program, file);
let out: String = '';
let err: String = '';
let out: string = '';
let err: string = '';

function handle(error: ExecException | null, stdout: String, stderr: any) {
function handle(error: ExecException | null, stdout: string, stderr: any) {

Check failure

Code scanning / ESLint

Disallow unused variables Error

'stderr' is defined but never used.

Check failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.
out = stdout;
err = error?.message ?? '';
}

let compile = exec(command, handle);
const compile = exec(command, handle);

compile.on('close', (code) => {
if (code !== 0) {
Expand All @@ -239,23 +239,23 @@ export class AsScriptCompiler extends Compiler {
private getCompilationCommand(program: string, output: string): Promise<string> {
// builds asc command based on the version of asc
return new Promise<string>(async (resolve) => {
let version: Version = await AsScriptCompiler.retrieveVersion();
const version: Version = await AsScriptCompiler.retrieveVersion();
resolve(`npx asc ${program} --exportTable --disable bulk-memory --sourceMap --debug ` +
`${(version.major > 0 || +version.minor >= 20) ? '--outFile' : '--binaryFile'} ${output}`);
});
}

private static retrieveVersion(): Promise<Version> {
return new Promise<Version>((resolve, reject) => {
let out: String = '';
let err: String = '';
let out: string = '';
let err: string = '';

function handle(error: ExecException | null, stdout: String, stderr: any) {
function handle(error: ExecException | null, stdout: string, stderr: any) {

Check failure

Code scanning / ESLint

Disallow unused variables Error

'stderr' is defined but never used.

Check failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.
out = stdout;
err = error?.message ?? '';
}

let compilerVersion = exec('npx asc --version', handle);
const compilerVersion = exec('npx asc --version', handle);
compilerVersion.on('close', (code) => {
if (code !== 0) {
reject(`asc --version failed: ${err}`);
Expand Down Expand Up @@ -299,7 +299,7 @@ function parseLines(context: CompileOutput): SourceMap.SourceLine[] {

const lines: string[] = context.out.split('\n');
const corrections = extractSectionAddressCorrections(lines);
let result: SourceLine[] = [];
const result: SourceLine[] = [];
let lastLineInfo = undefined;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
Expand Down Expand Up @@ -331,8 +331,8 @@ function parseLines(context: CompileOutput): SourceMap.SourceLine[] {
}

export function extractAddressInformation(addressLine: string): string {
let regexpr = /^(?<address>([\da-f])+):/;
let match = addressLine.match(regexpr);
const regexpr = /^(?<address>([\da-f])+):/;
const match = addressLine.match(regexpr);
if (match?.groups) {
return match.groups.address;
}
Expand Down
18 changes: 9 additions & 9 deletions src/manage/Uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export class UploaderFactory {

public pickUploader(specification: TestbedSpecification, args: string[] = []): Uploader {
switch (specification.type) {
case PlatformType.arduino:
return new ArduinoUploader(this.arduino, args, specification.options as SerialOptions);
case PlatformType.emulator:
case PlatformType.emu2emu:
case PlatformType.emuproxy:
return new EmulatorUploader(this.emulator, args, specification.options as SubprocessOptions);
case PlatformType.debug:
return new EmulatorConnector(specification.options as SubprocessOptions)
case PlatformType.arduino:
return new ArduinoUploader(this.arduino, args, specification.options as SerialOptions);
case PlatformType.emulator:
case PlatformType.emu2emu:
case PlatformType.emuproxy:
return new EmulatorUploader(this.emulator, args, specification.options as SubprocessOptions);
case PlatformType.debug:
return new EmulatorConnector(specification.options as SubprocessOptions)
}
throw new Error('Unsupported platform type');
}
Expand Down Expand Up @@ -206,7 +206,7 @@ export class ArduinoUploader extends Uploader {
private stage(program: string): Promise<void> {
const that = this;
return new Promise<void>((resolve, reject) => {
let compile = exec(`make compile PAUSED=true BINARY=${program}`, {cwd: this.sdkpath});
const compile = exec(`make compile PAUSED=true BINARY=${program}`, {cwd: this.sdkpath});

compile.on('close', (code) => {
if (code !== 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/messaging/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export namespace Message {
}

export async function uploadFile(program: string): Promise<Request<Ack>> {
let compiled: CompileOutput = await new CompilerFactory(WABT).pickCompiler(program).compile(program);
const compiled: CompileOutput = await new CompilerFactory(WABT).pickCompiler(program).compile(program);
return updateModule(compiled.file);
}

Expand Down
4 changes: 2 additions & 2 deletions src/messaging/Parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function ackParser(text: string, ack: string): Ack {
export function breakpointParser(text: string): Breakpoint {
const ack: Ack = ackParser(text, 'BP');

let breakpointInfo = ack.text.match(/BP (0x.*)!/);
const breakpointInfo = ack.text.match(/BP (0x.*)!/);
if (breakpointInfo!.length > 1) {
return new Breakpoint(parseInt(breakpointInfo![1]), 0); // TODO address to line mapping
}
Expand All @@ -50,7 +50,7 @@ export function breakpointParser(text: string): Breakpoint {
export function breakpointHitParser(text: string): Breakpoint {
const ack: Ack = ackParser(text, 'AT ');

let breakpointInfo = ack.text.match(/AT (0x.*)!/);
const breakpointInfo = ack.text.match(/AT (0x.*)!/);
if (breakpointInfo!.length > 1) {
return new Breakpoint(parseInt(breakpointInfo![1]), 0); // TODO address to line mapping
}
Expand Down
4 changes: 2 additions & 2 deletions src/reporter/Reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ export class Reporter {
results(time: number) {
this.archiver.set('duration (ms)', Math.round(time));

let passing = this.suites.flatMap((suite) => suite.scenarios).filter((scenario) => scenario.passing()).length;
let failing = this.suites.flatMap((suite) => suite.scenarios).filter((scenario) => scenario.failing()).length;
const passing = this.suites.flatMap((suite) => suite.scenarios).filter((scenario) => scenario.passing()).length;
const failing = this.suites.flatMap((suite) => suite.scenarios).filter((scenario) => scenario.failing()).length;
const skipped = this.suites.flatMap((suite) => suite.scenarios).filter((scenario) => scenario.skipped()).length;

const scs = this.suites.flatMap((suite) => suite.scenarios);
Expand Down
80 changes: 40 additions & 40 deletions src/reporter/Result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export class Result {

toString(): string {
switch (this.completion) {
case Completion.succeeded:
return `${bold(inverse(green(' PASS ')))} ${this.name}`;
case Completion.uncommenced:
return `${bold(inverse(yellow(' SKIP ')))} ${this.name}`;
case Completion.error:
case Completion.failed:
default:
return `${bold(inverse(red(' FAIL ')))} ${this.name}\n ${red(this.completion)}${red(this.description)}`;
case Completion.succeeded:
return `${bold(inverse(green(' PASS ')))} ${this.name}`;
case Completion.uncommenced:
return `${bold(inverse(yellow(' SKIP ')))} ${this.name}`;
case Completion.error:
case Completion.failed:
default:
return `${bold(inverse(red(' FAIL ')))} ${this.name}\n ${red(this.completion)}${red(this.description)}`;

}
}
Expand Down Expand Up @@ -74,38 +74,38 @@ export class Result {

public expectBehaviour(actual: any, previous: any, behaviour: Behaviour): void {
switch (behaviour) {
case Behaviour.unchanged:
if (deepEqual(actual, previous)) {
this.completion = Completion.succeeded;
} else {
this.completion = Completion.failed;
this.description = `Expected ${actual} to equal ${previous}`
}
break;
case Behaviour.changed:
if (!deepEqual(actual, previous)) {
this.completion = Completion.succeeded;
} else {
this.completion = Completion.failed;
this.description = `Expected ${actual} to be different from ${previous}`
}
break;
case Behaviour.increased:
if (actual > previous) {
this.completion = Completion.succeeded;
} else {
this.completion = Completion.failed;
this.description = `Expected ${actual} to be greater than ${previous}`
}
break;
case Behaviour.decreased:
if (actual < previous) {
this.completion = Completion.succeeded;
} else {
this.completion = Completion.failed;
this.description = `Expected ${actual} to be less than ${previous}`
}
break;
case Behaviour.unchanged:
if (deepEqual(actual, previous)) {
this.completion = Completion.succeeded;
} else {
this.completion = Completion.failed;
this.description = `Expected ${actual} to equal ${previous}`
}
break;
case Behaviour.changed:
if (!deepEqual(actual, previous)) {
this.completion = Completion.succeeded;
} else {
this.completion = Completion.failed;
this.description = `Expected ${actual} to be different from ${previous}`
}
break;
case Behaviour.increased:
if (actual > previous) {
this.completion = Completion.succeeded;
} else {
this.completion = Completion.failed;
this.description = `Expected ${actual} to be greater than ${previous}`
}
break;
case Behaviour.decreased:
if (actual < previous) {
this.completion = Completion.succeeded;
} else {
this.completion = Completion.failed;
this.description = `Expected ${actual} to be less than ${previous}`
}
break;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/reporter/Style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ interface Labels {
// strategy factory
export function styling(type: StyleType): Style {
switch (type) {
case StyleType.github:
case StyleType.plain:
default:
return new Plain();
case StyleType.github:
case StyleType.plain:
default:
return new Plain();
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/sourcemap/SourceMapFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export class SourceMapFactory {

public async map(source: string, tmpdir?: string): Promise<SourceMap.Mapping> {
switch (getFileExtension(source)) {
case 'wast' :
case 'wat' :
let compiled: CompileOutput = await this.compilerFactory.pickCompiler(source).compile(source);
return new WatMapper(compiled.out ?? '', tmpdir ?? path.dirname(compiled.file), WABT).mapping();
case 'ts' :
return new AsScriptMapper(source ?? '', tmpdir ?? path.dirname(source)).mapping();
case 'wast' :
case 'wat' :
const compiled: CompileOutput = await this.compilerFactory.pickCompiler(source).compile(source);

Check failure

Code scanning / ESLint

Disallow lexical declarations in case clauses Error

Unexpected lexical declaration in case block.
return new WatMapper(compiled.out ?? '', tmpdir ?? path.dirname(compiled.file), WABT).mapping();
case 'ts' :
return new AsScriptMapper(source ?? '', tmpdir ?? path.dirname(source)).mapping();
}
throw new Error('Unsupported file type');
}
Expand Down
Loading

0 comments on commit 6b887b4

Please sign in to comment.