Skip to content

Commit

Permalink
Refactor InputTypeValidationRule to skip type validation for invalid …
Browse files Browse the repository at this point in the history
…types
  • Loading branch information
davelopez committed Jun 20, 2024
1 parent 5ae87d2 commit d117fb8
Showing 1 changed file with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ValidationRule, WorkflowDataType } from "@gxwf/server-common/src/languageTypes";
import { ValidationRule } from "@gxwf/server-common/src/languageTypes";
import { isCompatibleType, isWorkflowDataType } from "@gxwf/server-common/src/utils";
import { Diagnostic, DiagnosticSeverity } from "vscode-languageserver-types";
import { GxFormat2WorkflowDocument } from "../../gxFormat2WorkflowDocument";
Expand All @@ -13,25 +13,21 @@ export class InputTypeValidationRule implements ValidationRule {
const result: Diagnostic[] = [];

const inputNodes = documentContext.getRawInputNodes();
inputNodes.forEach((input) => {
for (const input of inputNodes) {
const inputName = String(input.keyNode.value);
const inputType = documentContext.nodeManager.getPropertyValueByName(input, "type") as string;

if (!isWorkflowDataType(inputType)) {
result.push({
message: `Input '${inputName}' has an invalid type. Expected a valid workflow data type but found '${inputType}'.`,
range: documentContext.nodeManager.getNodeRange(input),
severity: this.severity,
});
// Skip type validation for invalid types. Those will be caught by the schema validation.
continue;
}

const defaultValueNode = documentContext.nodeManager.getPropertyNodeByName(input, "default");
const defaultValue = defaultValueNode?.valueNode?.value;

const defaultValueType = typeof defaultValue;

if (inputType && defaultValue) {
const defaultTypeMatchesValue = isCompatibleType(inputType as WorkflowDataType, defaultValueType);
const defaultTypeMatchesValue = isCompatibleType(inputType, defaultValueType);
if (!defaultTypeMatchesValue) {
result.push({
message: `Input '${inputName}' default value has invalid type. Expected '${inputType}' but found '${defaultValueType}'.`,
Expand All @@ -40,8 +36,7 @@ export class InputTypeValidationRule implements ValidationRule {
});
}
}
});

}
return Promise.resolve(result);
}
}

0 comments on commit d117fb8

Please sign in to comment.