diff --git a/src/workers/customCodes.ts b/src/workers/customCodes.ts index 72b18e2a96..6c3e0444eb 100644 --- a/src/workers/customCodes.ts +++ b/src/workers/customCodes.ts @@ -26,6 +26,7 @@ export const CustomErrorCodes = { MAX_RELATIVE: -14, UNBALANCED: -9, UNCAUGHT_ARG: -3, + UNCHECK_ARG: -15, }, /** * InvalidAbsoluteTime error code and message. @@ -186,4 +187,14 @@ Suggestion: ${balancedTime}`, UncaughtArgumentType: (): ErrorCode => { return { id: CustomErrorCodes.Type.UNCAUGHT_ARG, message: `Error: Command Argument Type Mismatch` }; }, + /** + * uncheckable warning code and message. + */ + UncheckableArgumentType: (): ErrorCode => { + return { + id: CustomErrorCodes.Type.UNCHECK_ARG, + message: `Warning: Not able to evaluate and validate identifier. +Suggestion: Use literals when you can`, + }; + }, }; diff --git a/src/workers/workerHelpers.ts b/src/workers/workerHelpers.ts index 66c3b86d27..2b1e628173 100644 --- a/src/workers/workerHelpers.ts +++ b/src/workers/workerHelpers.ts @@ -187,6 +187,29 @@ export function findNextChildOfKind( .find(child => child !== undefined); } +/** + * Checks if a TypeScript AST node is a literal (string, number, boolean). + * + * @param {ts.Node} node - The TypeScript AST node to check. + * @returns {boolean} `true` if the node is a literal (string, number, boolean), `false` otherwise. + * + * @example + * const node = ... // some TypeScript AST node + * const result = isLiteral(node); + * console.log(result); // Outputs: true or false + */ +function isLiteral(node: tsc.Node): boolean { + switch (node.kind) { + case tsc.SyntaxKind.StringLiteral: + case tsc.SyntaxKind.NumericLiteral: + case tsc.SyntaxKind.TrueKeyword: + case tsc.SyntaxKind.FalseKeyword: + return true; + default: + return false; + } +} + /** * Removes quotation marks from the input string. * @@ -401,6 +424,16 @@ export function validateArguments( return false; } + // ignore identifier as we need literals to do the checks + if (!isLiteral(argumentNode)) { + return makeDiagnostic( + CustomErrorCodes.UncheckableArgumentType(), + sourceFile, + argumentNode, + tsc.DiagnosticCategory.Warning, + ); + } + let validation_resp: ValidationReturn; switch (expected_argument.arg_type) {