Skip to content

Commit

Permalink
Enable typescript strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mullr committed Mar 7, 2024
1 parent 445c1f1 commit 30425f0
Show file tree
Hide file tree
Showing 25 changed files with 1,057 additions and 787 deletions.
33 changes: 33 additions & 0 deletions vscode/common-src/experimentWebViewApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export type WebViewMessage = VisualizeImpactScenarioCommand;

export interface VisualizeImpactScenarioCommand {
command: "visualizeImpactScenario";
args: ImpactScenario;
}

export interface ImpactScenario {
scenarioName: string;
mutations: MutationInfo[];
impactedTimelines: TimelineInfo[];
}

export interface MutationInfo {
mutationId: string;
timelineId: string;
timelineName: string;
segmentId: SegmentId;
}

// This matches the one in the backend api
export interface SegmentId {
workspace_version_id: string;
rule_name: string;
segment_name: string;
}

export interface TimelineInfo {
timelineName: string;
severity: number;
events: string[];
detailsHtml: string;
}
2 changes: 1 addition & 1 deletion vscode/common-src/transitionGraphWebViewApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface LogSelectedNodesCommand {

export interface NodeData extends cytoscape.NodeDataDefinition {
label?: string;
labelvalign?: "top" | "center";
labelvalign: "top" | "center";
filepath?: string;
timeline?: string;
timelineName?: string;
Expand Down
17 changes: 17 additions & 0 deletions vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@
"devDependencies": {
"@types/cytoscape": "^3.19",
"@types/cytoscape-context-menus": "^4.1.3",
"@types/glob": "^8.1.0",
"@types/jquery": "^3.5.29",
"@types/mocha": "^9.1.0",
"@types/node": "^16.11.7",
Expand Down
28 changes: 17 additions & 11 deletions vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export async function modalityUrl(): Promise<vscode.Uri> {
/**
* Extra environment variables to use for all command invocations, including the LSP server.
*/
function extraEnv(): null | object {
function extraEnv(): object | undefined {
const auxonConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("auxon");
return auxonConfig.get<null | object>("extraEnv");
return auxonConfig.get<object>("extraEnv");
}

/**
Expand All @@ -85,14 +85,18 @@ export async function allowInsecureHttps(): Promise<boolean> {
*/
export async function toolEnv(): Promise<Record<string, string>> {
const env: Record<string, string> = {
MODALITY_AUTH_TOKEN: await userAuthToken(),
// TODO implement this in the CLI
MODALITY_ALLOW_INSECURE_TLS: (await allowInsecureHttps()).toString(),
MODALITY_URL: (await modalityUrlV1()).toString(),
};

const auth_token = await userAuthToken();
if (auth_token != null) {
env["MODALITY_AUTH_TOKEN"] = auth_token;
}

const extra = extraEnv();
if (extra) {
if (extra != null) {
for (const [k, v] of Object.entries(extra)) {
env[k] = v.toString();
}
Expand Down Expand Up @@ -123,7 +127,7 @@ export async function toolDebugEnv(): Promise<Record<string, string>> {
export function toolPath(tool_name: string): string {
const auxonConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("auxon");
const toolDir = auxonConfig.get<null | string>("tooldir");
let toolPath: string;
let toolPath: string | undefined;

if (process.platform == "win32") {
let customPath = null;
Expand Down Expand Up @@ -167,18 +171,22 @@ export function toolPath(tool_name: string): string {
export function extraCliArgs(command: string): string[] {
const auxonConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("auxon");
const argsMap = auxonConfig.get<{ [key: string]: string[] }>("extraCliArgs");
if (argsMap == null) {
return [];
}

const args = argsMap[command];
if (args) {
return args;
} else {
if (args == null) {
return [];
}

return args;
}

/**
* Return the first given path which exists, or null if none of them do.
*/
function firstExistingPath(...paths: string[]): string | null {
function firstExistingPath(...paths: (string | null)[]): string | undefined {
for (let i = 0; i < paths.length; i++) {
const path = paths[i];
if (path == null) {
Expand All @@ -189,6 +197,4 @@ function firstExistingPath(...paths: string[]): string | null {
return path;
}
}

return null;
}
52 changes: 37 additions & 15 deletions vscode/src/deviantCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ export async function runDeviantExperimentCreateCommand(args: ExperimentCreateCo
try {
const res = await execFile(deviantPath, commandArgs, { encoding: "utf8" });
const _dont_wait = vscode.window.showInformationMessage(res.stdout);
} catch (e) {
vscode.window.showErrorMessage(e.stderr.trim());
} catch (e: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
if (Object.prototype.hasOwnProperty.call(e, "stderr")) {
vscode.window.showErrorMessage(e.stderr.trim());
} else {
vscode.window.showErrorMessage(e.toString());
}
}
}

Expand Down Expand Up @@ -64,8 +68,12 @@ async function runDeviantMutationClearCommand(args: MutationClearCommandArgs) {
try {
const res = await execFile(deviantPath, commandArgs, { encoding: "utf8" });
const _dont_wait = vscode.window.showInformationMessage(res.stdout);
} catch (e) {
vscode.window.showErrorMessage(e.stderr.trim());
} catch (e: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
if (Object.prototype.hasOwnProperty.call(e, "stderr")) {
vscode.window.showErrorMessage(e.stderr.trim());
} else {
vscode.window.showErrorMessage(e.toString());
}
}

vscode.commands.executeCommand("auxon.mutations.refresh");
Expand Down Expand Up @@ -102,15 +110,23 @@ async function runDeviantMutationCreateCommand(args: MutationCreateCommandArgs)

try {
const res = await execFile(deviantPath, commandArgs, { encoding: "utf8" });
const output = JSON.parse(res.stdout) as string;
const _dont_wait = vscode.window.showInformationMessage(`Created mutation '${output["mutation_id"]}'`);
} catch (e) {
vscode.window.showErrorMessage(e.stderr.trim());
const output = JSON.parse(res.stdout) as MutationCreateOutput;
const _dont_wait = vscode.window.showInformationMessage(`Created mutation '${output.mutation_id}'`);
} catch (e: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
if (Object.prototype.hasOwnProperty.call(e, "stderr")) {
vscode.window.showErrorMessage(e.stderr.trim());
} else {
vscode.window.showErrorMessage(e.toString());
}
}

vscode.commands.executeCommand("auxon.mutations.refresh");
}

interface MutationCreateOutput {
mutation_id: string;
}

// TODO - add linked experiment option
async function runCreateMutationWizard(mutator: Mutator) {
const title = `Create a mutation for mutator '${mutator.name}'`;
Expand Down Expand Up @@ -138,7 +154,7 @@ async function runCreateMutationWizard(mutator: Mutator) {
title: `${title} (${step}/${maxSteps})`,
placeHolder: `Enter the parameter value for '${param.name}' or leave blank for Deviant-suggested values`,
ignoreFocusOut: true,
validateInput: (input) => validateParameter(input, param),
validateInput: (input: string) => validateParameter(input, param),
};
let paramValue = await vscode.window.showInputBox(options);
if (paramValue === undefined) {
Expand Down Expand Up @@ -194,18 +210,24 @@ function validateParameter(input: string, param: MutatorParameter): string | nul
}
}

function isFloat(val) {
function isFloat(val: string) {
const floatRegex = /^-?\d+(?:[.]\d*?)?$/;
if (!floatRegex.test(val)) return false;
if (!floatRegex.test(val)) {
return false;
}

val = parseFloat(val);
if (isNaN(val)) return false;
const fVal = parseFloat(val);
if (isNaN(fVal)) {
return false;
}
return true;
}

function isInt(val) {
function isInt(val: string) {
const intRegex = /^-?\d+$/;
if (!intRegex.test(val)) return false;
if (!intRegex.test(val)) {
return false;
}

const intVal = parseInt(val, 10);
return parseFloat(val) == intVal && !isNaN(intVal);
Expand Down
Loading

0 comments on commit 30425f0

Please sign in to comment.